diff --git a/Gruntfile.js b/Gruntfile.js index 821e3f0..62482a7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -236,7 +236,7 @@ grunt.initConfig({ watch: { files: { - 'public/css/main.min.css': 'less/main.less' + 'public/css/main.min.css': 'less/000-main.less' } } }, diff --git a/cljs-server/cljs_cheatsheet_server/core.cljs b/cljs-server/cljs_cheatsheet_server/core.cljs index a24ab04..7319b3f 100644 --- a/cljs-server/cljs_cheatsheet_server/core.cljs +++ b/cljs-server/cljs_cheatsheet_server/core.cljs @@ -325,6 +325,10 @@ (fn-link "get-validator")]]]]]) +(def cljs-oops-lib-url "https://github.com/binaryage/cljs-oops") +(def cljs-docs-url "https://github.com/binaryage/cljs-oops#object-operations") + + (hiccups/defhtml js-interop-section [] [:div.section-31efe [:h3.section-title-8ccf5 "JavaScript Interop"] @@ -345,15 +349,19 @@ [:tr [:td.label-9e0b7 "Get Property"] [:td.body-885f4 - [:div.row-5dec8 "(.-innerHTML el)"]]] - ;; TODO: How to show oget here? - ; [:div.row-5dec8 "(" (inside-fn-link "aget") " el \"innerHTML\")"]]] + [:div.row-5dec8 "(.-innerHTML el)"] + [:div.row-5dec8 + [:div.msg-b3d36 + "Using " [:a {:href cljs-oops-lib-url} "cljs-oops"] " library:"] + [:div "(" [:a.inside-fn-c7607 {:href cljs-docs-url} "oget"] " el \"innerHTML\")"]]]] [:tr [:td.label-9e0b7 "Set Property"] [:td.body-885f4 - [: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!\")"]]] + [:div.row-5dec8 "(" (inside-fn-link "set!") " (.-innerHTML el) \"Hi!\")"] + [:div.row-5dec8 + [:div.msg-b3d36 + "Using " [:a {:href cljs-oops-lib-url} "cljs-oops"] " library:"] + [:div "(" [:a.inside-fn-c7607 {:href cljs-docs-url} "aget"] " el \"innerHTML\")"]]]] [:tr [:td.label-9e0b7 "Delete Property"] [:td.body-885f4 diff --git a/less/000-main.less b/less/000-main.less new file mode 100644 index 0000000..2d95d2f --- /dev/null +++ b/less/000-main.less @@ -0,0 +1,2 @@ +@import "001-normalize-3.0.3.less"; +@import "010-cheatsheet.less"; diff --git a/less/normalize-3.0.3.less b/less/001-normalize-3.0.3.less similarity index 100% rename from less/normalize-3.0.3.less rename to less/001-normalize-3.0.3.less diff --git a/less/main.less b/less/010-cheatsheet.less similarity index 98% rename from less/main.less rename to less/010-cheatsheet.less index d163dbd..c524964 100644 --- a/less/main.less +++ b/less/010-cheatsheet.less @@ -1,5 +1,3 @@ -@import "normalize-3.0.3.less"; - //------------------------------------------------------------------------------ // Fonts //------------------------------------------------------------------------------ @@ -745,3 +743,11 @@ em { .links-446e0 { margin-bottom: 4px; } + +.msg-b3d36 { + color: #888; + font-family: "Open Sans", sans-serif; + font-size: 12px; + font-style: italic; + margin-bottom: 2px; +} diff --git a/public/index.html b/public/index.html index e00398e..72f3092 100644 --- a/public/index.html +++ b/public/index.html @@ -1,4 +1,4 @@ -ClojureScript Cheatsheet

ClojureScript LogoClojureScript Cheatsheet

Basics

" " Strings

Create"abc"strname
Use(.-length my-str)countgetsubs(clojure.string/)joinescapesplitsplit-linesreplacereplace-firstreverse
Regex#"pattern"re-findre-seqre-matchesre-pattern(clojure.string/)replacereplace-first
Letters(clojure.string/)capitalizelower-caseupper-case
Trim(clojure.string/)trimtrim-newlinetrimltrimr
Testcharstring?(clojure.string/)blank?

Atoms / State

Createatom
Get Value@my-atom → (deref my-atom)
Set Valueswap!reset!compare-and-set!
Watchadd-watchremove-watch
Validatorsset-validator!get-validator

JavaScript Interop

Create Object#js {}js-obj
Create Array#js []arraymake-arrayaclone
Get Property
(.-innerHTML el)
Set Property
(set! (.-innerHTML el) "Hi!")
Delete Propertyjs-delete
Convert Betweenclj->jsjs->clj
Type Testsarray?fn?number?object?string?
Exceptionstrycatchfinallythrow
External Library
(js/alert "Hello world!")
(js/console.log my-obj)
(.html (js/jQuery "#myDiv") "Hi!")

JavaScript Interop

Create Object#js {}js-obj
Create Array#js []arraymake-arrayaclone
Get Property
(.-innerHTML el)
Set Property
(set! (.-innerHTML el) "Hi!")
Delete Propertyjs-delete
Convert Betweenclj->jsjs->clj
Type Testsarray?fn?number?object?string?
Exceptionstrycatchfinallythrow
External Library
(js/alert "Hello world!")
(js/console.log my-obj)
(.html (js/jQuery "#myDiv") "Hi!")

" " Strings

Create"abc"strname
Use(.-length my-str)countgetsubs(clojure.string/)joinescapesplitsplit-linesreplacereplace-firstreverse
Regex#"pattern"re-findre-seqre-matchesre-pattern(clojure.string/)replacereplace-first
Letters(clojure.string/)capitalizelower-caseupper-case
Trim(clojure.string/)trimtrim-newlinetrimltrimr
Testcharstring?(clojure.string/)blank?

Atoms / State

Createatom
Get Value@my-atom → (deref my-atom)
Set Valueswap!reset!compare-and-set!
Watchadd-watchremove-watch
Validatorsset-validator!get-validator

Collections

[ ] Vectors

Create[]vectorvec
Examine
(my-vec idx) → (nth my-vec idx)
getpeek
'Change'assocpopsubvecreplaceconjrseq
Loopmapvfiltervreduce-kv

#{ } Sets

Create#{}sethash-setsorted-setsorted-set-by
Examine
(my-set itm) → (get my-set itm)
contains?
'Change'conjdisj
Set Ops(clojure.set/)uniondifferenceintersectionselect
Test(clojure.set/)subset?superset?

[ ] Vectors

Create[]vectorvec
Examine
(my-vec idx) → (nth my-vec idx)
getpeek
'Change'assocpopsubvecreplaceconjrseq
Loopmapvfiltervreduce-kv

#{ } Sets

Create#{}sethash-setsorted-setsorted-set-by
Examine
(my-set itm) → (get my-set itm)
contains?
'Change'conjdisj
Set Ops(clojure.set/)uniondifferenceintersectionselect
Test(clojure.set/)subset?superset?

Sequences

Create a Seq

From Collectionseqvalskeysrseqsubseqrsubseq
Producer Functionslazy-seqrepeatedlyiterate
From Constantrepeatrange
From Otherre-seqtree-seq
From Sequencekeepkeep-indexed

Misc