From 3b5eb3e57b28fb97edc5cbc5fbfc6314b238f88e Mon Sep 17 00:00:00 2001 From: Yehonathan Sharvit Date: Sun, 15 Oct 2017 21:27:55 +0300 Subject: [PATCH] first draft of Klipse integration jsx-in-depth: one klipse snippet --- content/docs/introducing-jsx.md | 35 +++++++++++++++++++++++++++++++++ content/docs/jsx-in-depth.md | 17 ++++++++++++++++ gatsby-config.js | 6 ++++++ package.json | 1 + yarn.lock | 10 +++++----- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/content/docs/introducing-jsx.md b/content/docs/introducing-jsx.md index 9830ddc93d7..9edd03eb522 100644 --- a/content/docs/introducing-jsx.md +++ b/content/docs/introducing-jsx.md @@ -18,6 +18,15 @@ It is called JSX, and it is a syntax extension to JavaScript. We recommend using JSX produces React "elements". We will explore rendering them to the DOM in the [next section](/docs/rendering-elements.html). Below, you can find the basics of JSX necessary to get you started. + + + +
+Hello World +
+ ### Embedding Expressions in JSX You can embed any [JavaScript expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) in JSX by wrapping it in curly braces. @@ -65,6 +74,29 @@ function getGreeting(user) { } ``` +Hello +~~~klipse-eval-js +2+3 +~~~ + + +Simple + +~~~klipse-render-jsx +<p>Hello World </p> +~~~ + +Again: + +~~~klipse-jsx +function getGreeting(user) { + if (user) { + return <h1>Hello, {formatName(user)}!</h1>; + } + return <h1>Hello, Stranger.</h1>; +} +~~~ + ### Specifying Attributes with JSX You may use quotes to specify string literals as attributes: @@ -160,3 +192,6 @@ We will explore rendering React elements to the DOM in the next section. >**Tip:** > >We recommend using the ["Babel" language definition](http://babeljs.io/docs/editors) for your editor of choice so that both ES6 and JSX code is properly highlighted. This website uses the [Oceanic Next](https://labs.voronianski.com/oceanic-next-color-scheme/) color scheme which is compatible with it. + + + diff --git a/content/docs/jsx-in-depth.md b/content/docs/jsx-in-depth.md index fafbe64d3f8..1e9aa28a93b 100644 --- a/content/docs/jsx-in-depth.md +++ b/content/docs/jsx-in-depth.md @@ -31,6 +31,23 @@ React.createElement( ) ``` +Here is an interactive version of the jsx snippet: +~~~klipse-transpile-jsx +<MyButton color="blue" shadowSize={2}> + Click Me +</MyButton> +~~~ + +Here is an interactive version of the jsx snippet: +
+
+<MyButton color="blue" shadowSize={2}>
+  Click Me
+</MyButton>
+
+
+ + You can also use the self-closing form of the tag if there are no children. So: ```js diff --git a/gatsby-config.js b/gatsby-config.js index 029197a38a3..6ef1690b5b2 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -75,6 +75,12 @@ module.exports = { trackingId: 'UA-41298772-1', }, }, + { + resolve: 'gatsby-plugin-klipse', + options: { + classPrefix: 'gatsby-code-', + } + }, { resolve: 'gatsby-plugin-feed', options: { diff --git a/package.json b/package.json index 1d214c9f022..74fb6a019f6 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "gatsby-plugin-feed": "^1.3.9", "gatsby-plugin-glamor": "^1.6.4", "gatsby-plugin-google-analytics": "^1.0.4", + "gatsby-plugin-klipse": "^2.0.0", "gatsby-plugin-manifest": "^1.0.4", "gatsby-plugin-netlify": "^1.0.4", "gatsby-plugin-nprogress": "^1.0.7", diff --git a/yarn.lock b/yarn.lock index a86fa6c6bd7..7dd4cfd89a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3866,6 +3866,10 @@ gatsby-plugin-google-analytics@^1.0.4: dependencies: babel-runtime "^6.26.0" +gatsby-plugin-klipse@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/gatsby-plugin-klipse/-/gatsby-plugin-klipse-2.0.0.tgz#422e611c24ac758652399838929d4a6102e61a8e" + gatsby-plugin-manifest@^1.0.4: version "1.0.8" resolved "https://registry.yarnpkg.com/gatsby-plugin-manifest/-/gatsby-plugin-manifest-1.0.8.tgz#8c155cd2aed54759554c25bf9efb4a2c48de6429" @@ -5374,14 +5378,10 @@ items@2.x.x: version "2.1.1" resolved "https://registry.yarnpkg.com/items/-/items-2.1.1.tgz#8bd16d9c83b19529de5aea321acaada78364a198" -iterall@1.1.3: +iterall@1.1.3, iterall@^1.1.0: version "1.1.3" resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9" -iterall@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.1.tgz#f7f0af11e9a04ec6426260f5019d9fcca4d50214" - jest-docblock@^21.0.0: version "21.2.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414"