From d0072dc5286877a4aed12ca74f46107f75a4b7c6 Mon Sep 17 00:00:00 2001 From: janos erdos Date: Fri, 3 Nov 2023 23:46:47 +0100 Subject: [PATCH] wip --- src/stencil/merger.clj | 10 ++++------ test/stencil/merger_test.clj | 12 ++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/stencil/merger.clj b/src/stencil/merger.clj index 80e0bba9..f810b788 100644 --- a/src/stencil/merger.clj +++ b/src/stencil/merger.clj @@ -61,16 +61,14 @@ ;; returns either a collection of elements or nil (defn ->action-parser [prepend] (let [expected-open-tag-chars (volatile! (seq open-tag)) - buffer (new java.util.ArrayList prepend)] + buffer (new java.util.ArrayList ^java.util.Collection prepend)] (fn self ([] buffer) ([token] (if (= token (first @expected-open-tag-chars)) - (if-not (vswap! expected-open-tag-chars next) - (do (.add buffer token) - (->action-inside-parser buffer)) - (do (.add buffer token) - self)) + (do (.add buffer token) + (when-not (vswap! expected-open-tag-chars next) + (->action-inside-parser buffer))) (if (= (count open-tag) (count @expected-open-tag-chars)) ;; we are not inside a reading thing. (let [result (concat (vec buffer) [token])] diff --git a/test/stencil/merger_test.clj b/test/stencil/merger_test.clj index e85bf676..a62118aa 100644 --- a/test/stencil/merger_test.clj +++ b/test/stencil/merger_test.clj @@ -74,26 +74,26 @@ [{:action {:cmd :cmd/echo, :expression 1 :raw "{%=1%}"}}] [{:text "abc{%=1%}b"}] - [{:text "abc"} {:text "{%=1%}"} {:text "b"}] + [{:text "abc{%=1%}b"}] [{:text "abc"} {:action {:cmd :cmd/echo, :expression 1 :raw "{%=1%}"}} {:text "b"}] [{:text "abc{%="} O1 O2 {:text "1"} O3 O4 {:text "%}b"}] - [{:text "abc"} {:text "{%="} O1 O2 {:text "1"} O3 O4 {:text "%}b"}] + [{:text "abc{%="} O1 O2 {:text "1"} O3 O4 {:text "%}b"}] [{:text "abc"} {:action {:cmd :cmd/echo, :expression 1 :raw "{%=1%}"}} O1 O2 O3 O4 {:text "b"}] [{:text "abc{%="} O1 O2 {:text "1%"} O3 O4 {:text "}b"}] - [{:text "abc"} {:text "{%="} O1 O2 {:text "1%"} O3 O4 {:text "}b"}] + [{:text "abc{%="} O1 O2 {:text "1%"} O3 O4 {:text "}b"}] [{:text "abc"} {:action {:cmd :cmd/echo, :expression 1 :raw "{%=1%}"}} O1 O2 O3 O4 {:text "b"}] [{:text "abcd{%="} O1 {:text "1"} O2 {:text "%"} O3 {:text "}"} O4 {:text "b"}] - [{:text "abcd"} {:text "{%="} O1 {:text "1"} O2 {:text "%"} O3 {:text "}"} O4 {:text "b"}] + [{:text "abcd{%="} O1 {:text "1"} O2 {:text "%"} O3 {:text "}"} O4 {:text "b"}] [{:text "abcd"} {:action {:cmd :cmd/echo, :expression 1 :raw "{%=1%}"}} O1 O2 O3 O4{:text "b"}] [{:text "abc{"} O1 {:text "%"} O2 {:text "=1"} O3 {:text "2"} O4 {:text "%"} O5 {:text "}"} {:text "b"}] - [{:text "abc"} {:text "{"} O1 {:text "%"} O2 {:text "=1"} O3 {:text "2"} O4 {:text "%"} O5 {:text "}"} {:text "b"}] + [{:text "abc{"} O1 {:text "%"} O2 {:text "=1"} O3 {:text "2"} O4 {:text "%"} O5 {:text "}"} {:text "b"}] [{:text "abc"} {:action {:cmd :cmd/echo, :expression 12 :raw "{%=12%}"}} O1 O2 O3 O4 O5 {:text "b"}] [O1 {:text "{%if p"} O2 O3 {:text "%}one{%end%}"} O4] - [O1 {:text "{%if p"} O2 O3 {:text "%}one"} {:text "{%end%}"} O4] + [O1 {:text "{%if p"} O2 O3 {:text "%}one{%end%}"} O4] [O1 {:action {:cmd :if, :condition 'p :raw "{%if p%}"}} O2 O3 {:text "one"} {:action {:cmd :end :raw "{%end%}"}} O4] ))))