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
Expand Up @@ -7,27 +7,27 @@
compojure.core)
(: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 []
(let [props (Properties.)]
(.load props (reader (resource "default/velocity.properties")))
props))

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

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

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

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

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

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

0 comments on commit e24e662

Please sign in to comment.