Skip to content

Commit

Permalink
* src/tutorial/template1.clj: fix utils bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Feb 18, 2010
1 parent 8bdba89 commit 3133038
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/tutorial/template1.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns tutorial.template1
(:require [net.cgrand.enlive-html :as html])
(:use net.cgrand.contrib.utils)
(:use tutorial.utils)
(:use compojure))

(html/deftemplate index "tutorial/template1.html"
Expand Down
2 changes: 1 addition & 1 deletion src/tutorial/template2.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns tutorial.template2
(:use [net.cgrand.enlive-html
:only [selector deftemplate defsnippet content nth-of-type first-child]])
(:use net.cgrand.contrib.utils)
(:use tutorial.utils)
(:use compojure))

;; =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/tutorial/template3.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns tutorial.template3
(:require [net.cgrand.enlive-html :as html])
(:use net.cgrand.contrib.utils)
(:use tutorial.utils)
(:use compojure))

;; =============================================================================
Expand Down
22 changes: 22 additions & 0 deletions src/tutorial/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns tutorial.utils
(:require [net.cgrand.enlive-html :as html]))

(defn render [t]
(apply str t))

(defmulti parse-int type)
(defmethod parse-int java.lang.Integer [n] n)
(defmethod parse-int java.lang.String [s] (Integer/parseInt s))

(defmacro maybe-substitute
([expr] `(if-let [x# ~expr] (html/substitute x#) identity))
([expr & exprs] `(maybe-substitute (or ~expr ~@exprs))))

(defmacro maybe-content
([expr] `(if-let [x# ~expr] (html/content x#) identity))
([expr & exprs] `(maybe-content (or ~expr ~@exprs))))

(defn pluralize [astr n]
(if (= n 1)
(str astr)
(str astr "s")))

0 comments on commit 3133038

Please sign in to comment.