Provides access to third party Javascript libraries in clojupyter.
Replaces clojupyter.misc.helpter/add-javascript which is
deprecated because Jupyter no longer allows arbitrary script tags
to be sent by kernels but instead supports libraries loaded using
RequireJS (cf. https://requirejs.org) an implementation of
Javascript Asynchronuous Module Definitions (AMDs).
Alpha version - breakage may happen. Please report issues or missing features.
Provides access to third party Javascript libraries in clojupyter. Replaces `clojupyter.misc.helpter/add-javascript` which is deprecated because Jupyter no longer allows arbitrary `script` tags to be sent by kernels but instead supports libraries loaded using RequireJS (cf. https://requirejs.org) an implementation of Javascript Asynchronuous Module Definitions (AMDs). Alpha version - breakage may happen. Please report issues or missing features.
(amd-add-javascript jsdefs)Returns a string representing a Javascript config() statement for
RequireJS (cf. https://requirejs.org) providing access to Javascript
libraries using Asynchronuous Module Definitions (AMDs).
jsdefs must be a vector of jsdef (cf. clojure.spec definition
::jsdef in namespace clojupyter.javascript-amd).
Example:
c.j.alpha> (println (amd-add-javascript [{:ident :hicharts :exports "Highcharts" :url "https://code.highcharts.com/highcharts"}])) requirejs.config({"paths":{"hicharts":"https:\/\/code.highcharts.com\/highcharts"}, "shim":{"hicharts":{"exports":"Highcharts"}}}) nil c.j.alpha>
(Printed line above broken for readability.)
The above expression yields a RequireJS configuration providing
access to the Highcharts Javascript library available at
code.highcharts.com and referenced using :hicharts using
wrap-require. The library exports the symbol Highcharts.
Given the above RequireJS configuration, the Highcharts library can
be accessed using wrap-require.
Example:
c.j.alpha> (let [nodeid (gensym), data {:a 1}] (println (amd-wrap-require [:hicharts] (format "function(hc){hc.chart('%s',%s)}" nodeid (json/write-str data))))) require(["hicharts"],function(hc){hc.chart('G__34952',{"a":1})}); nil c.j.alpha>
where the function's formal parameter hc is bound to the exported
symbol Highcharts from the Highchart library which is referenced
by :hicharts. The number of ident-bindings in wrap-require and
the number of arguments in the Javascript function must be the same,
and referenced symbols are bound in order.
NOTE: The result of calling amd-add-javascript must be the last
form of the cell for the Javascript to be evaluated. Consider using
amd-add-javascript-html which creates a HTML div element which
both add the Javascript library and provides a textual
confirmation.
Returns a string representing a Javascript `config()` statement for
RequireJS (cf. https://requirejs.org) providing access to Javascript
libraries using Asynchronuous Module Definitions (AMDs).
`jsdefs` must be a vector of `jsdef` (cf. `clojure.spec` definition
`::jsdef` in namespace `clojupyter.javascript-amd`).
Example:
c.j.alpha> (println
(amd-add-javascript
[{:ident :hicharts
:exports "Highcharts"
:url "https://code.highcharts.com/highcharts"}]))
requirejs.config({"paths":{"hicharts":"https:\/\/code.highcharts.com\/highcharts"},
"shim":{"hicharts":{"exports":"Highcharts"}}})
nil
c.j.alpha>
(Printed line above broken for readability.)
The above expression yields a RequireJS configuration providing
access to the Highcharts Javascript library available at
`code.highcharts.com` and referenced using `:hicharts` using
`wrap-require`. The library exports the symbol `Highcharts`.
Given the above RequireJS configuration, the Highcharts library can
be accessed using `wrap-require`.
Example:
c.j.alpha> (let [nodeid (gensym), data {:a 1}]
(println
(amd-wrap-require [:hicharts]
(format "function(hc){hc.chart('%s',%s)}" nodeid (json/write-str data)))))
require(["hicharts"],function(hc){hc.chart('G__34952',{"a":1})});
nil
c.j.alpha>
where the function's formal parameter `hc` is bound to the exported
symbol `Highcharts` from the Highchart library which is referenced
by `:hicharts`. The number of ident-bindings in `wrap-require` and
the number of arguments in the Javascript function must be the same,
and referenced symbols are bound in order.
NOTE: The result of calling `amd-add-javascript` must be the last
form of the cell for the Javascript to be evaluated. Consider using
`amd-add-javascript-html` which creates a HTML `div` element which
both add the Javascript library and provides a textual
confirmation.(amd-add-javascript-html jsdefs)(amd-add-javascript-html {:keys [brief?] :or {brief? false}} jsdefs)Same as amd-add-javascript except the returned string is embedded in a
script element wrapped in a hiccup-html form.
Cf. amd-add-javascript for details.
NOTE: Evaluation of amd-add-javascript-html must be the last form
of the cell. The message 'Javascript library loaded...' indicates
that the library was loaded.
Same as `amd-add-javascript` except the returned string is embedded in a `script` element wrapped in a `hiccup-html` form. Cf. `amd-add-javascript` for details. NOTE: Evaluation of `amd-add-javascript-html` must be the last form of the cell. The message 'Javascript library loaded...' indicates that the library was loaded.
(amd-wrap-config s)Returns a string represeting the call if requirejs.config() with
arguments resulting from converting s to a string.
Returns a string represeting the call if `requirejs.config()` with arguments resulting from converting `s` to a string.
(amd-wrap-require ident-vec javascript-function)Returns a string representing a Javascript RequireJS require() statement.
Cf. amd-add-javascript for usage information.
Returns a string representing a Javascript RequireJS `require()` statement. Cf. `amd-add-javascript` for usage information.
(amd-wrap-semicolons & ss)Returns a string by concatenating the members of ss after having
appended ; to each value.
Returns a string by concatenating the members of `ss` after having appended \; to each value.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |