forked from swannodette/enlive-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* src/tutorial/template1.clj: fix utils bug.
- Loading branch information
1 parent
8bdba89
commit 3133038
Showing
4 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))) |