Browse files

Updated some stuff to Clojure 1.4 and Leiningen 2

  • Loading branch information...
1 parent a5d0c57 commit 21b386b9b287cea736e1e8166011b56db21a5aa8 @Flamefork committed Nov 21, 2012
Showing with 33 additions and 37 deletions.
  1. +1 −0 .gitignore
  2. +4 −5 project.clj
  3. +1 −1 src/fleet.clj
  4. +1 −1 src/fleet/builder.clj
  5. +3 −3 src/fleet/parser.clj
  6. +15 −19 src/fleet/runtime.clj
  7. +1 −1 src/fleet/util.clj
  8. +6 −6 test/fleet/runtime_test.clj
  9. +1 −1 test/fleet_lang_test.clj
View
1 .gitignore
@@ -1,5 +1,6 @@
README.html
pom.xml
+target
classes
lib
fleet.jar
View
9 project.clj
@@ -1,8 +1,7 @@
-(defproject
- fleet "0.9.5"
+(defproject fleet "0.10.0"
:description "Templating System for Clojure"
:url "http://github.com/Flamefork/fleet"
- :dependencies [[org.clojure/clojure "1.2.0"]]
- :java-source-path "src"
- :dev-dependencies [[lein-clojars "0.7.0"]])
+ :dependencies [[org.clojure/clojure "1.4.0"]]
+ :java-source-paths ["src"]
+ :dev-dependencies [[lein-clojars "0.9.1"]])
View
2 src/fleet.clj
@@ -19,7 +19,7 @@
:regex escape-regex
escaping))
-(def #^{:private true} default-opts {
+(def ^:private default-opts {
:escaping :bypass
:file-name "FLEET_TEMPLATE"
:file-path nil
View
2 src/fleet/builder.clj
@@ -6,7 +6,7 @@
(declare consume)
-(def #^{:private true} consumers {
+(def ^:private consumers {
:text #(str "(raw \"" (escape-clj-string %) "\")")
:clj bypass
:embed #(str "(screen (" (apply str (map consume %)) "))")
View
6 src/fleet/parser.clj
@@ -6,10 +6,10 @@
;;;;;;;;;; lexer ;;;;;;;;;;
-(def #^{:private true} escaped-tokens
+(def ^:private escaped-tokens
#{"\\)>" "\\\">" "\\<(" "\\<\""})
-(def #^{:private true} token-regexs {
+(def ^:private token-regexs {
true (Pattern/compile (str "^(.*?)(\\)>|\">|\\\\\\)>|\\\\\">)") Pattern/DOTALL)
false (Pattern/compile (str "^(.*?)(<\\(|<\"|\\\\<\\(|\\\\<\")") Pattern/DOTALL)})
@@ -32,7 +32,7 @@
[s]
(if (escaped-tokens s) (.substring s 1) s))
-(def #^{:private true} consumers {
+(def ^:private consumers {
true {
")>" (fn [_ loc] [false (-> loc z/up z/up)])
"\">" (fn [_ loc] [false (-> loc (z/append-child [:tpl []]) z/down z/rightmost z/down z/rightmost)])
View
34 src/fleet/runtime.clj
@@ -9,36 +9,32 @@
(defn raw
"Prevent encoding of string."
- [f s]
+ [escaping-fn s]
(let [obj (-> s .toString CljString.)
- new-escw (assoc (escaped-with s) f true)
+ new-escw (assoc (escaped-with s) escaping-fn true)
new-meta (assoc (meta obj) :escaped-with new-escw)]
(with-meta obj new-meta)))
(defn raw?
- [f s]
- (get (escaped-with s) f))
+ [escaping-fn s]
+ (get (escaped-with s) escaping-fn))
-(defmulti screen
- "Process and collect template string(s)."
- (fn [f s] (class s)))
+(defprotocol Screenable
+ (screen [s escaping-fn] "Process and collect template string(s)."))
-(defmethod screen CharSequence
- [f s]
- (raw f (if (raw? f s) s (f s))))
+(extend CharSequence Screenable
+ {:screen (fn [s f] (raw f (if (raw? f s) s (f s))))})
-(defmethod screen Sequential
- [f s]
- (raw f (apply str (map (partial screen f) s))))
+(extend Sequential Screenable
+ {:screen (fn [s f] (raw f (apply str (map #(screen %1 f) s))))})
-(defmethod screen :default
- [f s]
- (raw f (str s)))
+(extend Object Screenable
+ {:screen (fn [s f] (raw f (str s)))})
(defn make-runtime
"Create runtime functions applied to specified escaping-fn."
[escaping-fn]
- { :raw (partial raw escaping-fn)
- :raw? (partial raw? escaping-fn)
- :screen (partial screen escaping-fn)
+ { :raw (partial raw escaping-fn)
+ :raw? (partial raw? escaping-fn)
+ :screen #(screen %1 escaping-fn)
})
View
2 src/fleet/util.clj
@@ -6,7 +6,7 @@
arg)
;; copied from v1.1 clojure.contrib.lazy-xml
-(def #^{:private true}
+(def ^:private
escape-xml-map
(zipmap "'<>\"&" (map #(str \& % \;) '[apos lt gt quot amp])))
(defn escape-xml [text]
View
12 test/fleet/runtime_test.clj
@@ -21,17 +21,17 @@
(deftest screen-obj-test
(let [s "qwe<br>asd"]
(is (=
- (screen escaping-fn s)
+ (screen s escaping-fn)
"qwe&lt;br&gt;asd"))
(is (=
- (screen escaping-fn (raw escaping-fn s))
+ (screen (raw escaping-fn s) escaping-fn)
"qwe<br>asd"))
- (is (raw? escaping-fn (screen escaping-fn s)))
- (is (raw? escaping-fn (screen escaping-fn (raw escaping-fn s))))))
+ (is (raw? escaping-fn (screen s escaping-fn)))
+ (is (raw? escaping-fn (screen (raw escaping-fn s) escaping-fn)))))
(deftest screen-seq-test
(let [s ["qwe<br>asd" " " (raw escaping-fn "qwe<br>asd")]]
(is (=
- (screen escaping-fn s)
+ (screen s escaping-fn)
"qwe&lt;br&gt;asd qwe<br>asd"))
- (is (raw? escaping-fn (screen escaping-fn s)))))
+ (is (raw? escaping-fn (screen s escaping-fn)))))
View
2 test/fleet_lang_test.clj
@@ -25,7 +25,7 @@
((fileet [post title] "first/test_tpl") test-post "Post Template")
(readhtml "first/test_tpl"))))
-(deftest deftemplate-test
+(deftest def-name-fleet-test
(def single-post (fleet [post] "<p><(post :body)></p>" {:escaping str}))
(is (=
(single-post test-post)

0 comments on commit 21b386b

Please sign in to comment.