From bcaf24bb846bd2488979fefd6fae6a184f4d67cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Arenaza?= Date: Wed, 6 Apr 2022 20:05:39 +0200 Subject: [PATCH] Fix indentation using cljfmt rules and style --- src/cljstache/core.cljc | 44 +++++++++++++++++------------------ test/cljstache/core_test.cljc | 28 +++++++++------------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/cljstache/core.cljc b/src/cljstache/core.cljc index 27fd33f..1ff3099 100644 --- a/src/cljstache/core.cljc +++ b/src/cljstache/core.cljc @@ -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])) @@ -148,7 +148,7 @@ (re-matcher (re-pattern (str "(" open ".*?" close (when (not= "\\{\\{" open) - (str "|\\{\\{.*?\\}\\}")) + (str "|\\{\\{.*?\\}\\}")) ")")) s)) @@ -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 @@ -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])) @@ -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 @@ -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) @@ -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 diff --git a/test/cljstache/core_test.cljc b/test/cljstache/core_test.cljc index 55283d9..cacc313 100644 --- a/test/cljstache/core_test.cljc +++ b/test/cljstache/core_test.cljc @@ -53,8 +53,8 @@ (deftest replace-all-test (testing "escape-html" - (is (= "<html>&"" - (#'cs/escape-html "&\"")))) + (is (= "<html>&"" + (#'cs/escape-html "&\"")))) (testing "indent-partial" (is (= "a\n-->b\n-->c\n-->d" (#'cs/indent-partial "a\nb\nc\nd" "-->")))) @@ -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"))] @@ -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"}] @@ -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"}}})))) @@ -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 []})))) @@ -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"})))) @@ -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"}))))