Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #94 from pandeiro/docstringable-defs

Docstring-able defpartial
  • Loading branch information...
commit eb36d9961858688e7d514430f386a56fa62fd44b 2 parents 5e957af + 2aefcc1
@Raynes Raynes authored
Showing with 11 additions and 7 deletions.
  1. +2 −1  project.clj
  2. +9 −6 src/noir/core.clj
View
3  project.clj
@@ -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"]])
View
15 src/noir/core.clj
@@ -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 {}))
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.