From a35293373d8dfa05c5d197eee079cdedf9780d8f Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Mon, 20 Feb 2023 16:35:24 -0600 Subject: [PATCH] update libraries (#51) --- cljs-client/cljs_cheatsheet_client/dom.cljs | 8 +- cljs-client/cljs_cheatsheet_client/html.cljs | 35 +- .../cljs_cheatsheet_client/tooltips.cljs | 4 +- cljs-server/cljs_cheatsheet_server/core.cljs | 1207 +++++++++-------- docfiles/cljs.core_keep-indexed.cljsdoc | 2 +- project.clj | 16 +- 6 files changed, 640 insertions(+), 632 deletions(-) diff --git a/cljs-client/cljs_cheatsheet_client/dom.cljs b/cljs-client/cljs_cheatsheet_client/dom.cljs index b682405..af61f1b 100644 --- a/cljs-client/cljs_cheatsheet_client/dom.cljs +++ b/cljs-client/cljs_cheatsheet_client/dom.cljs @@ -36,10 +36,10 @@ (defn get-element-box [el] (let [$el ($ el) o (.offset $el) - x (oget o "left") - y (oget o "top") - height (ocall $el "outerHeight") - width (ocall $el "outerWidth")] + x (js/parseFloat (oget o "left")) + y (js/parseFloat (oget o "top")) + height (js/parseFloat (ocall $el "outerHeight")) + width (js/parseFloat (ocall $el "outerWidth"))] {:x1 x :x2 (+ x width) :y1 y diff --git a/cljs-client/cljs_cheatsheet_client/html.cljs b/cljs-client/cljs_cheatsheet_client/html.cljs index 92fcb57..32db6a8 100644 --- a/cljs-client/cljs_cheatsheet_client/html.cljs +++ b/cljs-client/cljs_cheatsheet_client/html.cljs @@ -3,7 +3,7 @@ [hiccups.core :as hiccups]) (:require hiccups.runtime - [clojure.string :refer [blank?]] + [clojure.string :as str] [cljs-cheatsheet.util :refer [docs-href js-log log]] [cljs-cheatsheet-client.util :refer [extract-namespace extract-symbol split-full-name]])) @@ -18,36 +18,37 @@ (str "code-b64c8 " (if (even? idx) "dark-even-7aff7" "dark-odd-6cd97"))) -(hiccups/defhtml code-signature [idx sig nme] +(defn CodeSignature [idx sig nme] (let [len (count sig) sig2 (subs sig 1 (dec len))] [:code {:class (code-signature-class idx)} - "(" (html-encode nme) - (when-not (blank? sig2) (str " " (html-encode sig2))) + "(" nme + (when-not (str/blank? sig2) + (str " " sig2)) ")"])) -(hiccups/defhtml related-fn-link [s] +(defn RelatedFnLink [s] [:a.related-link-674b6 {:data-full-name (:full-name s) :href (docs-href (:symbol s) (:namespace s))} - (html-encode (:symbol s))]) + (:symbol s)]) -(hiccups/defhtml related-links-for-ns [ns1 all-related] +(defn RelatedLinksForNs [ns1 all-related] (let [filtered-related (filter #(= (:namespace %) ns1) all-related)] (list (when-not (= ns1 cljs-core-ns) [:span.tt-literal-3cdfc "(" ns1 "/)"]) - (map related-fn-link filtered-related)))) + (map RelatedFnLink filtered-related)))) -(hiccups/defhtml related-links [r] +(defn RelatedLinks [r] (let [r2 (map split-full-name r) namespaces (distinct (map :namespace r2))] (list [:h5.related-hdr-915e5 "Related"] [:div.related-links-f8e49 - (map #(related-links-for-ns % r2) namespaces)]))) + (map #(RelatedLinksForNs % r2) namespaces)]))) -(hiccups/defhtml inline-tooltip [tt] +(hiccups/defhtml InlineTooltip [tt] (let [desc-html (:description-html tt) id (:id tt) full-name (:full-name tt) @@ -62,10 +63,12 @@ [:h4.tooltip-hdr-db7c5 (when-not (= cljs-core-ns ns1) [:span.namespace-2e700 ns1 "/"]) - (html-encode symbol-name) + symbol-name (when type [:span.type-7920d type])] [:div.signature-4086a - (map-indexed #(code-signature %1 %2 symbol-name) signature)] - [:div.description-26a4d desc-html] - (when (and related (first related) (not (blank? (first related)))) - (related-links related))])) + (map-indexed #(CodeSignature %1 %2 symbol-name) signature)] + [:div + {:dangerously-set-inner-HTML + {:__html (str "
" desc-html "
")}}] + (when (and related (first related) (not (str/blank? (first related)))) + (RelatedLinks related))])) diff --git a/cljs-client/cljs_cheatsheet_client/tooltips.cljs b/cljs-client/cljs_cheatsheet_client/tooltips.cljs index fe9e193..e5bb529 100644 --- a/cljs-client/cljs_cheatsheet_client/tooltips.cljs +++ b/cljs-client/cljs_cheatsheet_client/tooltips.cljs @@ -1,6 +1,6 @@ (ns cljs-cheatsheet-client.tooltips (:require - [cljs-cheatsheet-client.html :refer [inline-tooltip]] + [cljs-cheatsheet-client.html :refer [InlineTooltip]] [cljs-cheatsheet-client.state :refer [active-tooltip mouse-position mousetrap-boxes]] [cljs-cheatsheet-client.util :refer [fetch-clj half point-inside-box?]] [cljs-cheatsheet.util :refer [js-log log]] @@ -24,7 +24,7 @@ ;;------------------------------------------------------------------------------ (defn- create-inline-tooltip! [tt] - (.append ($ "body") (inline-tooltip tt))) + (.append ($ "body") (InlineTooltip tt))) ;;------------------------------------------------------------------------------ ;; Hide and Show diff --git a/cljs-server/cljs_cheatsheet_server/core.cljs b/cljs-server/cljs_cheatsheet_server/core.cljs index 6dff771..2c9ff04 100644 --- a/cljs-server/cljs_cheatsheet_server/core.cljs +++ b/cljs-server/cljs_cheatsheet_server/core.cljs @@ -2,8 +2,8 @@ (:require-macros [hiccups.core :as hiccups]) (:require - [clojure.string :refer [blank? join replace]] [cljs-cheatsheet.util :refer [docs-href js-log log]] + [clojure.string :refer [blank? join replace]] [hiccups.runtime :as hiccupsrt])) ;; This file produces: @@ -34,21 +34,18 @@ (defn- json-stringify [js-thing] (js/JSON.stringify js-thing nil 2)) - -(hiccups/defhtml tt-icon [id] +(defn TooltipIcon [id] [:img.tooltip-icon-0e91b {:alt "" :data-info-id id :src "img/info-circle.svg"}]) - -(hiccups/defhtml literal [n] +(defn CodeText [n] [:span.literal-c3029 n]) - -(hiccups/defhtml fn-link +(defn FnLink ([symbol-name] - (fn-link symbol-name clojure-core-ns)) + (FnLink symbol-name clojure-core-ns)) ([symbol-name name-space] (let [full-name (str name-space "/" symbol-name) ;; add this symbol to the docs list @@ -56,12 +53,11 @@ [:a.fn-a8476 {:data-full-name full-name :href (docs-href symbol-name name-space)} - (html-encode symbol-name)]))) - + symbol-name]))) -(hiccups/defhtml inside-fn-link +(defn InsideFnLink ([symbol-name] - (inside-fn-link symbol-name clojure-core-ns)) + (InsideFnLink symbol-name clojure-core-ns)) ([symbol-name name-space] (let [full-name (str name-space "/" symbol-name) ;; add this symbol to the docs list @@ -69,269 +65,269 @@ [:a.inside-fn-c7607 {:data-full-name (str name-space "/" symbol-name) :href (docs-href symbol-name name-space)} - (html-encode symbol-name)]))) + symbol-name]))) ;;------------------------------------------------------------------------------ ;; Sections ;;------------------------------------------------------------------------------ -(hiccups/defhtml basics-section [] +(defn BasicsSection [] [:div.section-31efe [:h3.section-title-8ccf5 "Basics"] [:table.tbl-902f0 [:tbody [:tr - [:td.label-9e0b7 "Define" (tt-icon "define")] - [:td.body-885f4 - (fn-link "def") - (fn-link "defn") - (fn-link "defn-") - (fn-link "let") - (fn-link "letfn") - (fn-link "declare") - (fn-link "ns")]] - [:tr - [:td.label-9e0b7 "Branch" (tt-icon "branch")] - [:td.body-885f4 - (fn-link "if") - (fn-link "if-not") - (fn-link "when") - (fn-link "when-not") - (fn-link "when-let") - (fn-link "when-first") - (fn-link "if-let") - (fn-link "cond") - (fn-link "condp") - (fn-link "case") - (fn-link "when-some") - (fn-link "if-some")]] + [:td.label-9e0b7 "Define" (TooltipIcon "define")] + [:td.body-885f4 + (FnLink "def") + (FnLink "defn") + (FnLink "defn-") + (FnLink "let") + (FnLink "letfn") + (FnLink "declare") + (FnLink "ns")]] + [:tr + [:td.label-9e0b7 "Branch" (TooltipIcon "branch")] + [:td.body-885f4 + (FnLink "if") + (FnLink "if-not") + (FnLink "when") + (FnLink "when-not") + (FnLink "when-let") + (FnLink "when-first") + (FnLink "if-let") + (FnLink "cond") + (FnLink "condp") + (FnLink "case") + (FnLink "when-some") + (FnLink "if-some")]] [:tr [:td.label-9e0b7 "Compare"] [:td.body-885f4 - (fn-link "=") - (fn-link "not=") - (fn-link "and") - (fn-link "or") - (fn-link "not") - (fn-link "identical?") - (fn-link "compare")]] + (FnLink "=") + (FnLink "not=") + (FnLink "and") + (FnLink "or") + (FnLink "not") + (FnLink "identical?") + (FnLink "compare")]] [:tr [:td.label-9e0b7 "Loop"] [:td.body-885f4 - (fn-link "map") - (fn-link "map-indexed") - (fn-link "reduce") - (fn-link "for") - (fn-link "doseq") - (fn-link "dotimes") - (fn-link "while")]] + (FnLink "map") + (FnLink "map-indexed") + (FnLink "reduce") + (FnLink "for") + (FnLink "doseq") + (FnLink "dotimes") + (FnLink "while")]] [:tr [:td.label-9e0b7 "Test"] [:td.body-885f4 - (fn-link "true?") - (fn-link "false?") - (fn-link "instance?") - (fn-link "nil?") - (fn-link "some?")]]]]]) + (FnLink "true?") + (FnLink "false?") + (FnLink "instance?") + (FnLink "nil?") + (FnLink "some?")]]]]]) -(hiccups/defhtml functions-section [] +(defn FunctionSection [] [:div.section-31efe - [:h3.section-title-8ccf5 "#( ) Functions" (tt-icon "functions")] + [:h3.section-title-8ccf5 "#( ) Functions" (TooltipIcon "functions")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - [:div.row-5dec8 "#(...) → (fn [args] (...))" - (tt-icon "function-shorthand")] - (fn-link "fn") - (fn-link "defn") - (fn-link "defn-") - (fn-link "identity") - (fn-link "constantly") - (fn-link "comp") - (fn-link "complement") - (fn-link "partial") - (fn-link "juxt") - (fn-link "memoize") - (fn-link "fnil") - (fn-link "every-pred") - (fn-link "some-fn")]] + [:div.row-5dec8 "#(...) → (fn [args] (...))" + (TooltipIcon "function-shorthand")] + (FnLink "fn") + (FnLink "defn") + (FnLink "defn-") + (FnLink "identity") + (FnLink "constantly") + (FnLink "comp") + (FnLink "complement") + (FnLink "partial") + (FnLink "juxt") + (FnLink "memoize") + (FnLink "fnil") + (FnLink "every-pred") + (FnLink "some-fn")]] [:tr [:td.label-9e0b7 "Call"] [:td.body-885f4 - (fn-link "apply") - (fn-link "->") - (fn-link "->>") - (fn-link "as->") - (fn-link "cond->") - (fn-link "cond->>") - (fn-link "some->") - (fn-link "some->>")]] + (FnLink "apply") + (FnLink "->") + (FnLink "->>") + (FnLink "as->") + (FnLink "cond->") + (FnLink "cond->>") + (FnLink "some->") + (FnLink "some->>")]] [:tr [:td.label-9e0b7 "Test"] [:td.body-885f4 - (fn-link "fn?") - (fn-link "ifn?")]]]]]) + (FnLink "fn?") + (FnLink "ifn?")]]]]]) -(hiccups/defhtml numbers-section [] +(defn NumbersSection [] [:div.section-31efe - [:h3.section-title-8ccf5 "Numbers" (tt-icon "numbers")] + [:h3.section-title-8ccf5 "Numbers" (TooltipIcon "numbers")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Literals"] [:td.body-885f4 - (literal "7") - (literal "3.14") - (literal "-1.2e3") - (literal "0x0000ff")]] + (CodeText "7") + (CodeText "3.14") + (CodeText "-1.2e3") + (CodeText "0x0000ff")]] [:tr [:td.label-9e0b7 "Arithmetic"] [:td.body-885f4 - (fn-link "+") - (fn-link "-") - (fn-link "*") - (fn-link "/") - (fn-link "quot") - (fn-link "rem") - (fn-link "mod") - (fn-link "inc") - (fn-link "dec") - (fn-link "max") - (fn-link "min")]] + (FnLink "+") + (FnLink "-") + (FnLink "*") + (FnLink "/") + (FnLink "quot") + (FnLink "rem") + (FnLink "mod") + (FnLink "inc") + (FnLink "dec") + (FnLink "max") + (FnLink "min")]] [:tr [:td.label-9e0b7 "Compare"] [:td.body-885f4 - (fn-link "=") - (fn-link "==") - (fn-link "not=") - (fn-link "<") - (fn-link ">") - (fn-link "<=") - (fn-link ">=") - (fn-link "compare")]] + (FnLink "=") + (FnLink "==") + (FnLink "not=") + (FnLink "<") + (FnLink ">") + (FnLink "<=") + (FnLink ">=") + (FnLink "compare")]] [:tr [:td.label-9e0b7 "Cast"] [:td.body-885f4 - (fn-link "int")]] + (FnLink "int")]] [:tr [:td.label-9e0b7 "Test"] [:td.body-885f4 - (fn-link "zero?") - (fn-link "pos?") - (fn-link "neg?") - (fn-link "even?") - (fn-link "odd?") - (fn-link "number?") - (fn-link "integer?")]] + (FnLink "zero?") + (FnLink "pos?") + (FnLink "neg?") + (FnLink "even?") + (FnLink "odd?") + (FnLink "number?") + (FnLink "integer?")]] [:tr [:td.label-9e0b7 "Random"] [:td.body-885f4 - (fn-link "rand") - (fn-link "rand-int")]]]]]) + (FnLink "rand") + (FnLink "rand-int")]]]]]) -(hiccups/defhtml strings-section [] +(defn StringsSection [] [:div.section-31efe - [:h3.section-title-8ccf5 "\" \" Strings" (tt-icon "strings")] + [:h3.section-title-8ccf5 "\" \" Strings" (TooltipIcon "strings")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - (literal "\"abc\"") - (fn-link "str") - (fn-link "name")]] + (CodeText "\"abc\"") + (FnLink "str") + (FnLink "name")]] [:tr [:td.label-9e0b7 "Use"] [:td.body-885f4 - (literal "(.-length my-str)") - (fn-link "count") - (fn-link "get") - (fn-link "subs") - (literal "(clojure.string/)") - (fn-link "join" clj-string-ns) - (fn-link "escape" clj-string-ns) - (fn-link "split" clj-string-ns) - (fn-link "split-lines" clj-string-ns) - (fn-link "replace" clj-string-ns) - (fn-link "replace-first" clj-string-ns) - (fn-link "reverse" clj-string-ns)]] + (CodeText "(.-length my-str)") + (FnLink "count") + (FnLink "get") + (FnLink "subs") + (CodeText "(clojure.string/)") + (FnLink "join" clj-string-ns) + (FnLink "escape" clj-string-ns) + (FnLink "split" clj-string-ns) + (FnLink "split-lines" clj-string-ns) + (FnLink "replace" clj-string-ns) + (FnLink "replace-first" clj-string-ns) + (FnLink "reverse" clj-string-ns)]] [:tr [:td.label-9e0b7 "Regex"] [:td.body-885f4 [:span.literal-c3029 "#\"" [:span {:style "font-style:italic"} "pattern"] "\""] - (fn-link "re-find") - (fn-link "re-seq") - (fn-link "re-matches") - (fn-link "re-pattern") - (literal "(clojure.string/)") - (fn-link "replace" clj-string-ns) - (fn-link "replace-first" clj-string-ns)]] + (FnLink "re-find") + (FnLink "re-seq") + (FnLink "re-matches") + (FnLink "re-pattern") + (CodeText "(clojure.string/)") + (FnLink "replace" clj-string-ns) + (FnLink "replace-first" clj-string-ns)]] [:tr [:td.label-9e0b7 "Letters"] [:td.body-885f4 - (literal "(clojure.string/)") - (fn-link "capitalize" clj-string-ns) - (fn-link "lower-case" clj-string-ns) - (fn-link "upper-case" clj-string-ns)]] + (CodeText "(clojure.string/)") + (FnLink "capitalize" clj-string-ns) + (FnLink "lower-case" clj-string-ns) + (FnLink "upper-case" clj-string-ns)]] [:tr [:td.label-9e0b7 "Trim"] [:td.body-885f4 - (literal "(clojure.string/)") - (fn-link "trim" clj-string-ns) - (fn-link "trim-newline" clj-string-ns) - (fn-link "triml" clj-string-ns) - (fn-link "trimr" clj-string-ns)]] + (CodeText "(clojure.string/)") + (FnLink "trim" clj-string-ns) + (FnLink "trim-newline" clj-string-ns) + (FnLink "triml" clj-string-ns) + (FnLink "trimr" clj-string-ns)]] [:tr [:td.label-9e0b7 "Test"] [:td.body-885f4 - (fn-link "char") - (fn-link "string?") - (literal "(clojure.string/)") - (fn-link "includes?" clj-string-ns) - (fn-link "blank?" clj-string-ns)]]]]]) + (FnLink "char") + (FnLink "string?") + (CodeText "(clojure.string/)") + (FnLink "includes?" clj-string-ns) + (FnLink "blank?" clj-string-ns)]]]]]) -(hiccups/defhtml atoms-section [] +(defn AtomsSection [] [:div.section-31efe - [:h3.section-title-8ccf5 "Atoms / State" (tt-icon "atoms")] + [:h3.section-title-8ccf5 "Atoms / State" (TooltipIcon "atoms")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - (fn-link "atom")]] + (FnLink "atom")]] [:tr [:td.label-9e0b7 "Get Value"] [:td.body-885f4 - [:span.literal-c3029 "@my-atom → (" (inside-fn-link "deref") " my-atom)"]]] + [:span.literal-c3029 "@my-atom → (" (InsideFnLink "deref") " my-atom)"]]] [:tr [:td.label-9e0b7 "Set Value"] [:td.body-885f4 - (fn-link "swap!") - (fn-link "reset!") - (fn-link "compare-and-set!")]] + (FnLink "swap!") + (FnLink "reset!") + (FnLink "compare-and-set!")]] [:tr [:td.label-9e0b7 "Watch"] [:td.body-885f4 - (fn-link "add-watch") - (fn-link "remove-watch")]] + (FnLink "add-watch") + (FnLink "remove-watch")]] [:tr [:td.label-9e0b7 "Validators"] [:td.body-885f4 - (fn-link "set-validator!") - (fn-link "get-validator")]]]]]) + (FnLink "set-validator!") + (FnLink "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 [] +(defn JsInteropSection [] [:div.section-31efe [:h3.section-title-8ccf5 "JavaScript Interop"] [:table.tbl-902f0 @@ -339,15 +335,15 @@ [:tr [:td.label-9e0b7 "Create Object"] [:td.body-885f4 - (literal "#js {}") - (fn-link "js-obj" cljs-core-ns)]] + (CodeText "#js {}") + (FnLink "js-obj" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Create Array"] [:td.body-885f4 - (literal "#js []") - (fn-link "array" cljs-core-ns) - (fn-link "make-array" cljs-core-ns) - (fn-link "aclone" cljs-core-ns)]] + (CodeText "#js []") + (FnLink "array" cljs-core-ns) + (FnLink "make-array" cljs-core-ns) + (FnLink "aclone" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Get Property"] [:td.body-885f4 @@ -359,7 +355,7 @@ [:tr [:td.label-9e0b7 "Set Property"] [:td.body-885f4 - [:div.row-5dec8 "(" (inside-fn-link "set!" cljs-core-ns) " (.-innerHTML el) \"Hi!\")"] + [:div.row-5dec8 "(" (InsideFnLink "set!" cljs-core-ns) " (.-innerHTML el) \"Hi!\")"] [:div.row-5dec8 [:div.msg-b3d36 "Using " [:a {:href cljs-oops-lib-url} "cljs-oops"] " library:"] @@ -367,27 +363,27 @@ [:tr [:td.label-9e0b7 "Delete Property"] [:td.body-885f4 - (fn-link "js-delete" cljs-core-ns)]] + (FnLink "js-delete" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Convert Between"] [:td.body-885f4 - (fn-link "clj->js" cljs-core-ns) - (fn-link "js->clj" cljs-core-ns)]] + (FnLink "clj->js" cljs-core-ns) + (FnLink "js->clj" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Type Tests"] [:td.body-885f4 - (fn-link "array?" cljs-core-ns) - (fn-link "fn?" cljs-core-ns) - (fn-link "number?" cljs-core-ns) - (fn-link "object?" cljs-core-ns) - (fn-link "string?" cljs-core-ns)]] + (FnLink "array?" cljs-core-ns) + (FnLink "fn?" cljs-core-ns) + (FnLink "number?" cljs-core-ns) + (FnLink "object?" cljs-core-ns) + (FnLink "string?" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Exceptions"] [:td.body-885f4 - (fn-link "try" cljs-core-ns) - (fn-link "catch" cljs-core-ns) - (fn-link "finally" cljs-core-ns) - (fn-link "throw" cljs-core-ns)]] + (FnLink "try" cljs-core-ns) + (FnLink "catch" cljs-core-ns) + (FnLink "finally" cljs-core-ns) + (FnLink "throw" cljs-core-ns)]] [:tr [:td.label-9e0b7 "External Library"] [:td.body-885f4 @@ -396,201 +392,201 @@ [:div.row-5dec8 "(.html (js/jQuery \"#myDiv\") \"Hi!\")"]]]]]]) -(hiccups/defhtml collections-section [] +(defn CollectionsBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "Collections" (tt-icon "collections")] + [:h3.section-title-8ccf5 "Collections" (TooltipIcon "collections")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "General"] [:td.body-885f4 - (fn-link "count") - (fn-link "empty") - (fn-link "not-empty") - (fn-link "into") - (fn-link "conj")]] + (FnLink "count") + (FnLink "empty") + (FnLink "not-empty") + (FnLink "into") + (FnLink "conj")]] [:tr [:td.label-9e0b7 "Content Tests"] [:td.body-885f4 - (fn-link "distinct?") - (fn-link "empty?") - (fn-link "every?") - (fn-link "not-every?") - (fn-link "some") - (fn-link "not-any?")]] + (FnLink "distinct?") + (FnLink "empty?") + (FnLink "every?") + (FnLink "not-every?") + (FnLink "some") + (FnLink "not-any?")]] [:tr [:td.label-9e0b7 "Capabilities"] [:td.body-885f4 - (fn-link "sequential?") - (fn-link "associative?") - (fn-link "sorted?") - (fn-link "counted?") - (fn-link "reversible?")]] + (FnLink "sequential?") + (FnLink "associative?") + (FnLink "sorted?") + (FnLink "counted?") + (FnLink "reversible?")]] [:tr [:td.label-9e0b7 "Type Tests"] [:td.body-885f4 - (fn-link "coll?") - (fn-link "list?") - (fn-link "vector?") - (fn-link "set?") - (fn-link "map?") - (fn-link "seq?")]]]]]) + (FnLink "coll?") + (FnLink "list?") + (FnLink "vector?") + (FnLink "set?") + (FnLink "map?") + (FnLink "seq?")]]]]]) -(hiccups/defhtml lists-section [] +(defn ListsBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "( ) Lists" (tt-icon "lists")] + [:h3.section-title-8ccf5 "( ) Lists" (TooltipIcon "lists")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - (literal "'()") - (fn-link "list") - (fn-link "list*")]] + (CodeText "'()") + (FnLink "list") + (FnLink "list*")]] [:tr [:td.label-9e0b7 "Examine"] [:td.body-885f4 - (fn-link "first") - (fn-link "nth") - (fn-link "peek")]] + (FnLink "first") + (FnLink "nth") + (FnLink "peek")]] [:tr [:td.label-9e0b7 "'Change'"] [:td.body-885f4 - (fn-link "cons") - (fn-link "conj") - (fn-link "rest") - (fn-link "pop")]]]]]) + (FnLink "cons") + (FnLink "conj") + (FnLink "rest") + (FnLink "pop")]]]]]) -(hiccups/defhtml vectors-section [] +(defn VectorsBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "[ ] Vectors" (tt-icon "vectors")] + [:h3.section-title-8ccf5 "[ ] Vectors" (TooltipIcon "vectors")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - (literal "[]") - (fn-link "vector") - (fn-link "vec")]] + (CodeText "[]") + (FnLink "vector") + (FnLink "vec")]] [:tr [:td.label-9e0b7 "Examine"] [:td.body-885f4 [:div.row-5dec8 - "(my-vec idx) → (" (inside-fn-link "nth") " my-vec idx)" - (tt-icon "vector-as-fn")] - (fn-link "get") - (fn-link "peek")]] + "(my-vec idx) → (" (InsideFnLink "nth") " my-vec idx)" + (TooltipIcon "vector-as-fn")] + (FnLink "get") + (FnLink "peek")]] [:tr [:td.label-9e0b7 "'Change'"] [:td.body-885f4 - (fn-link "assoc") - (fn-link "pop") - (fn-link "subvec") - (fn-link "replace") - (fn-link "conj") - (fn-link "rseq")]] + (FnLink "assoc") + (FnLink "pop") + (FnLink "subvec") + (FnLink "replace") + (FnLink "conj") + (FnLink "rseq")]] [:tr [:td.label-9e0b7 "Loop"] [:td.body-885f4 - (fn-link "mapv") - (fn-link "filterv") - (fn-link "reduce-kv")]]]]]) + (FnLink "mapv") + (FnLink "filterv") + (FnLink "reduce-kv")]]]]]) -(hiccups/defhtml sets-section [] +(defn SetsBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "#{ } Sets" (tt-icon "sets")] + [:h3.section-title-8ccf5 "#{ } Sets" (TooltipIcon "sets")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 - (literal "#{}") - (fn-link "set") - (fn-link "hash-set") - (fn-link "sorted-set") - (fn-link "sorted-set-by")]] + (CodeText "#{}") + (FnLink "set") + (FnLink "hash-set") + (FnLink "sorted-set") + (FnLink "sorted-set-by")]] [:tr [:td.label-9e0b7 "Examine"] [:td.body-885f4 [:div.row-5dec8 - "(my-set itm) → (" (inside-fn-link "get") " my-set itm)" - (tt-icon "set-as-fn")] - (fn-link "contains?")]] + "(my-set itm) → (" (InsideFnLink "get") " my-set itm)" + (TooltipIcon "set-as-fn")] + (FnLink "contains?")]] [:tr [:td.label-9e0b7 "'Change'"] [:td.body-885f4 - (fn-link "conj") - (fn-link "disj")]] + (FnLink "conj") + (FnLink "disj")]] [:tr [:td.label-9e0b7 "Set Ops"] [:td.body-885f4 - (literal "(clojure.set/)") - (fn-link "union" clj-set-ns) - (fn-link "difference" clj-set-ns) - (fn-link "intersection" clj-set-ns) - (fn-link "select" clj-set-ns)]] + (CodeText "(clojure.set/)") + (FnLink "union" clj-set-ns) + (FnLink "difference" clj-set-ns) + (FnLink "intersection" clj-set-ns) + (FnLink "select" clj-set-ns)]] [:tr [:td.label-9e0b7 "Test"] [:td.body-885f4 - (literal "(clojure.set/)") - (fn-link "subset?" clj-set-ns) - (fn-link "superset?" clj-set-ns)]]]]]) + (CodeText "(clojure.set/)") + (FnLink "subset?" clj-set-ns) + (FnLink "superset?" clj-set-ns)]]]]]) -(hiccups/defhtml maps-section [] +(defn MapsBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "{ } Maps" (tt-icon "maps")] + [:h3.section-title-8ccf5 "{ } Maps" (TooltipIcon "maps")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Create"] [:td.body-885f4 [:div.row-5dec8 "{:key1 \"a\" :key2 \"b\"}"] - (fn-link "hash-map") - (fn-link "array-map") - (fn-link "zipmap") - (fn-link "sorted-map") - (fn-link "sorted-map-by") - (fn-link "frequencies") - (fn-link "group-by")]] + (FnLink "hash-map") + (FnLink "array-map") + (FnLink "zipmap") + (FnLink "sorted-map") + (FnLink "sorted-map-by") + (FnLink "frequencies") + (FnLink "group-by")]] [:tr [:td.label-9e0b7 "Examine"] [:td.body-885f4 [:div.row-5dec8 - "(:key my-map) → (" (inside-fn-link "get") " my-map :key)" - (tt-icon "keywords-as-fn")] - (fn-link "get-in") - (fn-link "contains?") - (fn-link "find") - (fn-link "keys") - (fn-link "vals")]] + "(:key my-map) → (" (InsideFnLink "get") " my-map :key)" + (TooltipIcon "keywords-as-fn")] + (FnLink "get-in") + (FnLink "contains?") + (FnLink "find") + (FnLink "keys") + (FnLink "vals")]] [:tr [:td.label-9e0b7 "'Change'"] [:td.body-885f4 - (fn-link "assoc") - (fn-link "assoc-in") - (fn-link "dissoc") - (fn-link "merge") - (fn-link "merge-with") - (fn-link "select-keys") - (fn-link "update-in")]] + (FnLink "assoc") + (FnLink "assoc-in") + (FnLink "dissoc") + (FnLink "merge") + (FnLink "merge-with") + (FnLink "select-keys") + (FnLink "update-in")]] [:tr [:td.label-9e0b7 "Entry"] [:td.body-885f4 - (fn-link "key") - (fn-link "val")]] + (FnLink "key") + (FnLink "val")]] [:tr [:td.label-9e0b7 "Sorted Maps"] [:td.body-885f4 - (fn-link "rseq") - (fn-link "subseq") - (fn-link "rsubseq")]]]]]) + (FnLink "rseq") + (FnLink "subseq") + (FnLink "rsubseq")]]]]]) -(hiccups/defhtml create-seq-section [] +(defn CreateSeqBlock [] [:div.section-31efe [:h3.section-title-8ccf5 "Create a Seq"] [:table.tbl-902f0 @@ -598,119 +594,119 @@ [:tr [:td.label-9e0b7 "From Collection"] [:td.body-885f4 - (fn-link "seq") - (fn-link "vals") - (fn-link "keys") - (fn-link "rseq") - (fn-link "subseq") - (fn-link "rsubseq")]] + (FnLink "seq") + (FnLink "vals") + (FnLink "keys") + (FnLink "rseq") + (FnLink "subseq") + (FnLink "rsubseq")]] [:tr [:td.label-9e0b7 "From JS Array"] [:td.body-885f4 - (fn-link "array-seq" cljs-core-ns) - (fn-link "prim-seq" cljs-core-ns)]] + (FnLink "array-seq" cljs-core-ns) + (FnLink "prim-seq" cljs-core-ns)]] [:tr [:td.label-9e0b7 "Producer Functions"] [:td.body-885f4 - (fn-link "lazy-seq") - (fn-link "repeatedly") - (fn-link "iterate")]] + (FnLink "lazy-seq") + (FnLink "repeatedly") + (FnLink "iterate")]] [:tr [:td.label-9e0b7 "From Constant"] [:td.body-885f4 - (fn-link "repeat") - (fn-link "range")]] + (FnLink "repeat") + (FnLink "range")]] [:tr [:td.label-9e0b7 "From Other"] [:td.body-885f4 - (fn-link "re-seq") - (fn-link "tree-seq")]] + (FnLink "re-seq") + (FnLink "tree-seq")]] [:tr [:td.label-9e0b7 "From Sequence"] [:td.body-885f4 - (fn-link "keep") - (fn-link "keep-indexed")]]]]]) + (FnLink "keep") + (FnLink "keep-indexed")]]]]]) -(hiccups/defhtml seq-in-out-section [] +(defn SeqInOutBlock [] [:div.section-31efe - [:h3.section-title-8ccf5 "Seq in, Seq out" (tt-icon "sequences")] + [:h3.section-title-8ccf5 "Seq in, Seq out" (TooltipIcon "sequences")] [:table.tbl-902f0 [:tbody [:tr [:td.label-9e0b7 "Get Shorter"] [:td.body-885f4 - (fn-link "distinct") - (fn-link "filter") - (fn-link "remove") - (fn-link "take-nth") - (fn-link "for")]] + (FnLink "distinct") + (FnLink "filter") + (FnLink "remove") + (FnLink "take-nth") + (FnLink "for")]] [:tr [:td.label-9e0b7 "Get Longer"] [:td.body-885f4 - (fn-link "cons") - (fn-link "conj") - (fn-link "concat") - (fn-link "lazy-cat") - (fn-link "mapcat") - (fn-link "cycle") - (fn-link "interleave") - (fn-link "interpose")]] + (FnLink "cons") + (FnLink "conj") + (FnLink "concat") + (FnLink "lazy-cat") + (FnLink "mapcat") + (FnLink "cycle") + (FnLink "interleave") + (FnLink "interpose")]] [:tr [:td.label-9e0b7 "Get From Tail"] [:td.body-885f4 - (fn-link "rest") - (fn-link "nthrest") - (fn-link "next") - (fn-link "fnext") - (fn-link "nnext") - (fn-link "drop") - (fn-link "drop-while") - (fn-link "take-last") - (fn-link "for")]] + (FnLink "rest") + (FnLink "nthrest") + (FnLink "next") + (FnLink "fnext") + (FnLink "nnext") + (FnLink "drop") + (FnLink "drop-while") + (FnLink "take-last") + (FnLink "for")]] [:tr [:td.label-9e0b7 "Get From Head"] [:td.body-885f4 - (fn-link "take") - (fn-link "take-while") - (fn-link "butlast") - (fn-link "drop-last") - (fn-link "for")]] + (FnLink "take") + (FnLink "take-while") + (FnLink "butlast") + (FnLink "drop-last") + (FnLink "for")]] [:tr [:td.label-9e0b7 "'Change'"] [:td.body-885f4 - (fn-link "conj") - (fn-link "concat") - (fn-link "distinct") - (fn-link "flatten") - (fn-link "group-by") - (fn-link "partition") - (fn-link "partition-all") - (fn-link "partition-by") - (fn-link "split-at") - (fn-link "split-with") - (fn-link "filter") - (fn-link "remove") - (fn-link "replace") - (fn-link "shuffle")]] + (FnLink "conj") + (FnLink "concat") + (FnLink "distinct") + (FnLink "flatten") + (FnLink "group-by") + (FnLink "partition") + (FnLink "partition-all") + (FnLink "partition-by") + (FnLink "split-at") + (FnLink "split-with") + (FnLink "filter") + (FnLink "remove") + (FnLink "replace") + (FnLink "shuffle")]] [:tr [:td.label-9e0b7 "Rearrange"] [:td.body-885f4 - (fn-link "reverse") - (fn-link "sort") - (fn-link "sort-by") - (fn-link "compare")]] + (FnLink "reverse") + (FnLink "sort") + (FnLink "sort-by") + (FnLink "compare")]] [:tr [:td.label-9e0b7 "Process Items"] [:td.body-885f4 - (fn-link "map") - (fn-link "map-indexed") - (fn-link "mapcat") - (fn-link "for") - (fn-link "replace")]]]]]) + (FnLink "map") + (FnLink "map-indexed") + (FnLink "mapcat") + (FnLink "for") + (FnLink "replace")]]]]]) -(hiccups/defhtml use-seq-section [] +(defn UsingSequenceBlock [] [:div.section-31efe [:h3.section-title-8ccf5 "Using a Seq"] [:table.tbl-902f0 @@ -718,68 +714,68 @@ [:tr [:td.label-9e0b7 "Extract Item"] [:td.body-885f4 - (fn-link "first") - (fn-link "second") - (fn-link "last") - (fn-link "rest") - (fn-link "next") - (fn-link "ffirst") - (fn-link "nfirst") - (fn-link "fnext") - (fn-link "nnext") - (fn-link "nth") - (fn-link "nthnext") - (fn-link "rand-nth") - (fn-link "when-first") - (fn-link "max-key") - (fn-link "min-key")]] + (FnLink "first") + (FnLink "second") + (FnLink "last") + (FnLink "rest") + (FnLink "next") + (FnLink "ffirst") + (FnLink "nfirst") + (FnLink "fnext") + (FnLink "nnext") + (FnLink "nth") + (FnLink "nthnext") + (FnLink "rand-nth") + (FnLink "when-first") + (FnLink "max-key") + (FnLink "min-key")]] [:tr [:td.label-9e0b7 "Construct Collection"] [:td.body-885f4 - (fn-link "zipmap") - (fn-link "into") - (fn-link "reduce") - (fn-link "reductions") - (fn-link "set") - (fn-link "vec") - (fn-link "into-array") - (fn-link "to-array-2d")]] + (FnLink "zipmap") + (FnLink "into") + (FnLink "reduce") + (FnLink "reductions") + (FnLink "set") + (FnLink "vec") + (FnLink "into-array") + (FnLink "to-array-2d")]] [:tr [:td.label-9e0b7 "Pass to Function"] [:td.body-885f4 - (fn-link "apply")]] + (FnLink "apply")]] [:tr [:td.label-9e0b7 "Search"] [:td.body-885f4 - (fn-link "some") - (fn-link "filter")]] + (FnLink "some") + (FnLink "filter")]] [:tr [:td.label-9e0b7 "Force Evaluation"] [:td.body-885f4 - (fn-link "doseq") - (fn-link "dorun") - (fn-link "doall")]] + (FnLink "doseq") + (FnLink "dorun") + (FnLink "doall")]] [:tr [:td.label-9e0b7 "Check For Forced"] [:td.body-885f4 - (fn-link "realized?")]]]]]) + (FnLink "realized?")]]]]]) -(hiccups/defhtml bitwise-section [] +(defn BitwiseBlock [] [:div.section-31efe [:h3.section-title-8ccf5 "Bitwise"] [:div.solo-section-d5309 - (fn-link "bit-and") - (fn-link "bit-or") - (fn-link "bit-xor") - (fn-link "bit-not") - (fn-link "bit-flip") - (fn-link "bit-set") - (fn-link "bit-shift-right") - (fn-link "bit-shift-left") - (fn-link "bit-and-not") - (fn-link "bit-clear") - (fn-link "bit-test") - (fn-link "unsigned-bit-shift-right")]]) + (FnLink "bit-and") + (FnLink "bit-or") + (FnLink "bit-xor") + (FnLink "bit-not") + (FnLink "bit-flip") + (FnLink "bit-set") + (FnLink "bit-shift-right") + (FnLink "bit-shift-left") + (FnLink "bit-and-not") + (FnLink "bit-clear") + (FnLink "bit-test") + (FnLink "unsigned-bit-shift-right")]]) ;; TODO: create "Export to JavaScript" section ;; include ^:export and goog.exportSymbol functions @@ -789,9 +785,7 @@ ;; Info Tooltips ;;------------------------------------------------------------------------------ -;; TODO: break these up into functions - -(hiccups/defhtml truthy-table [] +(defn TruthyTable [] [:table.tbl-3160a [:thead [:tr @@ -829,7 +823,7 @@ [:td.cell-e6fd2 [:code "false"]]]]]) -(hiccups/defhtml function-shorthand-table [] +(defn FunctionShorthandTable [] [:table.exmpl-tbl-42d9f [:thead [:tr @@ -845,152 +839,153 @@ [:tr [:td.code-72fa0.right-border-c1b54 {:style "font-size: 10px"} - "#(* % (apply + %&))"] + "#(* % (apply + %&))"] [:td.code-72fa0 [:pre {:style "font-size: 10px"} - "(fn [x & the-rest]\n" + "(fn [x & the-rest]\n" " (* x (apply + the-rest)))"]]]]]) -(hiccups/defhtml basics-tooltips [] - - [:div#tooltip-define.tooltip-53dde {:style "display:none"} - [:p "Everything in ClojureScript is immutable by default, meaning that the " - "value of a symbol cannot be changed after it is defined."]] - - [:div#tooltip-branch.tooltip-53dde {:style "display:none"} - [:p "In conditional statements, everything evaluates to " [:code "true"] - " except for " [:code "false"] " and " [:code "nil"] "."] - [:p "This is much simpler than JavaScript, which has complex rules for " - "truthiness."] - (truthy-table)] - - [:div#tooltip-numbers.tooltip-53dde {:style "display:none"} - [:p "All ClojureScript Numbers are IEEE 754 Double Precision floating point. " - "The same as JavaScript."]] - - [:div#tooltip-atoms.tooltip-53dde {:style "display:none"} - [:p - "Atoms provide a way to manage state in a ClojureScript program."] - [:p - "Unlike JavaScript, everything in ClojureScript is immutable by default. " - "This means that you cannot change the value of something after it has " - "been defined."] - [:p - "Atoms allow for mutability and distinguish between setting and reading " - "a value, which makes state easier to reason about."] - [:p - "Watcher functions execute when a value changes, providing a powerful UI " - "pattern when your value maps to interface state."]] - - [:div#tooltip-functions.tooltip-53dde {:style "display:none"} - [:p - "ClojureScript Functions are JavaScript Functions and can be called and " - "used in all the ways that JavaScript Functions can."] - [:p - "The core library provides many useful higher-order functions and there " - "is a convenient shorthand for creating anonymous functions."]] - - [:div#tooltip-function-shorthand.tooltip-53dde {:style "display:none"} - [:p - "The " [:code "#()"] " function shorthand is a convenient way to write a " - "small function definition and is often used to pass closures from one " - "scope to another."] - [:p - [:code "#()"] " forms cannot be nested and it is idiomatic to keep them " - "short."] - (function-shorthand-table)] - - [:div#tooltip-strings.tooltip-53dde {:style "display:none"} - [:p "ClojureScript Strings are JavaScript Strings and have all of the native " - "methods and properties that a JavaScript String has."] - [:p "ClojureScript Strings must be defined using double quotes."] - [: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 - "ClojureScript provides four collection types: lists, vectors, sets, and " - "maps. " - "Each of these data types has unique strengths and are used heavily in " - "most programs."] - [:p - "All collections are immutable and persistent, which means they preserve " - "the previous version(s) of themselves when they are modified. " - "Creating a \"changed\" version of any collection is an efficient " - "operation."] - [:p - "Collections can be represented literally:"] - [:table.tbl-3160a - [:thead - [:tr - [:th.tbl-hdr-e0564 "Collection"] - [:th.tbl-hdr-e0564 "Literal Form"]]] - [:tbody - [:tr - [:td.cell-e6fd2.right-border-c1b54 "List"] - [:td.cell-e6fd2 [:code "()"]]] - [:tr - [:td.cell-e6fd2.right-border-c1b54 "Vector"] - [:td.cell-e6fd2 [:code "[]"]]] - [:tr - [:td.cell-e6fd2.right-border-c1b54 "Set"] - [:td.cell-e6fd2 [:code "#{}"]]] - [:tr - [:td.cell-e6fd2.right-border-c1b54 "Map"] - [:td.cell-e6fd2 [:code "{}"]]]]]] - - [:div#tooltip-lists.tooltip-53dde {:style "display:none"} - [:p - "Lists are a sequence of values, similar to a vector."] - [:p - "Most literal lists represent a function call."] - [:p - [:code "(a b c)"] " is a list of three things, and it also means " - "\"call the function " [:code "a"] " with two arguments: " [:code "b"] - " and " [:code "c"] "\""]] - - [:div#tooltip-vectors.tooltip-53dde {:style "display:none"} - [:p - "Vectors are collections of values that are indexed by sequential " - "integers."] - [:p - "Though similar, a JavaScript Array is not the same thing as a " - "ClojureScript vector. " - "ie: " [:code "(.indexOf my-vec)"] " will not work on a vector."]] - - [:div#tooltip-vector-as-fn.tooltip-53dde {:style "display:none"} - [:p - "A vector can be used as a function to access its elements."]] - - [:div#tooltip-sets.tooltip-53dde {:style "display:none"} - [:p "Sets are collections of unique values, just like in " - "mathematics."]] - - [:div#tooltip-set-as-fn.tooltip-53dde {:style "display:none"} - [:p - "A set can be used as a function to access its elements."]] - - [:div#tooltip-maps.tooltip-53dde {:style "display:none"} - [:p - "A map is a collection that maps keys to values. " - "Accessing a value in a map using a key is very fast."] - [:p - "In JavaScript, Objects are commonly used as a de facto map using " - "strings as keys. " - "A key in a ClojureScript map can be any value, although keywords are " - "commonly used."]] - - [:div#tooltip-keywords-as-fn.tooltip-53dde {:style "display:none"} - [:p - "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 [] +(defn BasicsTooltips [] + (list + [:div#tooltip-define.tooltip-53dde {:style "display:none"} + [:p "Everything in ClojureScript is immutable by default, meaning that the " + "value of a symbol cannot be changed after it is defined."]] + + [:div#tooltip-branch.tooltip-53dde {:style "display:none"} + [:p "In conditional statements, everything evaluates to " [:code "true"] + " except for " [:code "false"] " and " [:code "nil"] "."] + [:p "This is much simpler than JavaScript, which has complex rules for " + "truthiness."] + (TruthyTable)] + + [:div#tooltip-numbers.tooltip-53dde {:style "display:none"} + [:p "All ClojureScript Numbers are IEEE 754 Double Precision floating point. " + "The same as JavaScript."]] + + [:div#tooltip-atoms.tooltip-53dde {:style "display:none"} + [:p + "Atoms provide a way to manage state in a ClojureScript program."] + [:p + "Unlike JavaScript, everything in ClojureScript is immutable by default. " + "This means that you cannot change the value of something after it has " + "been defined."] + [:p + "Atoms allow for mutability and distinguish between setting and reading " + "a value, which makes state easier to reason about."] + [:p + "Watcher functions execute when a value changes, providing a powerful UI " + "pattern when your value maps to interface state."]] + + [:div#tooltip-functions.tooltip-53dde {:style "display:none"} + [:p + "ClojureScript Functions are JavaScript Functions and can be called and " + "used in all the ways that JavaScript Functions can."] + [:p + "The core library provides many useful higher-order functions and there " + "is a convenient shorthand for creating anonymous functions."]] + + [:div#tooltip-function-shorthand.tooltip-53dde {:style "display:none"} + [:p + "The " [:code "#()"] " function shorthand is a convenient way to write a " + "small function definition and is often used to pass closures from one " + "scope to another."] + [:p + [:code "#()"] " forms cannot be nested and it is idiomatic to keep them " + "short."] + (FunctionShorthandTable)] + + [:div#tooltip-strings.tooltip-53dde {:style "display:none"} + [:p "ClojureScript Strings are JavaScript Strings and have all of the native " + "methods and properties that a JavaScript String has."] + [:p "ClojureScript Strings must be defined using double quotes."] + [:p "The " [:code "clojure.string"] " namespace provides many useful " + "functions for dealing with strings."]])) + + +(defn CollectionsTooltips [] + (list + [:div#tooltip-collections.tooltip-53dde {:style "display:none"} + [:p + "ClojureScript provides four collection types: lists, vectors, sets, and " + "maps. " + "Each of these data types has unique strengths and are used heavily in " + "most programs."] + [:p + "All collections are immutable and persistent, which means they preserve " + "the previous version(s) of themselves when they are modified. " + "Creating a \"changed\" version of any collection is an efficient " + "operation."] + [:p + "Collections can be represented literally:"] + [:table.tbl-3160a + [:thead + [:tr + [:th.tbl-hdr-e0564 "Collection"] + [:th.tbl-hdr-e0564 "Literal Form"]]] + [:tbody + [:tr + [:td.cell-e6fd2.right-border-c1b54 "List"] + [:td.cell-e6fd2 [:code "()"]]] + [:tr + [:td.cell-e6fd2.right-border-c1b54 "Vector"] + [:td.cell-e6fd2 [:code "[]"]]] + [:tr + [:td.cell-e6fd2.right-border-c1b54 "Set"] + [:td.cell-e6fd2 [:code "#{}"]]] + [:tr + [:td.cell-e6fd2.right-border-c1b54 "Map"] + [:td.cell-e6fd2 [:code "{}"]]]]]] + + [:div#tooltip-lists.tooltip-53dde {:style "display:none"} + [:p + "Lists are a sequence of values, similar to a vector."] + [:p + "Most literal lists represent a function call."] + [:p + [:code "(a b c)"] " is a list of three things, and it also means " + "\"call the function " [:code "a"] " with two arguments: " [:code "b"] + " and " [:code "c"] "\""]] + + [:div#tooltip-vectors.tooltip-53dde {:style "display:none"} + [:p + "Vectors are collections of values that are indexed by sequential " + "integers."] + [:p + "Though similar, a JavaScript Array is not the same thing as a " + "ClojureScript vector. " + "ie: " [:code "(.indexOf my-vec)"] " will not work on a vector."]] + + [:div#tooltip-vector-as-fn.tooltip-53dde {:style "display:none"} + [:p + "A vector can be used as a function to access its elements."]] + + [:div#tooltip-sets.tooltip-53dde {:style "display:none"} + [:p "Sets are collections of unique values, just like in " + "mathematics."]] + + [:div#tooltip-set-as-fn.tooltip-53dde {:style "display:none"} + [:p + "A set can be used as a function to access its elements."]] + + [:div#tooltip-maps.tooltip-53dde {:style "display:none"} + [:p + "A map is a collection that maps keys to values. " + "Accessing a value in a map using a key is very fast."] + [:p + "In JavaScript, Objects are commonly used as a de facto map using " + "strings as keys. " + "A key in a ClojureScript map can be any value, although keywords are " + "commonly used."]] + + [:div#tooltip-keywords-as-fn.tooltip-53dde {:style "display:none"} + [:p + "Keywords can be used as a function to get a value from a map. " + "They are commonly used as map keys for this reason."]])) + + +(defn SequencesTooltips [] [:div#tooltip-sequences.tooltip-53dde {:style "display:none"} [:p "Many core algorithms are defined in terms of sequences. A sequence is " @@ -1011,18 +1006,18 @@ "results of a side-effecting function over an entire sequence."]]) -(hiccups/defhtml info-tooltips [] +(defn InfoTooltips [] [:section - (basics-tooltips) - (collections-tooltips) - (sequences-tooltips)]) + (BasicsTooltips) + (CollectionsTooltips) + (SequencesTooltips)]) ;;------------------------------------------------------------------------------ ;; Header and Footer ;;------------------------------------------------------------------------------ -(hiccups/defhtml header [] +(defn Header [] [:header [:h1 [:img {:src "img/cljs-ring.svg" :alt "ClojureScript Logo"}] @@ -1039,7 +1034,7 @@ ;; include this? "Please copy, improve, and share this work." ;; TODO: improve the markup here -(hiccups/defhtml footer [] +(defn Footer [] [:footer [:div.links-446e0 [:label.quiet-5d4e8 "reference: "] @@ -1062,7 +1057,7 @@ (def page-title "ClojureScript Cheatsheet") -(hiccups/defhtml head [] +(defn Head [] [:head [:meta {:charset "utf-8"}] [:meta {:http-equiv "x-ua-compatible" :content "ie=edge"}] @@ -1070,13 +1065,17 @@ [:meta {:name "description" :content "ClojureScript cheatsheet"}] [:meta {:name "viewport" :content "width=device-width, initial-scale=1"}] [:link {:rel "apple-touch-icon" :href "apple-touch-icon.png"}] - [:script - (str "if (window.location.hostname !== 'localhost' && window.location.protocol !== 'https:') {" - "window.location.href = window.location.href.replace('http://', 'https://');}")] + [:div + {:dangerously-set-inner-HTML + {:__html + (str "")}}] [:link {:rel "stylesheet" :href "css/main.min.css"}]]) -(hiccups/defhtml script-tags [] +(defn Scripts [] [:script {:src "js/cheatsheet.min.js"}]) @@ -1084,80 +1083,88 @@ ;; Body ;;------------------------------------------------------------------------------ -(hiccups/defhtml body [] +(defn BasicsMajorSection [] [:section.major-category [:h2 "Basics"] [:div.three-col-container [:div.column - (basics-section) - (functions-section)] + (BasicsSection) + (FunctionSection)] [:div.column - (numbers-section) - (strings-section)] + (NumbersSection) + (StringsSection)] [:div.column - (atoms-section) - (js-interop-section)]] + (AtomsSection) + (JsInteropSection)]] [:div.two-col-container [:div.column - (basics-section) - (numbers-section) - (js-interop-section)] + (BasicsSection) + (NumbersSection) + (JsInteropSection)] [:div.column - (functions-section) - (strings-section) - (atoms-section)]]] + (FunctionSection) + (StringsSection) + (AtomsSection)]]]) +(defn CollectionsMajorSection [] [:section.major-category [:h2 "Collections"] [:div.three-col-container [:div.column - (collections-section) - (lists-section)] + (CollectionsBlock) + (ListsBlock)] [:div.column - (vectors-section) - (sets-section)] + (VectorsBlock) + (SetsBlock)] [:div.column - (maps-section)]] + (MapsBlock)]] [:div.two-col-container [:div.column - (collections-section) - (lists-section) - (maps-section)] + (CollectionsBlock) + (ListsBlock) + (MapsBlock)] [:div.column - (vectors-section) - (sets-section)]]] + (VectorsBlock) + (SetsBlock)]]]) +(defn SequencesMajorSection [] [:section.major-category [:h2 "Sequences"] [:div.three-col-container - [:div.column (seq-in-out-section)] - [:div.column (use-seq-section)] - [:div.column (create-seq-section)]] + [:div.column (SeqInOutBlock)] + [:div.column (UsingSequenceBlock)] + [:div.column (CreateSeqBlock)]] [:div.two-col-container - [:div.column (seq-in-out-section)] + [:div.column (SeqInOutBlock)] [:div.column - (use-seq-section) - (create-seq-section)]]] + (UsingSequenceBlock) + (CreateSeqBlock)]]]) +(defn MiscMajorSection [] [:section.major-category [:h2 "Misc"] [:div.three-col-container - [:div.column (bitwise-section)]] + [:div.column (BitwiseBlock)]] [:div.two-col-container - [:div.column (bitwise-section)]]]) + [:div.column (BitwiseBlock)]]]) +(defn Body [] + (list (BasicsMajorSection) + (CollectionsMajorSection) + (SequencesMajorSection) + (MiscMajorSection))) -(defn cheatsheet-page [] +(defn CheatsheetPage [] (str "" "" - (head) + (hiccups/html (Head)) "" - (header) - (body) - (footer) - (info-tooltips) - (script-tags) + (hiccups/html (Header)) + (hiccups/html (Body)) + (hiccups/html (Footer)) + (hiccups/html (InfoTooltips)) + (hiccups/html (Scripts)) "" "")) @@ -1165,11 +1172,11 @@ ;; Init (defn- write-cheatsheet-html! [] - (js-log "[cljs-cheatsheet] Writing public/index.html ...") - (.writeFileSync fs "public/index.html" (cheatsheet-page))) + (js-log "[cljs-cheatsheet] Writing public/index.html …") + (.writeFileSync fs "public/index.html" (CheatsheetPage))) (defn- write-symbols-json! [] - (js-log "[cljs-cheatsheet] Writing symbols.json ...") + (js-log "[cljs-cheatsheet] Writing symbols.json …") (.writeFileSync fs "symbols.json" (-> @symbols sort clj->js json-stringify))) (defn -main [] diff --git a/docfiles/cljs.core_keep-indexed.cljsdoc b/docfiles/cljs.core_keep-indexed.cljsdoc index d6e71b1..5b8b218 100644 --- a/docfiles/cljs.core_keep-indexed.cljsdoc +++ b/docfiles/cljs.core_keep-indexed.cljsdoc @@ -10,7 +10,7 @@ cljs.core/keep-indexed Returns a lazy sequence of the non-nil results of `(f index item)`. Note, this means false return values will be included. -`f must be free of side-effects. +`f` must be free of side-effects. Returns a stateful transducer when no collection is provided. diff --git a/project.clj b/project.clj index 66b4ec5..1cabac4 100644 --- a/project.clj +++ b/project.clj @@ -8,14 +8,14 @@ :distribution :repo} :dependencies - [[org.clojure/clojure "1.9.0"] - [org.clojure/clojurescript "1.10.439"] - [binaryage/oops "0.6.3"] + [[org.clojure/clojure "1.11.1"] + [org.clojure/clojurescript "1.11.60"] + [binaryage/oops "0.7.2"] [cljsjs/jquery "2.1.4-0"] - [com.cognitect/transit-cljs "0.8.256"] - [hiccups "0.3.0"]] + [com.cognitect/transit-cljs "0.8.280"] + [macchiato/hiccups "0.4.1"]] - :plugins [[lein-cljsbuild "1.1.7"]] + :plugins [[lein-cljsbuild "1.1.8"]] :source-paths ["src"] @@ -42,8 +42,6 @@ {:id "server" :source-paths ["cljs-server" "cljs-shared"] - :compiler {:language-in :ecmascript5 - :language-out :ecmascript5 - :output-to "app.js" + :compiler {:output-to "app.js" :optimizations :simple :target :nodejs}}]})