Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec klipsify #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defproject klipse "2.3.0"
:description "Cljs compiler in cljs"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.198"]
:dependencies [[org.clojure/clojure "1.9.0-alpha10"]
[org.clojure/clojurescript "1.9.211"]
[org.clojure/core.async "0.2.385"]
[im.chit/purnam "0.5.2"]
[cljsjs/markdown "0.6.0-beta1-0"]
Expand Down
32 changes: 1 addition & 31 deletions resources/public/playground-dbg.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,7 @@
<br/>


<div class="lambda">
{div {@ style="text-align:center;font:bold 2em georgia;color:red;"} √(3{sup 2}+4{sup 2}) = {sqrt {+ {* 3 3} {* 4 4}}}}
</div>
<br/>
<div class="lambda">
{def amélie {img
{@ id="amelie"
src="http://epsilonwiki.free.fr/lambdaway/data/amelie_poulain.jpg"
height="150"
title="Amélie Poulain"
style="box-shadow:0 0 8px black;
border:1px solid white;
-webkit-transform:rotate(-5deg);
-moz-transform:rotate(-5deg);
transform:rotate(-5deg);"}}}
{amélie}
</div>
<br/>
<pre>
<code class="eval-html" data-editor-type="html">
&lt;h1&gt; Title &lt;/h1&gt;
&lt;b&gt; bold &lt;/b&gt;
</code>
</pre>


<div class="eval-html" data-editor-type="html">
&lt;img id="amelie" src="http://epsilonwiki.free.fr/lambdaway/data/amelie_poulain.jpg" height="150" title="Amélie Poulain" style="box-shadow:0 0 8px black; border:1px solid white; -webkit-transform:rotate(-5deg); -moz-transform:rotate(-5deg); transform:rotate(-5deg);"&gt;&lt;/img&gt;
</div>



<script src="https://viebel.github.io/klipse/examples/lambdaway_eval.js"></script>
<script>
window.klipse_settings = {
Expand Down
25 changes: 20 additions & 5 deletions src/klipse/plugin.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(:require
[klipse.args-from-element :refer [editor-args-from-element eval-args-from-element content]]
[klipse.klipse-editors :refer [create-editor]]
[cljs.spec :as s]
[clojure.spec :as s]
[clojure.spec.test :as stest]
[clojure.walk :refer [keywordize-keys]]
[goog.dom :refer [isElement]]
[cljs.core.async :refer [<!]]
Expand Down Expand Up @@ -70,10 +71,24 @@
:settings ::klipse-settings
:opts ::options))

(s/def ::mode string?)

(s/fdef klipsify
:args (s/cat :element ::dom-element
:settings ::klipse-settings
:mode ::mode))

(defn ->clj [settings]
; we cannot keywordize the keys as the modules might be written in javascript
(js->clj settings :keywordize-keys false))

(defn ^:export klipsify [element general-settings mode]
(if-let [opts (@mode-options mode)]
(klipsify-with-opts element general-settings opts)
(go (js/console.error "cannot find options for mode: " mode ". Supported modes: " (keys @mode-options)))))
(go (js/console.error "cannot find options for mode: " mode ". Supported modes are: " (clj->js (keys @mode-options))))))

(defn klipsify-js [element js-general-settings mode]
(klipsify element (->clj js-general-settings) mode))

(defn ^:export klipsify-elements [elements general-settings mode]
(go
Expand All @@ -87,7 +102,7 @@
(klipsify-elements (array-seq (js/document.querySelectorAll selector)) keywordized-settings (@selector->mode selector-name))))))

(defn ^:export init [js-settings]
(init-clj (js->clj js-settings :keywordize-keys false))); we cannot keywordize the keys as the modules might be written in javascript
(init-clj (->clj js-settings)))

(comment
(s/instrument #'klipsify-with-opts))
(stest/instrument `klipsify)
(stest/instrument `klipsify-with-opts)
3 changes: 3 additions & 0 deletions src/klipse/run/plugin/plugin.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
(defn ^:export settings []
(aget js/window "klipse_settings"))

(defn ^:export klipsify [element mode]
(plugin/klipsify-js element (settings) mode))

(plugin/init (settings))