Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit

Permalink
add pad_left
Browse files Browse the repository at this point in the history
  • Loading branch information
gered committed Mar 23, 2014
1 parent 6b88897 commit b6d0f30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/clj_jtwig/standard_functions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
(apply min (first numbers))
(apply min numbers)))}

"pad_left"
{:fn (fn [s size & [padding-string]]
(StringUtils/leftPad s size (or padding-string " ")))}

"random"
{:fn (fn [& values]
(let [first-value (first values)]
Expand Down
8 changes: 8 additions & 0 deletions test/clj_jtwig/functions_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@
(is (= (render "{{ min(2, 1, 5, 3, 4) }}" nil)
"1")))

(testing "pad_left"
(is (= (render "{{ pad_left('bat', 5) }}" nil)
" bat"))
(is (= (render "{{ pad_left('bat', 3) }}" nil)
"bat"))
(is (= (render "{{ pad_left('bat', 5, 'x') }}" nil)
"xxbat")))

(testing "random"
(is (some #{(render "{{ ['apple', 'orange', 'citrus']|random }}" nil)}
["apple" "orange" "citrus"]))
Expand Down

0 comments on commit b6d0f30

Please sign in to comment.