Skip to content

Commit

Permalink
Experimental: drop cljs macros namespace, merge into tower.clj
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Apr 26, 2014
1 parent b13c62c commit 527ff05
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -111,8 +111,8 @@ In all cases, translation requests are logged upon fallback to fallback locale o

```clojure
(ns my-clojurescript-ns
(:require-macros [taoensso.tower.cljs-macros :as tower-macros :refer (with-tscope)])
(:require [taoensso.tower :as tower]))
(:require-macros [taoensso.tower :as tower-macros :refer (with-tscope)])
(:require [taoensso.tower :as tower]))

(def ^:private tconfig
{:fallback-locale :en
Expand Down
19 changes: 13 additions & 6 deletions src/taoensso/tower.clj
Expand Up @@ -312,8 +312,10 @@
(comment (scoped :a.b :c :d))

(def ^:dynamic *tscope* nil)
(defmacro with-tscope "Executes body with given translation scope binding."
[translation-scope & body] `(binding [*tscope* ~translation-scope] ~@body))
(defmacro ^:also-cljs with-tscope
"Executes body with given translation scope binding."
[translation-scope & body]
`(binding [taoensso.tower/*tscope* ~translation-scope] ~@body))

(def example-tconfig
"Example/test config as passed to `make-t`, Ring middleware, etc.
Expand Down Expand Up @@ -431,8 +433,13 @@
;; 1-level deep merge:
(apply merge-with merge)))))

(def dict-compile (comp dict-compile-prepared dict-prepare)) ; Public for cljs
(comment (time (dotimes [_ 1000] (dict-compile (:dictionary example-tconfig)))))
(def dict-compile* (comp dict-compile-prepared dict-prepare)) ; Public for cljs macro
(comment (time (dotimes [_ 1000] (dict-compile* (:dictionary example-tconfig)))))

(defmacro ^:only-cljs dict-compile
"Tower's standard dictionary compiler, as a compile-time macro. For use with
ClojureScript."
[dict] (dict-compile* dict))

;;;

Expand All @@ -449,13 +456,13 @@
"Missing translation" args))}} tconfig]

(let [nstr (fn [x] (if (nil? x) "nil" (str x)))
dict-cached (when-not dev-mode? (dict-compile dictionary))
dict-cached (when-not dev-mode? (dict-compile* dictionary))
;;; Could cache these for extra perf (probably overkill):
find-scoped (fn [d k l] (some #(get-in d [(scope-fn k) %]) (loc-tree l)))
find-unscoped (fn [d k l] (some #(get-in d [ k %]) (loc-tree l)))]

(fn new-t [loc k-or-ks & fmt-args]
(let [dict (or dict-cached (dict-compile dictionary)) ; Recompile (slow)
(let [dict (or dict-cached (dict-compile* dictionary)) ; Recompile (slow)
ks (if (vector? k-or-ks) k-or-ks [k-or-ks])
tr
(or
Expand Down
4 changes: 2 additions & 2 deletions src/taoensso/tower.cljs
@@ -1,9 +1,9 @@
(ns taoensso.tower
"Experimental ClojureScript support for Tower."
{:author "Peter Taoussanis"}
(:require-macros [taoensso.tower :as tower-macros])
(:require [clojure.string :as str]
[taoensso.encore :as encore])
(:require-macros [taoensso.tower.cljs-macros :as tower-macros]))
[taoensso.encore :as encore]))

;;;; TODO
;; * NB: Locale-aware format fn for fmt-str.
Expand Down
11 changes: 0 additions & 11 deletions src/taoensso/tower/cljs_macros.clj

This file was deleted.

0 comments on commit 527ff05

Please sign in to comment.