Skip to content

Commit

Permalink
Fix indentation using cljfmt rules and style
Browse files Browse the repository at this point in the history
  • Loading branch information
iarenaza committed Apr 6, 2022
1 parent d86ebcd commit bcaf24b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
44 changes: 22 additions & 22 deletions src/cljstache/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
[f coll]
(apply str (map f coll)))

; To match clj regex api
;; To match clj regex api
#?(:cljs
(defn re-matcher [pattern s]
[(re-pattern pattern) s]))
Expand Down Expand Up @@ -148,7 +148,7 @@
(re-matcher
(re-pattern (str "(" open ".*?" close
(when (not= "\\{\\{" open)
(str "|\\{\\{.*?\\}\\}"))
(str "|\\{\\{.*?\\}\\}"))
")"))
s))

Expand Down Expand Up @@ -195,9 +195,9 @@
(sb-delete builder match-start match-end)
(recur (int match-start)))
(when-let [tag (re-find
(re-pattern (str @open-delim "(.*?)"
@close-delim))
match)]
(re-pattern (str @open-delim "(.*?)"
@close-delim))
match)]
(let [section-start (re-find (re-pattern
(str "^"
@open-delim
Expand All @@ -210,17 +210,17 @@
(not (and (= @open-delim "\\{\\{")
(= @close-delim "\\}\\}"))))
(swap! data
(fn [old]
(fn [data]
(str "{{="
(unescape-regex @open-delim)
" "
(unescape-regex @close-delim)
"=}}"
(old data)))))))
#(update % k
(fn [old]
(fn [data]
(str "{{="
(unescape-regex @open-delim)
" "
(unescape-regex @close-delim)
"=}}"
(old data)))))))
(sb-replace builder match-start match-end
(str "{{" (second tag) "}}"))
(str "{{" (second tag) "}}"))
(recur (int match-end))))))))))
[(sb->str builder) @data]))

Expand Down Expand Up @@ -313,7 +313,7 @@
""
(subs section body-start body-end))
section-name (.trim (subs section 3
(.indexOf section "}}")))]
(.indexOf section "}}")))]
(Section. section-name body start end inverted)))))))

(defn- replace-all-callback
Expand Down Expand Up @@ -472,7 +472,7 @@
[^String template data partials skip-delimiter-preprocess?]
(let [[^String template data] (if skip-delimiter-preprocess?
[template data]
(delimiter-preprocess template data ))
(delimiter-preprocess template data))
^String section (extract-section template)]
(if (nil? section)
(replace-variables template data partials)
Expand All @@ -493,14 +493,14 @@
(defn render
"Renders the template with the data and, if supplied, partials."
([template]
(render template {} {}))
(render template {} {}))
([template data]
(render template data {}))
(render template data {}))
([template data partials]
(let [[template data] (preprocess template data partials)]
(replace-all (render-template template data partials true)
[["\\\\\\{\\\\\\{" "{{"]
["\\\\\\}\\\\\\}" "}}"]]))))
(let [[template data] (preprocess template data partials)]
(replace-all (render-template template data partials true)
[["\\\\\\{\\\\\\{" "{{"]
["\\\\\\}\\\\\\}" "}}"]]))))

#?(:clj
(defn render-resource
Expand Down
28 changes: 11 additions & 17 deletions test/cljstache/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@

(deftest replace-all-test
(testing "escape-html"
(is (= "<html>&""
(#'cs/escape-html "<html>&\""))))
(is (= "&lt;html&gt;&amp;&quot;"
(#'cs/escape-html "<html>&\""))))
(testing "indent-partial"
(is (= "a\n-->b\n-->c\n-->d"
(#'cs/indent-partial "a\nb\nc\nd" "-->"))))
Expand All @@ -63,7 +63,7 @@
(#'cs/escape-regex "\\{}[]().?^+-|="))))
(testing "unescape-regex"
(is (= "{}[]().?^+-|=\\"
(#'cs/unescape-regex "\\{\\}\\[\\]\\(\\)\\.\\?\\^\\+\\-\\|=\\")))))
(#'cs/unescape-regex "\\{\\}\\[\\]\\(\\)\\.\\?\\^\\+\\-\\|=\\")))))

(deftest stringbuilder-test
(let [b (fn [] (#'cs/->stringbuilder "abcdef"))]
Expand All @@ -82,8 +82,6 @@
(is (= "abc123def"
(-> (b) (#'cs/sb-insert 3 "123") (#'cs/sb->str)))))))



(deftest process-set-delimiters-test
(testing "Correctly replaces custom delimiters"
(is (= ["Hello, {{name}}" {:name "Felix"}]
Expand Down Expand Up @@ -145,15 +143,14 @@
{:name "Jenny"}])}))))

(deftest test-render-hash
; according to mustache(5) non-false, non-list value
; should be used as a context for a single rendering of a block
;; according to mustache(5) non-false, non-list value
;; should be used as a context for a single rendering of a block
(is (= "Hello, Felix!" (render "Hello{{#person}}, {{name}}{{/person}}!"
{:person {:name "Felix"}}))))

(deftest test-render-empty-list
(is (= "" (render "{{#things}}Something{{/things}}" {:things []}))))


(deftest test-render-nested-list
(is (= "z" (render "{{#x}}{{#y}}{{z}}{{/y}}{{/x}}" {:x {:y {:z "z"}}}))))

Expand All @@ -175,7 +172,7 @@

(deftest test-render-atomic-string
(is (= "Hello, Atomic string" (render "Hello{{#string}}, {{string}}{{/string}}"
{:string "Atomic string"}))))
{:string "Atomic string"}))))

(deftest test-render-inverted-empty-list
(is (= "Empty" (render "{{^things}}Empty{{/things}}" {:things []}))))
Expand All @@ -190,15 +187,12 @@
(deftest test-render-inverted-boolean-false
(is (= "Hello, Felix" (render "Hello, {{^condition}}Felix{{/condition}}"
{:condition false}))))

(deftest test-render-with-delimiters
(is (= "Hello, Felix" (render "{{=<% %>=}}Hello, <%name%>" {:name "Felix"}))))


(deftest test-render-with-regex-delimiters
(is (= "Hello, Felix" (render "{{=[ ]=}}Hello, [name]" {:name "Felix"}))))


(deftest test-render-with-delimiters-changed-twice
(is (= "Hello, Felix" (render "{{=[ ]=}}[greeting], [=<% %>=]<%name%>"
{:greeting "Hello" :name "Felix"}))))
Expand Down Expand Up @@ -258,11 +252,11 @@

(deftest test-render-partial-recursive
(is (= "One Two Three Four Five" (render "One {{>two}}"
{}
{:two "Two {{>three}}"
:three "Three {{>four}}"
:four "Four {{>five}}"
:five "Five"}))))
{}
{:two "Two {{>three}}"
:three "Three {{>four}}"
:four "Four {{>five}}"
:five "Five"}))))

(deftest test-render-with-variable-containing-template
(is (= "{{hello}},world" (render "{{tmpl}},{{hello}}" {:tmpl "{{hello}}" :hello "world"}))))
Expand Down

0 comments on commit bcaf24b

Please sign in to comment.