Skip to content

Commit

Permalink
Merge pull request noir-clojure#94 from pandeiro/docstringable-defs
Browse files Browse the repository at this point in the history
Docstring-able defpartial
  • Loading branch information
Raynes committed May 15, 2012
2 parents 5e957af + 2aefcc1 commit eb36d99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion project.clj
Expand Up @@ -10,4 +10,5 @@
[ring "1.1.0"]
[hiccup "1.0.0"]
[clj-stacktrace "0.2.4"]
[org.mindrot/jbcrypt "0.3m"]])
[org.mindrot/jbcrypt "0.3m"]
[org.clojure/tools.macro "0.1.1"]])
15 changes: 9 additions & 6 deletions src/noir/core.clj
Expand Up @@ -2,7 +2,8 @@
"Functions to work with partials and pages."
(:use hiccup.core
compojure.core)
(:require [clojure.string :as string]))
(:require [clojure.string :as string]
[clojure.tools.macro :as macro]))

(defonce noir-routes (atom {}))
(defonce route-funcs (atom {}))
Expand Down Expand Up @@ -100,11 +101,13 @@
(swap! noir-routes assoc ~(keyword fn-name) (~action ~url {params# :params} (~fn-name params#))))))

(defmacro defpartial
"Create a function that returns html using hiccup. The function is callable with the given name."
[fname params & body]
`(defn ~fname ~params
(html
~@body)))
"Create a function that returns html using hiccup. The function is callable with the given name. Can optionally include a docstring or metadata map, like a normal function declaration."
[fname & args]
(let [[fname args] (macro/name-with-attributes fname args)
[params & body] args]
`(defn ~fname ~params
(html
~@body))))

(defn ^{:skip-wiki true} route-arguments
"returns the list of route arguments in a route"
Expand Down

0 comments on commit eb36d99

Please sign in to comment.