Skip to content

Commit

Permalink
Refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 committed Oct 25, 2012
1 parent 13b007d commit e24e662
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/ring/velocity/core.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
compojure.core) compojure.core)
(:use [clojure.java.io :only [resource reader]])) (:use [clojure.java.io :only [resource reader]]))


(def ^{:dynamic true :private true} VELOCITY-PROPS "ring-velocity.properties") (def ^{:dynamic true :private true :constant true} velocity-props "ring-velocity.properties")


(defn- ^{:tag Properties} get-default-properties [] (defn- ^{:tag Properties} get-default-properties []
(let [props (Properties.)] (let [props (Properties.)]
(.load props (reader (resource "default/velocity.properties"))) (.load props (reader (resource "default/velocity.properties")))
props)) props))


;;initialize velocity ;;initialize velocity
(if-let [r (resource VELOCITY-PROPS)] (if-let [r (resource velocity-props)]
(let [props (Properties.)] (let [props (Properties.)]
(do (.load props (reader r)) (Velocity/init props))) (do (.load props (reader r)) (Velocity/init props)))
(Velocity/init (get-default-properties))) (Velocity/init (get-default-properties)))


(defn- ^{:tag VelocityContext} ->context [kvs] (defn- ^{:tag VelocityContext} ->context [kvs]
"Convert a map to a velocity context instance" "Convert a vector of key/value pairs to a velocity context instance"
(let [^VelocityContext ctx (VelocityContext.)] (let [^VelocityContext ctx (VelocityContext.)]
(loop [[k v & r] kvs] (loop [[k v & r] kvs]
(.put ctx (name k) v) (.put ctx (name k) v)
(when r (when r
(recur r))) (recur r)))
ctx)) ctx))


(defprotocol ^{:doc "Template render protocol"} (defprotocol ^{:doc "Template render protocol"}
TemplateRender TemplateRender
Expand All @@ -44,7 +44,7 @@
(.toString sw)) (.toString sw))
(throw (RuntimeException. (format "could not find template named `%s`" tname))))))) (throw (RuntimeException. (format "could not find template named `%s`" tname)))))))


(def ^:private *velocity-render (VelocityRender.)) (def ^{:private true :dynamic true} *render (VelocityRender.))


(defn render (defn render
[tname & kvs] [tname & kvs]
Expand All @@ -54,7 +54,7 @@
:name and :age are the variables in template. :name and :age are the variables in template.
" "
(render-template *velocity-render tname kvs)) (render-template *render tname kvs))


(defn- add-wildcard (defn- add-wildcard
"Add a wildcard to the end of a route path." "Add a wildcard to the end of a route path."
Expand Down

0 comments on commit e24e662

Please sign in to comment.