Skip to content

Commit

Permalink
Merge branch 'master' into handlebars
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/hopen/runner.cljs
  • Loading branch information
green-coder committed Apr 5, 2019
2 parents 87895f9 + 228b5e2 commit 3f81ea4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
:target-path "target/%s"

:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/clojurescript "1.10.520"]]
[org.clojure/clojurescript "1.10.520"]
[instaparse "1.4.10"]]
:plugins [[lein-doo "0.1.10"]]
:cljsbuild
{:builds [{:id "node-test"
Expand Down
4 changes: 1 addition & 3 deletions src/hopen/renderer/xf.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
(apply f env args)
(if-let [f (get-in env [:bindings f-symb])]
(apply f (mapv f-eval args))
(throw (#?(:clj Exception.
:cljs js/Error.)
(str "Function " f-symb " not found in env " env))))))
(util/throw-exception (str "Function " f-symb " not found in env " env)))))
:else element))]
(f-eval element)))

Expand Down
10 changes: 10 additions & 0 deletions src/hopen/syntax/util.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns hopen.syntax.util
(:require [clojure.string :as str]))

(defn re-quote
"Escapes characters in the string that are not safe to use in a regex.
Function ported to Clojure from https://github.com/google/closure-library/blob/0257667129eded0cb9b86b4701e50c986b5db648/closure/goog/string/string.js#L1016"
[s]
(-> s
(str/replace #"[-()\[\]{}+?*.$\^|,:#<!\\]" #(str "\\" %))
(str/replace #"\x08", "\\x08")))
4 changes: 4 additions & 0 deletions src/hopen/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@
coll))
[data]
path)))

(defn throw-exception [message]
(throw (#?(:clj Exception.
:cljs js/Error.) message)))
2 changes: 2 additions & 0 deletions test/hopen/runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
[doo.runner :refer-macros [doo-all-tests doo-tests]]
[hopen.renderer.xf-test]
[hopen.syntax.handlebars-test]
[hopen.syntax.util-test]
[hopen.util-test]))

(doo-tests 'hopen.renderer.xf-test
'hopen.syntax.handlebars-test
'hopen.syntax.util-test
'hopen.util-test)
13 changes: 13 additions & 0 deletions test/hopen/syntax/util_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns hopen.syntax.util-test
(:require #?(:clj [clojure.test :refer [deftest testing is are]]
:cljs [cljs.test :refer [deftest testing is are]
:include-macros true])
[hopen.syntax.util :refer [re-quote]]))

(deftest re-quote-test
(are [input output]
(= (re-quote input) output)

"bonjour" "bonjour"
"{{}}" "\\{\\{\\}\\}"
"<%%>" "\\<%%>"))

0 comments on commit 3f81ea4

Please sign in to comment.