You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by ah...@apache.org on 2017/02/16 01:26:21 UTC
zeppelin git commit: [ZEPPELIN-2070][DOCS] Create Docs for Spell
Repository: zeppelin
Updated Branches:
refs/heads/master 7805dd8c9 -> 90e8b80b5
[ZEPPELIN-2070][DOCS] Create Docs for Spell
### What is this PR for?
Docs for Spell which was added by #1940
### What type of PR is it?
[Documentation]
### Todos
* [x] - Add docs for spell
* [x] - Fix typo in vis docs
### What is the Jira issue?
[ZEPPELIN-2070](https://issues.apache.org/jira/browse/ZEPPELIN-2070)
### How should this be tested?
- `cd docs`
- `/usr/local/bin/bundle exec jekyll serve --watch`
- Open `http://localhost:4000/development/writingzeppelinspell.html`
### Screenshots (if appropriate)


### Questions:
* Does the licenses files need update? - NO
* Is there breaking changes for older versions? - NO
* Does this needs documentation? - YES
Author: 1ambda <1a...@gmail.com>
Closes #1998 from 1ambda/ZEPPELIN-2070/docs-for-spell and squashes the following commits:
dbb8082 [1ambda] fix: Typo
af63ff6 [1ambda] fix: Enhance spell doc
9fd2a3b [1ambda] fix: Typo
0851ad1 [1ambda] fix: Typo in spell doc
00d5158 [1ambda] fix: Indent
c7dc9bd [1ambda] fix: Typo in writing in viz
bcc9b3e [1ambda] docs: Add docs for spell
83ee050 [1ambda] docs: Add spell doc to nav
04deb81 [1ambda] fix: Invalid desc in vis docs
Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/90e8b80b
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/90e8b80b
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/90e8b80b
Branch: refs/heads/master
Commit: 90e8b80b560c6681f20ed00a913402f37f6e53ee
Parents: 7805dd8
Author: 1ambda <1a...@gmail.com>
Authored: Mon Feb 13 19:50:50 2017 +0900
Committer: ahyoungryu <ah...@apache.org>
Committed: Thu Feb 16 10:25:55 2017 +0900
----------------------------------------------------------------------
docs/_includes/themes/zeppelin/_navigation.html | 1 +
.../img/docs-img/writing_spell_registered.png | Bin 0 -> 168037 bytes
.../img/docs-img/writing_spell_using.gif | Bin 0 -> 3111011 bytes
docs/development/writingzeppelinspell.md | 214 +++++++++++++++++++
.../development/writingzeppelinvisualization.md | 9 +-
5 files changed, 219 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/90e8b80b/docs/_includes/themes/zeppelin/_navigation.html
----------------------------------------------------------------------
diff --git a/docs/_includes/themes/zeppelin/_navigation.html b/docs/_includes/themes/zeppelin/_navigation.html
index bc06b85..b53e9e9 100644
--- a/docs/_includes/themes/zeppelin/_navigation.html
+++ b/docs/_includes/themes/zeppelin/_navigation.html
@@ -123,6 +123,7 @@
<li role="separator" class="divider"></li>
<li class="title"><span><b>Contibute</b><span></li>
<li><a href="{{BASE_PATH}}/development/writingzeppelininterpreter.html">Writing Zeppelin Interpreter</a></li>
+ <li><a href="{{BASE_PATH}}/development/writingzeppelinspell.html">Writing Zeppelin Spell (Experimental)</a></li>
<li><a href="{{BASE_PATH}}/development/writingzeppelinvisualization.html">Writing Zeppelin Visualization (Experimental)</a></li>
<li><a href="{{BASE_PATH}}/development/writingzeppelinapplication.html">Writing Zeppelin Application (Experimental)</a></li>
<li><a href="{{BASE_PATH}}/development/howtocontribute.html">How to contribute (code)</a></li>
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/90e8b80b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_registered.png
----------------------------------------------------------------------
diff --git a/docs/assets/themes/zeppelin/img/docs-img/writing_spell_registered.png b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_registered.png
new file mode 100644
index 0000000..e8bcd47
Binary files /dev/null and b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_registered.png differ
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/90e8b80b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_using.gif
----------------------------------------------------------------------
diff --git a/docs/assets/themes/zeppelin/img/docs-img/writing_spell_using.gif b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_using.gif
new file mode 100644
index 0000000..ac73cef
Binary files /dev/null and b/docs/assets/themes/zeppelin/img/docs-img/writing_spell_using.gif differ
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/90e8b80b/docs/development/writingzeppelinspell.md
----------------------------------------------------------------------
diff --git a/docs/development/writingzeppelinspell.md b/docs/development/writingzeppelinspell.md
new file mode 100644
index 0000000..02a2301
--- /dev/null
+++ b/docs/development/writingzeppelinspell.md
@@ -0,0 +1,214 @@
+---
+layout: page
+title: "Writing a new Spell(Experimental)"
+description: "Spell is a kind of interpreter that runs on browser not on backend. So, technically it's the frontend interpreter. "
+group: development
+---
+<!--
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+{% include JB/setup %}
+
+# Writing a new Spell (Experimental)
+
+<div id="toc"></div>
+
+## What is Apache Zeppelin Spell
+
+Spell is a kind of interpreter that runs on browser not on backend. So, technically it's the frontend interpreter.
+It can provide many benefits.
+
+- Spell is pluggable frontend interpreter. So it can be installed and removed easily using helium registry.
+- Every spell is written in javascript. It means you can use existing javascript libraries whatever you want.
+- Spell runs on browser like display system (`%html`, `%table`). In other words, every spell can be used as display system as well.
+
+## How it works
+
+Helium Spell works like [Helium Visualization](./writingzeppelinvisualization.html).
+
+- Every helium packages are loaded from central (online) registry or local registry
+- You can see loaded packages in `/helium` page.
+- When you enable a spell, it's built from server and sent to client
+- Finally it will be loaded into browser.
+
+## How to use spell
+
+### 1. Enabling
+
+Find a spell what you want to use in `/helium` package and click `Enable` button.
+
+<img class="img-responsive" style="width:70%" src="../assets/themes/zeppelin/img/docs-img/writing_spell_registered.png" />
+
+### 2. Using
+
+Spell works like an interpreter. Use the `MAGIC` value to execute spell in a note. (you might need to refresh after enabling)
+For example, Use `%echo` for the Echo Spell.
+
+<img class="img-responsive" style="width:70%" src="../assets/themes/zeppelin/img/docs-img/writing_spell_using.gif" />
+
+
+## Write a new Spell
+
+Making a new spell is similar to [Helium Visualization#write-new-visualization](./writingzeppelinvisualization.html#write-new-visualization).
+
+- Add framework dependency called zeppelin-spell into `package.json`
+- Write code using framework
+- Publish your spell to [npm]("https://www.npmjs.com/")
+
+### 1. Create a npm package
+
+Create a [package.json](https://docs.npmjs.com/files/package.json) in new directory for spell.
+
+- You have to add a framework called `zeppelin-spell` as a dependency to create spell ([zeppelin-spell](https://github.com/apache/zeppelin/tree/master/zeppelin-web/src/app/spell))
+- Also, you can add any dependencies you want to utilise.
+
+Here's an example
+
+```
+{
+ "name": "zeppelin-echo-spell",
+ "description": "Zeppelin Echo Spell (example)",
+ "version": "1.0.0",
+ "main": "index",
+ "author": "",
+ "license": "Apache-2.0",
+ "dependencies": {
+ "zeppelin-spell": "*"
+ },
+ "helium": {
+ "icon" : "<i class='fa fa-repeat'></i>",
+ "spell": {
+ "magic": "%echo",
+ "usage": "%echo <TEXT>"
+ }
+ }
+}
+```
+
+### 2. Write spell using framework
+
+Here are some examples you can refer
+
+- [Echo Spell](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-echo/index.js)
+- [Markdown Spell: Using library](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-markdown/index.js)
+- [Flowchart Spell: Using DOM](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-flowchart/index.js)
+- [Google Translation API Spell: Using API (returning promise)](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-translator/index.js)
+
+Now, you need to write code to create spell which processing text.
+
+```javascript
+import {
+ SpellBase,
+ SpellResult,
+ DefaultDisplayType,
+} from 'zeppelin-spell';
+
+export default class EchoSpell extends SpellBase {
+ constructor() {
+ /** pass magic to super class's constructor parameter */
+ super("%echo");
+ }
+
+ interpret(paragraphText) {
+ const processed = paragraphText + '!';
+
+ /**
+ * should return `SpellResult` which including `data` and `type`
+ * default type is `TEXT` if you don't specify.
+ */
+ return new SpellResult(processed);
+ }
+}
+```
+
+Here is another example. Let's say we want to create markdown spell. First of all, we should add a dependency for markdown in package.json
+
+```
+// package.json
+ "dependencies": {
+ "markdown": "0.5.0",
+ "zeppelin-spell": "*"
+ },
+```
+
+And here is spell code.
+
+```javascript
+import {
+ SpellBase,
+ SpellResult,
+ DefaultDisplayType,
+} from 'zeppelin-spell';
+
+import md from 'markdown';
+
+const markdown = md.markdown;
+
+export default class MarkdownSpell extends SpellBase {
+ constructor() {
+ super("%markdown");
+ }
+
+ interpret(paragraphText) {
+ const parsed = markdown.toHTML(paragraphText);
+
+ /**
+ * specify `DefaultDisplayType.HTML` since `parsed` will contain DOM
+ * otherwise it will be rendered as `DefaultDisplayType.TEXT` (default)
+ */
+ return new SpellResult(parsed, DefaultDisplayType.HTML);
+ }
+}
+```
+
+- You might want to manipulate DOM directly (e.g google d3.js), then refer [Flowchart Spell](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-flowchart/index.js)
+- You might want to return promise not string (e.g API call), then refer [Google Translation API Spell](https://github.com/apache/zeppelin/blob/master/zeppelin-examples/zeppelin-example-spell-translator/index.js)
+
+### 3. Create __Helium package file__ for local deployment
+
+You don't want to publish your package every time you make a change in your spell. Zeppelin provides local deploy.
+The only thing you need to do is creating a __Helium Package file__ (JSON) for local deploy.
+It's automatically created when you publish to npm repository but in local case, you should make it by yourself.
+
+```
+{
+ "type" : "SPELL",
+ "name" : "zeppelin-echo-spell",
+ "version": "1.0.0",
+ "description" : "Return just what receive (example)",
+ "artifact" : "./zeppelin-examples/zeppelin-example-spell-echo",
+ "license" : "Apache-2.0",
+ "spell": {
+ "magic": "%echo",
+ "usage": "%echo <TEXT>"
+ }
+}
+```
+
+- Place this file in your local registry directory (default `$ZEPPELIN_HOME/helium`).
+- `type` should be `SPELL`
+- Make sure that `artifact` should be same as your spell directory.
+- You can get information about other fields in [Helium Visualization#3-create-helium-package-file-and-locally-deploy](./writingzeppelinvisualization.html#3-create-helium-package-file-and-locally-deploy).
+
+### 4. Run in dev mode
+
+```
+cd zeppelin-web
+yarn run dev:helium
+```
+
+You can browse localhost:9000. Every time refresh your browser, Zeppelin will rebuild your spell and reload changes.
+
+### 5. Publish your spell to the npm repository
+
+See [Publishing npm packages](https://docs.npmjs.com/getting-started/publishing-npm-packages)
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/90e8b80b/docs/development/writingzeppelinvisualization.md
----------------------------------------------------------------------
diff --git a/docs/development/writingzeppelinvisualization.md b/docs/development/writingzeppelinvisualization.md
index f7e1408..5ccd970 100644
--- a/docs/development/writingzeppelinvisualization.md
+++ b/docs/development/writingzeppelinvisualization.md
@@ -1,7 +1,7 @@
---
layout: page
title: "Writing a new Visualization(Experimental)"
-description: "Apache Zeppelin Application is a package that runs on Interpreter process and displays it's output inside of the notebook. Make your own Application in Apache Zeppelin is quite easy."
+description: "Apache Zeppelin Visualization is a pluggable package that can be loaded/unloaded on runtime through Helium framework in Zeppelin. A Visualization is a javascript npm package and user can use them just like any other built-in visualization in a note."
group: development
---
<!--
@@ -46,8 +46,7 @@ Click 'enable' button.
#### 3. Create and load visualization bundle on the fly
-Once a Visualization package is enabled, [HeliumVisualizationFactory](https://github.com/apache/zeppelin/blob/master/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumVisualizationFactory.java) creates a js bundle. The js bundle is served by `helium/visualization/load` rest api endpoint.
-
+Once a Visualization package is enabled, [HeliumBundleFactory](https://github.com/apache/zeppelin/blob/master/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumBundleFactory.java) creates a js bundle. The js bundle is served by `helium/bundle/load` rest api endpoint.
#### 4. Run visualization
@@ -130,7 +129,7 @@ Json file contains the following information
}
```
-Place file in your local registry directory (default `./helium`).
+Place this file in your local registry directory (default `./helium`).
##### type
@@ -194,7 +193,7 @@ Run Zeppelin. And then run zeppelin-web in visualization dev mode.
```
cd zeppelin-web
-yarn run visdev
+yarn run dev:helium
```
You can browse localhost:9000. Everytime refresh your browser, Zeppelin will rebuild your visualization and reload changes.