Skip to content

Commit

Permalink
allow defpartial to accept a docstring or metadata map
Browse files Browse the repository at this point in the history
  • Loading branch information
pandeiro committed May 8, 2012
1 parent fdeb559 commit dc21120
Showing 1 changed file with 9 additions and 6 deletions.
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 params] (macro/name-with-attributes fname args)
body (rest (filter vector? 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 dc21120

Please sign in to comment.