diff --git a/src/clj_jtwig/standard_functions.clj b/src/clj_jtwig/standard_functions.clj index a4a034f..4b3ed15 100644 --- a/src/clj_jtwig/standard_functions.clj +++ b/src/clj_jtwig/standard_functions.clj @@ -11,7 +11,7 @@ ; :aliases, which should be a vector of strings containing one or more possible aliases for this function. (defonce standard-functions - {"blankIfNull" + {"blank_if_null" {:fn (fn [x] (if (nil? x) "" x)) :aliases ["nonull"]} @@ -91,14 +91,16 @@ {:fn (fn [sequence] (sort < sequence))} - "sortDescending" + "sort_descending" {:fn (fn [sequence] - (sort > sequence))} + (sort > sequence)) + :aliases ["sort_desc"]} - "sortBy" + "sort_by" {:fn (fn [coll k] (sort-by #(get % k) coll))} - "sortDescendingBy" + "sort_descending_by" {:fn (fn [coll k] - (sort-by #(get % k) #(compare %2 %1) coll))}}) + (sort-by #(get % k) #(compare %2 %1) coll)) + :aliases ["sort_desc_by"]}}) diff --git a/test/clj_jtwig/functions_test.clj b/test/clj_jtwig/functions_test.clj index 7fc9342..46b0f37 100644 --- a/test/clj_jtwig/functions_test.clj +++ b/test/clj_jtwig/functions_test.clj @@ -254,7 +254,7 @@ (deftest standard-functions (testing "Standard functions were added properly" - (is (true? (function-exists? "blankIfNull"))) + (is (true? (function-exists? "blank_if_null"))) (is (true? (function-exists? "butlast"))) (is (true? (function-exists? "dump"))) (is (true? (function-exists? "nth"))) @@ -265,16 +265,16 @@ (is (true? (function-exists? "rest"))) (is (true? (function-exists? "second"))) (is (true? (function-exists? "sort"))) - (is (true? (function-exists? "sortDescending"))) - (is (true? (function-exists? "sortBy"))) - (is (true? (function-exists? "sortDescendingBy")))) + (is (true? (function-exists? "sort_descending"))) + (is (true? (function-exists? "sort_by"))) + (is (true? (function-exists? "sort_descending_by")))) - (testing "blankIfNull" - (is (= (render "{{ a|blankIfNull }}" nil) + (testing "blank_if_null" + (is (= (render "{{ a|blank_if_null }}" nil) "")) - (is (= (render "{{ a|blankIfNull }}" {:a nil}) + (is (= (render "{{ a|blank_if_null }}" {:a nil}) "")) - (is (= (render "{{ a|blankIfNull }}" {:a "foo"}) + (is (= (render "{{ a|blank_if_null }}" {:a "foo"}) "foo")) (is (= (render "{{ a|nonull }}" nil) ""))) @@ -333,14 +333,14 @@ (is (= (render "{{ [2, 1, 5, 3, 4]|sort }}" nil) "[1, 2, 3, 4, 5]"))) - (testing "sortDescending" - (is (= (render "{{ [2, 1, 5, 3, 4]|sortDescending }}" nil) + (testing "sort_descending" + (is (= (render "{{ [2, 1, 5, 3, 4]|sort_descending }}" nil) "[5, 4, 3, 2, 1]"))) - (testing "sortBy" - (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sortBy(\"a\") }}" nil) + (testing "sort_by" + (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_by(\"a\") }}" nil) "[{a=1}, {a=2}, {a=3}, {a=4}, {a=5}]"))) - (testing "sortDescendingBy" - (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sortDescendingBy(\"a\") }}" nil) + (testing "sort_descending_by" + (is (= (render "{{ [{a: 2}, {a: 1}, {a: 5}, {a: 3}, {a: 4}]|sort_descending_by(\"a\") }}" nil) "[{a=5}, {a=4}, {a=3}, {a=2}, {a=1}]"))))