Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
erdos committed Nov 3, 2023
1 parent 5505b72 commit d0072dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/stencil/merger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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])]
Expand Down
12 changes: 6 additions & 6 deletions test/stencil/merger_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
))))

0 comments on commit d0072dc

Please sign in to comment.