From 7f2014c14f146a07e6a068013e17efd1bea58dfb Mon Sep 17 00:00:00 2001 From: Luca Cervello Date: Wed, 1 Feb 2017 20:39:37 +0100 Subject: [PATCH] string-based keys with slash recognized (#146) --- src/selmer/filter_parser.clj | 4 +++- test/selmer/core_test.clj | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/selmer/filter_parser.clj b/src/selmer/filter_parser.clj index 0c4ff3c..0e9ecfc 100644 --- a/src/selmer/filter_parser.clj +++ b/src/selmer/filter_parser.clj @@ -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 diff --git a/test/selmer/core_test.clj b/test/selmer/core_test.clj index cd64d94..a5dfbd2 100644 --- a/test/selmer/core_test.clj +++ b/test/selmer/core_test.clj @@ -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"})))))