-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* eval jsx * transpile jsx * load codemirror mode scripts dynamically
- Loading branch information
Showing
24 changed files
with
9,047 additions
and
16,460 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>KLIPSE: a simple and elegant online cljs compiler and evaluator</title> | ||
<link rel='shortcut icon' type='image/x-icon' href='img/klipse.png' /> | ||
<link rel="stylesheet" type="text/css" href="css/codemirror.css"> | ||
</head> | ||
<body> | ||
|
||
<pre><code class="js" data-external-libs="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react-with-addons.js, https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react-dom.js"> | ||
Object.keys(React) | ||
</code></pre> | ||
<pre><code class="transpile-jsx"> | ||
<div className="shopping-list"> | ||
<h1>Shopping List for {this.props.name}</h1> | ||
</div> | ||
</code></pre> | ||
|
||
<pre><code class="jsx"> | ||
class ShoppingList extends React.Component { | ||
render() { | ||
return ( | ||
<div className="shopping-list"> | ||
<h1>Shopping List for {this.props.name}</h1> | ||
<ul> | ||
<li>Instagram</li> | ||
<li>WhatsApp</li> | ||
<li>Oculus</li> | ||
</ul> | ||
</div> | ||
); | ||
} | ||
} | ||
window.ShoppingList = ShoppingList | ||
</code></pre> | ||
<code><pre class="js"> | ||
ShoppingList | ||
</code></pre> | ||
<br/> | ||
<script> | ||
window.klipse_settings = { | ||
selector_eval_js: '.js', | ||
selector_jsx: '.jsx', | ||
selector_transpile_jsx: '.transpile-jsx', | ||
}; | ||
</script> | ||
<script src="/lib/mirror_extensions.js"></script> | ||
<script src="/fig/js/klipse.fig.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>KLIPSE: a simple and elegant online cljs compiler and evaluator</title> | ||
<link rel='shortcut icon' type='image/x-icon' href='img/klipse.png' /> | ||
<link rel="stylesheet" type="text/css" href="css/codemirror.css"> | ||
</head> | ||
<body> | ||
<h1> Markdown </h1> | ||
<h2> HTML transpilation</h2> | ||
<code class="eval-markdown"> | ||
# This is a title | ||
`clojure` rocks! | ||
</code> | ||
<br/> | ||
|
||
<h2> HTML rendering</h2> | ||
<code class="eval-markdown" data-editor-type="html"> | ||
# This is a title | ||
`clojure` rocks! | ||
</code> | ||
<br/> | ||
|
||
|
||
<script> | ||
window.klipse_settings = { | ||
selector_eval_markdown: '.eval-markdown', | ||
}; | ||
</script> | ||
<script src="/lib/mirror_extensions.js"></script> | ||
<script src="/fig/js/klipse.fig.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
(ns klipse.lang.jsx | ||
(:require-macros | ||
[gadjett.core :refer [dbg]] | ||
[purnam.core :refer [!>]] | ||
[cljs.core.async.macros :refer [go]]) | ||
(:require | ||
[klipse.common.registry :refer [codemirror-mode-src register-mode]])) | ||
|
||
(def eval-in-global-scope js/eval); this is the trick to make `eval` work in the global scope: http://perfectionkills.com/global-eval-what-are-the-options/ | ||
|
||
|
||
(defn babel [src] | ||
(-> (!> js/Babel.transform src #js {:presets #js ["react"]}) | ||
(aget "code"))) | ||
|
||
(defn eval-jsx [exp _] | ||
(go | ||
(try | ||
(-> exp | ||
babel | ||
eval-in-global-scope) | ||
"//Evaluation done" | ||
(catch :default o | ||
(str o))))) | ||
|
||
(defn transpile-jsx [exp _] | ||
(go | ||
(try | ||
(babel exp) | ||
(catch :default o | ||
(str o))))) | ||
|
||
(def eval-opts {:editor-in-mode "text/jsx" | ||
:editor-out-mode "javascript" | ||
:eval-fn eval-jsx | ||
:external-scripts [(codemirror-mode-src "xml") (codemirror-mode-src "javascript") (codemirror-mode-src "jsx") "https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.1/babel.min.js"] | ||
:comment-str "//"}) | ||
|
||
(def transpile-opts {:editor-in-mode "text/jsx" | ||
:editor-out-mode "javascript" | ||
:eval-fn transpile-jsx | ||
:external-scripts [(codemirror-mode-src "xml") (codemirror-mode-src "javascript") (codemirror-mode-src "jsx")] | ||
:comment-str "//"}) | ||
|
||
(register-mode "eval-jsx" "selector_jsx" eval-opts) | ||
(register-mode "transpile-jsx" "selector_transpile_jsx" transpile-opts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.