Skip to content

Commit

Permalink
string-based keys with slash recognized (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacervello authored and yogthos committed Feb 1, 2017
1 parent 5c75fe0 commit 7f2014c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/selmer/filter_parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ applied filter."
"Returns the value of `k` from map `m`, either as a keyword or string lookup."
(or (get m k)
(when (keyword? k)
(get m (name k)))))
(if-let [n (namespace k)]
(get m (str n "/" (name k)))
(get m (name k))))))

(defn compile-filter-body
"Turns a string like foo|filter1:x|filter2:y into a fn that expects a
Expand Down
3 changes: 2 additions & 1 deletion test/selmer/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@

(deftest name-test
(testing "converts keywords to strings"
(is (= "foobar" (render "{{foo|name}}" {:foo :foobar}))))
(is (= "foobar" (render "{{foo|name}}" {:foo :foobar})))
(is (= "foobar" (render "{{foo/bar}}" {"foo/bar" "foobar"}))))
(testing "leaves strings as they are"
(is (= "foobar" (render "{{foo|name}}" {:foo "foobar"})))))

Expand Down

0 comments on commit 7f2014c

Please sign in to comment.