Skip to content

Commit

Permalink
GitHub Issue #15 - remove reference to aget and aset for JS property …
Browse files Browse the repository at this point in the history
…access
  • Loading branch information
oakmac committed Jan 13, 2018
1 parent 23cb098 commit 799d041
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
77 changes: 58 additions & 19 deletions cljs-server/cljs_cheatsheet_server/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(def clj-string-ns "clojure.string")
(def clj-set-ns "clojure.set")


(def symbols
"Keeps track of the symbols on the cheatsheet that need tooltips.
Used to produce symbols.json"
Expand All @@ -32,15 +33,18 @@
(defn- json-stringify [js-thing]
(js/JSON.stringify js-thing nil 2))


(hiccups/defhtml tt-icon [id]
[:img.tooltip-icon-0e91b
{:alt ""
:data-info-id id
:src "img/info-circle.svg"}])


(hiccups/defhtml literal [n]
[:span.literal-c3029 n])


(hiccups/defhtml fn-link
([symbol-name]
(fn-link symbol-name cljs-core-ns))
Expand All @@ -53,6 +57,7 @@
:href (docs-href symbol-name name-space)}
(html-encode symbol-name)])))


(hiccups/defhtml inside-fn-link
([symbol-name]
(inside-fn-link symbol-name cljs-core-ns))
Expand Down Expand Up @@ -128,6 +133,7 @@
(fn-link "nil?")
(fn-link "some?")]]]]])


(hiccups/defhtml functions-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "#( ) Functions" (tt-icon "functions")]
Expand Down Expand Up @@ -168,6 +174,7 @@
(fn-link "fn?")
(fn-link "ifn?")]]]]])


(hiccups/defhtml numbers-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Numbers" (tt-icon "numbers")]
Expand Down Expand Up @@ -225,6 +232,7 @@
(fn-link "rand")
(fn-link "rand-int")]]]]])


(hiccups/defhtml strings-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "\" \" Strings" (tt-icon "strings")]
Expand Down Expand Up @@ -285,6 +293,7 @@
(literal "(clojure.string/)")
(fn-link "blank?" clj-string-ns)]]]]])


(hiccups/defhtml atoms-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Atoms / State" (tt-icon "atoms")]
Expand Down Expand Up @@ -315,6 +324,7 @@
(fn-link "set-validator!")
(fn-link "get-validator")]]]]])


(hiccups/defhtml js-interop-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "JavaScript Interop"]
Expand All @@ -335,13 +345,15 @@
[:tr
[:td.label-9e0b7 "Get Property"]
[:td.body-885f4
[:div.row-5dec8 "(.-innerHTML el)"]
[:div.row-5dec8 "(" (inside-fn-link "aget") " el \"innerHTML\")"]]]
[:div.row-5dec8 "(.-innerHTML el)"]]]
;; TODO: How to show oget here?
; [:div.row-5dec8 "(" (inside-fn-link "aget") " el \"innerHTML\")"]]]
[:tr
[:td.label-9e0b7 "Set Property"]
[:td.body-885f4
[:div.row-5dec8 "(" (inside-fn-link "set!") " (.-innerHTML el) \"Hi!\")"]
[:div.row-5dec8 "(" (inside-fn-link "aset") " el \"innerHTML\" \"Hi!\")"]]]
[:div.row-5dec8 "(" (inside-fn-link "set!") " (.-innerHTML el) \"Hi!\")"]]]
;; TODO: how to show aset here?
; [:div.row-5dec8 "(" (inside-fn-link "aset") " el \"innerHTML\" \"Hi!\")"]]]
[:tr
[:td.label-9e0b7 "Delete Property"]
[:td.body-885f4
Expand Down Expand Up @@ -373,6 +385,7 @@
[:div.row-5dec8 "(js/console.log my-obj)"]
[:div.row-5dec8 "(.html (js/jQuery \"#myDiv\") \"Hi!\")"]]]]]])


(hiccups/defhtml collections-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Collections" (tt-icon "collections")]
Expand Down Expand Up @@ -413,6 +426,7 @@
(fn-link "map?")
(fn-link "seq?")]]]]])


(hiccups/defhtml lists-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "( ) Lists" (tt-icon "lists")]
Expand All @@ -438,6 +452,7 @@
(fn-link "rest")
(fn-link "pop")]]]]])


(hiccups/defhtml vectors-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "[ ] Vectors" (tt-icon "vectors")]
Expand Down Expand Up @@ -473,6 +488,7 @@
(fn-link "filterv")
(fn-link "reduce-kv")]]]]])


(hiccups/defhtml sets-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "#{ } Sets" (tt-icon "sets")]
Expand Down Expand Up @@ -513,6 +529,7 @@
(fn-link "subset?" clj-set-ns)
(fn-link "superset?" clj-set-ns)]]]]])


(hiccups/defhtml maps-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "{ } Maps" (tt-icon "maps")]
Expand Down Expand Up @@ -562,6 +579,7 @@
(fn-link "subseq")
(fn-link "rsubseq")]]]]])


(hiccups/defhtml create-seq-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Create a Seq"]
Expand Down Expand Up @@ -598,6 +616,7 @@
(fn-link "keep")
(fn-link "keep-indexed")]]]]])


(hiccups/defhtml seq-in-out-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Seq in, Seq out" (tt-icon "sequences")]
Expand Down Expand Up @@ -675,6 +694,7 @@
(fn-link "for")
(fn-link "replace")]]]]])


(hiccups/defhtml use-seq-section []
[:div.section-31efe
[:h3.section-title-8ccf5 "Using a Seq"]
Expand Down Expand Up @@ -793,6 +813,7 @@
[:td.cell-e6fd2.right-border-c1b54 [:code "nil"]]
[:td.cell-e6fd2 [:code "false"]]]]])


(hiccups/defhtml function-shorthand-table []
[:table.exmpl-tbl-42d9f
[:thead
Expand All @@ -808,11 +829,14 @@
[:td.code-72fa0 [:pre "(fn [a b c]\n (my-fn a b c))"]]]
[:tr
[:td.code-72fa0.right-border-c1b54
{:style "font-size:10px"}
{:style "font-size: 10px"}
"#(* % (apply + %&))"]
[:td.code-72fa0 [:pre {:style "font-size:10px"}
"(fn [x & the-rest]\n"
" (* x (apply + the-rest)))"]]]]])
[:td.code-72fa0
[:pre
{:style "font-size: 10px"}
"(fn [x & the-rest]\n"
" (* x (apply + the-rest)))"]]]]])


(hiccups/defhtml basics-tooltips []

Expand Down Expand Up @@ -870,6 +894,7 @@
[:p "The " [:code "clojure.string"] " namespace provides many useful "
"functions for dealing with strings."]])


(hiccups/defhtml collections-tooltips []
[:div#tooltip-collections.tooltip-53dde {:style "display:none"}
[:p
Expand Down Expand Up @@ -949,6 +974,7 @@
"Keywords can be used as a function to get a value from a map. "
"They are commonly used as map keys for this reason."]])


(hiccups/defhtml sequences-tooltips []
[:div#tooltip-sequences.tooltip-53dde {:style "display:none"}
[:p
Expand All @@ -969,12 +995,14 @@
[:code "doseq"] " function. This is useful when you want to see the "
"results of a side-effecting function over an entire sequence."]])


(hiccups/defhtml info-tooltips []
[:section
(basics-tooltips)
(collections-tooltips)
(sequences-tooltips)])


;;------------------------------------------------------------------------------
;; Header and Footer
;;------------------------------------------------------------------------------
Expand All @@ -986,12 +1014,14 @@
"ClojureScript Cheatsheet"]
[:input#searchInput {:type "text" :placeholder "Search"}]])


(def clojure-cheatsheet-href "http://clojure.org/cheatsheet")
(def clojure-tooltip-cheatsheet-href "http://jafingerhut.github.io/cheatsheet/clojuredocs/cheatsheet-tiptip-cdocs-summary.html")
(def clojurescript-github-href "https://github.com/clojure/clojurescript")
(def repo-href "https://github.com/oakmac/cljs-cheatsheet/")
(def license-href "https://github.com/oakmac/cljs-cheatsheet/blob/master/LICENSE.md")


;; include this? "Please copy, improve, and share this work."
;; TODO: improve the markup here
(hiccups/defhtml footer []
Expand All @@ -1010,6 +1040,7 @@
[:label.quiet-5d4e8 "license: "]
[:a.ftr-link-e980e {:href license-href} "MIT"]]])


;;------------------------------------------------------------------------------
;; Head and Script Includes
;;------------------------------------------------------------------------------
Expand All @@ -1026,9 +1057,11 @@
[:link {:rel "apple-touch-icon" :href "apple-touch-icon.png"}]
[:link {:rel "stylesheet" :href "css/main.min.css"}]])


(hiccups/defhtml script-tags []
[:script {:src "js/cheatsheet.min.js"}])


;;------------------------------------------------------------------------------
;; Body
;;------------------------------------------------------------------------------
Expand Down Expand Up @@ -1095,18 +1128,21 @@
[:div.two-col-container
[:div.column (bitwise-section)]]])


(defn cheatsheet-page []
(str "<!doctype html>"
"<html>"
(head)
"<body>"
(header)
(body)
(footer)
(info-tooltips)
(script-tags)
"</body>"
"</html>"))
(str
"<!doctype html>"
"<html>"
(head)
"<body>"
(header)
(body)
(footer)
(info-tooltips)
(script-tags)
"</body>"
"</html>"))


;;------------------------------------------------------------------------------
;; Init
Expand All @@ -1115,12 +1151,15 @@
(defn- write-cheatsheet-html! []
(.writeFileSync fs "public/index.html" (cheatsheet-page)))


(defn- write-symbols-json! []
(.writeFileSync fs "symbols.json" (-> @symbols sort clj->js json-stringify)))


(write-cheatsheet-html!)
(write-symbols-json!)


;; needed for :nodejs cljs build
(def always-nil (constantly nil))
(set! *main-cli-fn* always-nil)
4 changes: 2 additions & 2 deletions public/index.html

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
"cljs.core/>=",
"cljs.core/aclone",
"cljs.core/add-watch",
"cljs.core/aget",
"cljs.core/and",
"cljs.core/apply",
"cljs.core/array",
"cljs.core/array-map",
"cljs.core/array?",
"cljs.core/as->",
"cljs.core/aset",
"cljs.core/assoc",
"cljs.core/assoc-in",
"cljs.core/associative?",
Expand Down

0 comments on commit 799d041

Please sign in to comment.