Skip to content

Commit

Permalink
upper case parse-tag so it is friendly with .-nodeName
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller committed Nov 7, 2016
1 parent 9e47cc3 commit 034b521
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

:profiles {:dev
{:source-paths ["dev"]
:dependencies [[org.clojure/clojure "1.7.0"]
[thheller/shadow-build "1.0.201"]
[org.clojure/clojurescript "1.7.228"]]}}
:dependencies [[org.clojure/clojure "1.9.0-alpha14"]
[thheller/shadow-build "1.0.236"]
[org.clojure/clojurescript "1.9.293"]]}}

:source-paths ["src/clj"
"src/cljs"]
Expand Down
36 changes: 19 additions & 17 deletions src/cljs/shadow/api.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
which means it triggers earlier"
[script]
(let [init-fn (dom/data script :fn)
dom-ref (dom/data script :ref)
dom-ref (dom/data script :ref)
args (dom/get-html script)
args (when (and args (not= "" args))
(reader/read-string args))
Expand All @@ -30,10 +30,10 @@
(throw (ex-info "script tag with invalid dom ref" {:dom-ref dom-ref :init-fn init-fn :script script})))]

(let [queued-fn (goog/getObjectByName init-fn)]
(if queued-fn
(do (log "init" init-fn)
(apply queued-fn args))
(log "unknown init function" init-fn args)))))
(if queued-fn
(do (log "init" init-fn)
(apply queued-fn args))
(log "unknown init function" init-fn args)))))

(def available-namespaces (atom #{}))

Expand All @@ -44,17 +44,19 @@
will pick remaining tags"
[node]
(doseq [script (dom/query "script[type=\"shadow/run\"]" node)
:let [fn (dom/data script :fn)
fn-ns (.substring fn 0 (.lastIndexOf fn "."))]
:when (contains? @available-namespaces fn-ns)]
(run-script-tag script)))
:let [fn (dom/data script :fn)
fn-ns (.substring fn 0 (.lastIndexOf fn "."))]
:when (contains? @available-namespaces fn-ns)]
(run-script-tag script)))

(defn ^:export ns-ready* [ns-name]
(log "ns-ready" ns-name)
(swap! available-namespaces conj ns-name)
(let [ns-name (str/replace ns-name #"-" "_")]
(doseq [script (dom/query "script[type=\"shadow/run\"]")
:let [fn (dom/data script :fn)
fn-ns (.substring fn 0 (.lastIndexOf fn "."))]
:when (= ns-name fn-ns)]
(run-script-tag script))))
;; don't run things twice, not live-reload friendly
(when-not (contains? @available-namespaces ns-name)
(log "ns-ready" ns-name)
(swap! available-namespaces conj ns-name)
(let [ns-name (str/replace ns-name #"-" "_")]
(doseq [script (dom/query "script[type=\"shadow/run\"]")
:let [fn (dom/data script :fn)
fn-ns (.substring fn 0 (.lastIndexOf fn "."))]
:when (= ns-name fn-ns)]
(run-script-tag script)))))
8 changes: 4 additions & 4 deletions src/cljs/shadow/dom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@
fhash (.indexOf spec "#")]
(cond
(and (= -1 fdot) (= -1 fhash))
[spec nil nil]
[(str/upper-case spec) nil nil]

(= -1 fhash)
[(.substring spec 0 fdot)
[(str/upper-case (.substring spec 0 fdot))
nil
(str/replace (.substring spec (inc fdot)) #"\." " ")]

(= -1 fdot)
[(.substring spec 0 fhash)
[(str/upper-case (.substring spec 0 fhash))
(.substring spec (inc fhash))
nil]

(> fhash fdot)
(throw (str "cant have id after class?" spec))

:else
[(.substring spec 0 fhash)
[(str/upper-case (.substring spec 0 fhash))
(.substring spec (inc fhash) fdot)
(str/replace (.substring spec (inc fdot)) #"\." " ")])))

Expand Down

0 comments on commit 034b521

Please sign in to comment.