Permalink
Browse files

Experimental: drop cljs macros namespace, merge into tower.clj

  • Loading branch information...
1 parent b13c62c commit 527ff0584caaaccc9353ceec28f85e74e5832e70 @ptaoussanis committed Apr 24, 2014
Showing with 17 additions and 21 deletions.
  1. +2 −2 README.md
  2. +13 −6 src/taoensso/tower.clj
  3. +2 −2 src/taoensso/tower.cljs
  4. +0 −11 src/taoensso/tower/cljs_macros.clj
View
@@ -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
@@ -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.
@@ -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))
;;;
@@ -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
@@ -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.
@@ -1,11 +0,0 @@
-(ns taoensso.tower.cljs-macros
- {:author "Peter Taoussanis"}
- (:require [taoensso.tower :as tower]))
-
-(defmacro dict-compile
- "Tower's standard dictionary compiler, as a compile-time macro."
- [dict] (tower/dict-compile dict))
-
-(defmacro with-tscope [translation-scope & body]
- `(binding [taoensso.tower/*tscope* ~translation-scope]
- ~@body))

0 comments on commit 527ff05

Please sign in to comment.