mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
style: Rename to Spell
This commit is contained in:
parent
e81cb03285
commit
cac0667b44
34 changed files with 164 additions and 162 deletions
|
|
@ -104,8 +104,8 @@
|
|||
<directory>../zeppelin-web/src/app/tabledata</directory>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<outputDirectory>/lib/node_modules/zeppelin-frontend-interpreter</outputDirectory>
|
||||
<directory>../zeppelin-web/src/app/frontend-interpreter</directory>
|
||||
<outputDirectory>/lib/node_modules/zeppelin-spell</outputDirectory>
|
||||
<directory>../zeppelin-web/src/app/spell</directory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
|
|
|
|||
|
|
@ -36,8 +36,10 @@
|
|||
<modules>
|
||||
<module>zeppelin-example-clock</module>
|
||||
<module>zeppelin-example-horizontalbar</module>
|
||||
<module>zeppelin-example-frontend-interpreter-flowchart</module>
|
||||
<module>zeppelin-example-frontend-interpreter-translator</module>
|
||||
<module>zeppelin-example-spell-flowchart</module>
|
||||
<module>zeppelin-example-spell-translator</module>
|
||||
<module>zeppelin-example-spell-markdown</module>
|
||||
<module>zeppelin-example-spell-echo</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"name": "echo-frontend-interpreter",
|
||||
"description": "Frontend Echo Interpreter (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"name": "markdown-frontend-interpreter",
|
||||
"description": "Frontend Markdown Interpreter (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"markdown": "0.5.0",
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"name": "translator-frontend-interpreter",
|
||||
"description": "Frontend Translator Interpreter (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"whatwg-fetch": "^2.0.1",
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -16,17 +16,17 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
SpellBase,
|
||||
SpellResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
} from 'zeppelin-spell';
|
||||
|
||||
export default class MarkdownInterpreter extends AbstractFrontendInterpreter {
|
||||
export default class EchoSpell extends SpellBase {
|
||||
constructor() {
|
||||
super("%echo");
|
||||
}
|
||||
|
||||
interpret(paragraphText) {
|
||||
return new FrontendInterpreterResult(paragraphText);
|
||||
return new SpellResult(paragraphText);
|
||||
}
|
||||
}
|
||||
11
zeppelin-examples/zeppelin-example-spell-echo/package.json
Normal file
11
zeppelin-examples/zeppelin-example-spell-echo/package.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "echo-spell",
|
||||
"description": "Echo Spell (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"zeppelin-spell": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,10 @@
|
|||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-echo</artifactId>
|
||||
<artifactId>zeppelin-example-spell-echo</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Echo Interpreter</name>
|
||||
<name>Zeppelin: Example Spell - Echo</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -15,10 +15,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "echo-frontend-interpreter",
|
||||
"type" : "SPELL",
|
||||
"name" : "echo-spell",
|
||||
"description" : "Return just what receive (example)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-echo",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-spell-echo",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-repeat'></i>"
|
||||
}
|
||||
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
SpellBase,
|
||||
SpellResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
} from 'zeppelin-spell';
|
||||
|
||||
import flowchart from 'flowchart.js';
|
||||
|
||||
export default class FlowchartInterpreter extends AbstractFrontendInterpreter {
|
||||
export default class FlowchartSpell extends SpellBase {
|
||||
constructor() {
|
||||
super("%flowchart");
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ export default class FlowchartInterpreter extends AbstractFrontendInterpreter {
|
|||
* `interpret` method can return multiple results using `add()`
|
||||
* but now, we return just 1 result
|
||||
*/
|
||||
return new FrontendInterpreterResult(
|
||||
return new SpellResult(
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "flowchart-frontend-interpreter",
|
||||
"description": "Frontend Flowchart Interpreter (example)",
|
||||
"name": "flowchart-spell",
|
||||
"description": "Flowchart Spell (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
|
|
@ -8,6 +8,6 @@
|
|||
"dependencies": {
|
||||
"raphael": "2.2.0",
|
||||
"flowchart.js": "^1.6.5",
|
||||
"zeppelin-frontend-interpreter": "*"
|
||||
"zeppelin-spell": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,10 @@
|
|||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-markdown</artifactId>
|
||||
<artifactId>zeppelin-example-spell-flowchart</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Markdown Interpreter</name>
|
||||
<name>Zeppelin: Example Spell - Flowchart</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -15,10 +15,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "flowchart-frontend-interpreter",
|
||||
"type" : "SPELL",
|
||||
"name" : "flowchart-spell",
|
||||
"description" : "with Flowchart.js (example)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-flowchart",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-spell-flowchart",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-random'></i>"
|
||||
}
|
||||
|
|
@ -16,16 +16,16 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
SpellBase,
|
||||
SpellResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
} from 'zeppelin-spell';
|
||||
|
||||
import md from 'markdown';
|
||||
|
||||
const markdown = md.markdown;
|
||||
|
||||
export default class MarkdownInterpreter extends AbstractFrontendInterpreter {
|
||||
export default class MarkdownSpell extends SpellBase {
|
||||
constructor() {
|
||||
super("%markdown");
|
||||
}
|
||||
|
|
@ -37,6 +37,6 @@ export default class MarkdownInterpreter extends AbstractFrontendInterpreter {
|
|||
* specify `DefaultDisplayType.HTML` since `parsed` will contain DOM
|
||||
* otherwise it will be rendered as `DefaultDisplayType.TEXT` (default)
|
||||
*/
|
||||
return new FrontendInterpreterResult(parsed, DefaultDisplayType.HTML);
|
||||
return new SpellResult(parsed, DefaultDisplayType.HTML);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "markdown-spell",
|
||||
"description": "Markdown Spell (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"markdown": "0.5.0",
|
||||
"zeppelin-spell": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,10 @@
|
|||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-flowchart</artifactId>
|
||||
<artifactId>zeppelin-example-spell-markdown</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Flowchart Interpreter</name>
|
||||
<name>Zeppelin: Example Spell - Markdown</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -15,10 +15,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "markdown-frontend-interpreter",
|
||||
"type" : "SPELL",
|
||||
"name" : "markdown-spell",
|
||||
"description" : "with markdown-js (example)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-markdown",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-spell-markdown",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-bold'></i>"
|
||||
}
|
||||
|
|
@ -16,26 +16,28 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
AbstractFrontendInterpreter,
|
||||
FrontendInterpreterResult,
|
||||
SpellBase,
|
||||
SpellResult,
|
||||
DefaultDisplayType,
|
||||
} from 'zeppelin-frontend-interpreter';
|
||||
} from 'zeppelin-spell';
|
||||
|
||||
import 'whatwg-fetch';
|
||||
|
||||
export default class TranslatorInterpreter extends AbstractFrontendInterpreter {
|
||||
export default class TranslatorSpell extends SpellBase {
|
||||
constructor() {
|
||||
super("%translator");
|
||||
}
|
||||
|
||||
interpret(paragraphText) {
|
||||
/**
|
||||
* FrontendInterpreterResult
|
||||
* SpellResult
|
||||
* - accepts not only `string` but also `promise`
|
||||
* - allows multiple output using the `add()` function
|
||||
* - allows to add multiple output using the `add()` function
|
||||
*/
|
||||
const result = new FrontendInterpreterResult()
|
||||
.add('%html <h4>Translation From English To Korean</h4>')
|
||||
const result = new SpellResult()
|
||||
.add('<h4>Translation From English To Korean</h4>', DefaultDisplayType.HTML)
|
||||
// or use display system implicitly like
|
||||
// .add('%html <h4>Translation From English To Korean</h4>')
|
||||
.add(this.translate(paragraphText));
|
||||
return result;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "translator-spell",
|
||||
"description": "Translator Spell (example)",
|
||||
"version": "1.0.0",
|
||||
"main": "index",
|
||||
"author": "",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"whatwg-fetch": "^2.0.1",
|
||||
"zeppelin-spell": "*"
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,10 @@
|
|||
</parent>
|
||||
|
||||
<groupId>org.apache.zeppelin</groupId>
|
||||
<artifactId>zeppelin-example-frontend-interpreter-translator</artifactId>
|
||||
<artifactId>zeppelin-example-spell-translator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.8.0-SNAPSHOT</version>
|
||||
<name>Zeppelin: Example application - Frontend Translator Interpreter</name>
|
||||
<name>Zeppelin: Example Spell - Translator</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -15,10 +15,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
{
|
||||
"type" : "FRONTEND_INTERPRETER",
|
||||
"name" : "translator-frontend-interpreter",
|
||||
"type" : "SPELL",
|
||||
"name" : "translator-spell",
|
||||
"description" : "with Google Translation API (examaple)",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-frontend-interpreter-translator",
|
||||
"artifact" : "./zeppelin-examples/zeppelin-example-spell-translator",
|
||||
"license" : "Apache-2.0",
|
||||
"icon" : "<i class='fa fa-globe '></i>"
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ public class HeliumPackage {
|
|||
NOTEBOOK_REPO,
|
||||
APPLICATION,
|
||||
VISUALIZATION,
|
||||
FRONTEND_INTERPRETER
|
||||
SPELL
|
||||
}
|
||||
|
||||
public HeliumPackage(Type type,
|
||||
|
|
@ -83,7 +83,7 @@ public class HeliumPackage {
|
|||
|
||||
public static boolean isBundleType(Type type) {
|
||||
return (type == Type.VISUALIZATION ||
|
||||
type == Type.FRONTEND_INTERPRETER);
|
||||
type == Type.SPELL);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
|||
|
|
@ -114,13 +114,13 @@ public class ZeppelinServer extends Application {
|
|||
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)),
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-tabledata")),
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-vis")),
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-frontend-interpreter")));
|
||||
new File(conf.getRelativeDir("lib/node_modules/zeppelin-spell")));
|
||||
} else {
|
||||
heliumBundleFactory = new HeliumBundleFactory(
|
||||
new File(conf.getRelativeDir(ConfVars.ZEPPELIN_DEP_LOCALREPO)),
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/tabledata")),
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/visualization")),
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/frontend-interpreter")));
|
||||
new File(conf.getRelativeDir("zeppelin-web/src/app/spell")));
|
||||
}
|
||||
|
||||
this.helium = new Helium(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { FrontendInterpreterResult } from '../../frontend-interpreter'
|
||||
import { SpellResult } from '../../spell'
|
||||
|
||||
angular.module('zeppelinWebApp').controller('ParagraphCtrl', ParagraphCtrl);
|
||||
|
||||
|
|
@ -225,15 +225,15 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
|
|||
websocketMsgSrv.cancelParagraphRun(paragraph.id);
|
||||
};
|
||||
|
||||
$scope.handleFrontendInterpreterError = function(error) {
|
||||
$scope.handleSpellError = function(error) {
|
||||
$scope.paragraph.status = 'ERROR';
|
||||
$scope.paragraph.errorMessage = error.stack;
|
||||
console.error('Failed to execute FrontendInterpreter.interpret\n', error);
|
||||
console.error('Failed to execute interpret() in spell\n', error);
|
||||
$scope.$digest();
|
||||
};
|
||||
|
||||
$scope.runParagraphUsingFrontendInterpreter = function(intp, paragraphText,
|
||||
magic, digestRequired) {
|
||||
$scope.runParagraphUsingSpell = function(spell, paragraphText,
|
||||
magic, digestRequired) {
|
||||
$scope.paragraph.results = {};
|
||||
if (digestRequired) { $scope.$digest(); }
|
||||
|
||||
|
|
@ -243,16 +243,16 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
|
|||
// remove leading spaces
|
||||
const textWithoutMagic = splited[1].replace(/^\s+/g, '');
|
||||
$scope.paragraph.status = 'FINISHED';
|
||||
const frontIntpResult = intp.interpret(textWithoutMagic);
|
||||
const parsed = frontIntpResult.getAllParsedGeneratorsWithTypes(
|
||||
heliumService.getAvailableFrontendInterpreters());
|
||||
const spellResult = spell.interpret(textWithoutMagic);
|
||||
const parsed = spellResult.getAllParsedGeneratorsWithTypes(
|
||||
heliumService.getAllSpells());
|
||||
parsed.then(resultsMsg => {
|
||||
$scope.paragraph.results.msg = resultsMsg;
|
||||
$scope.paragraph.config.tableHide = false;
|
||||
if (digestRequired) { $scope.$digest(); }
|
||||
}).catch($scope.handleFrontendInterpreterError);
|
||||
}).catch($scope.handleSpellError);
|
||||
} catch (error) {
|
||||
$scope.handleFrontendInterpreterError(error);
|
||||
$scope.handleSpellError(error);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -281,12 +281,12 @@ function ParagraphCtrl($scope, $rootScope, $route, $window, $routeParams, $locat
|
|||
return;
|
||||
}
|
||||
|
||||
const magic = FrontendInterpreterResult.extractMagic(paragraphText);
|
||||
const frontendIntp = heliumService.getFrontendInterpreterUsingMagic(magic);
|
||||
const magic = SpellResult.extractMagic(paragraphText);
|
||||
const spell = heliumService.getSpellByMagic(magic);
|
||||
|
||||
if (frontendIntp) {
|
||||
$scope.runParagraphUsingFrontendInterpreter(
|
||||
frontendIntp, paragraphText, magic, digestRequired);
|
||||
if (spell) {
|
||||
$scope.runParagraphUsingSpell(
|
||||
spell, paragraphText, magic, digestRequired);
|
||||
} else {
|
||||
$scope.runParagraphUsingBackendInterpreter(paragraphText);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import LinechartVisualization from '../../../visualization/builtins/visualizatio
|
|||
import ScatterchartVisualization from '../../../visualization/builtins/visualization-scatterchart';
|
||||
import {
|
||||
DefaultDisplayType,
|
||||
FrontendInterpreterResult,
|
||||
} from '../../../frontend-interpreter'
|
||||
SpellResult,
|
||||
} from '../../../spell'
|
||||
|
||||
angular.module('zeppelinWebApp').controller('ResultCtrl', ResultCtrl);
|
||||
|
||||
|
|
@ -297,12 +297,12 @@ function ResultCtrl($scope, $rootScope, $route, $window, $routeParams, $location
|
|||
renderApp(`p${appState.id}`, appState);
|
||||
} else {
|
||||
if (!DefaultDisplayType[type]) {
|
||||
const frontendIntp = heliumService.getFrontendInterpreterUsingMagic(type);
|
||||
if (!frontendIntp) {
|
||||
console.error(`Unknown Display Type: ${type}`);
|
||||
const spell = heliumService.getSpellByMagic(type);
|
||||
if (!spell) {
|
||||
console.error(`Can't execute spell due to unknown display type: ${type}`);
|
||||
return;
|
||||
}
|
||||
$scope.renderCustomDisplay(type, data, frontendIntp);
|
||||
$scope.renderCustomDisplay(type, data, spell);
|
||||
} else {
|
||||
const targetElemId = $scope.createDisplayDOMId(`p${$scope.id}`, type);
|
||||
$scope.renderDefaultDisplay(targetElemId, type, data, refresh);
|
||||
|
|
@ -317,12 +317,12 @@ function ResultCtrl($scope, $rootScope, $route, $window, $routeParams, $location
|
|||
/**
|
||||
* Render multiple sub results for custom display
|
||||
*/
|
||||
$scope.renderCustomDisplay = function(type, data, frontendIntp) {
|
||||
$scope.renderCustomDisplay = function(type, data, spell) {
|
||||
// get result from intp
|
||||
|
||||
const frontIntpResult = frontendIntp.interpret(data.trim());
|
||||
const parsed = frontIntpResult.getAllParsedGeneratorsWithTypes(
|
||||
heliumService.getAvailableFrontendInterpreters());
|
||||
const spellResult = spell.interpret(data.trim());
|
||||
const parsed = spellResult.getAllParsedGeneratorsWithTypes(
|
||||
heliumService.getAllSpells());
|
||||
|
||||
// custom display result can include multiple subset results
|
||||
parsed.then(dataWithTypes => {
|
||||
|
|
@ -356,14 +356,14 @@ function ResultCtrl($scope, $rootScope, $route, $window, $routeParams, $location
|
|||
* @param failureCallback
|
||||
*/
|
||||
const generateData = function(generator, type, successCallback, failureCallback) {
|
||||
if (FrontendInterpreterResult.isFunctionGenerator(generator)) {
|
||||
if (SpellResult.isFunctionGenerator(generator)) {
|
||||
try {
|
||||
successCallback(generator());
|
||||
} catch (error) {
|
||||
failureCallback(error);
|
||||
console.error(`Failed to handle ${type} type, function generator\n`, error);
|
||||
}
|
||||
} else if (FrontendInterpreterResult.isObjectGenerator(generator)) {
|
||||
} else if (SpellResult.isObjectGenerator(generator)) {
|
||||
try {
|
||||
successCallback(generator);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
export {
|
||||
DefaultDisplayType,
|
||||
FrontendInterpreterResult,
|
||||
} from './frontend-interpreter-result';
|
||||
SpellResult,
|
||||
} from './spell-result';
|
||||
|
||||
export {
|
||||
AbstractFrontendInterpreter
|
||||
} from './frontend-interpreter-framework';
|
||||
SpellBase,
|
||||
} from './spell-base';
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "zeppelin-frontend-interpreter",
|
||||
"description": "Frontend Interpreter API",
|
||||
"version": "0.7.0-SNAPSHOT",
|
||||
"name": "zeppelin-spell",
|
||||
"description": "Zeppelin Spell Framework",
|
||||
"version": "0.8.0-SNAPSHOT",
|
||||
"main": "index",
|
||||
"dependencies": {
|
||||
},
|
||||
|
|
@ -18,29 +18,27 @@
|
|||
/*eslint-disable no-unused-vars */
|
||||
import {
|
||||
DefaultDisplayType,
|
||||
FrontendInterpreterResult,
|
||||
} from './frontend-interpreter-result';
|
||||
SpellResult,
|
||||
} from './spell-result';
|
||||
/*eslint-enable no-unused-vars */
|
||||
|
||||
export class AbstractFrontendInterpreter {
|
||||
export class SpellBase {
|
||||
constructor(magic) {
|
||||
this.magic = magic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes text and return multiple interpreter results.
|
||||
* This method should handle error properly to provide precise error message.
|
||||
* Consumes text and return `SpellResult`.
|
||||
*
|
||||
* @param paragraphText {string} which doesn't include magic
|
||||
* @return {Array<FrontendInterpreterResult>}
|
||||
* @return {SpellResult}
|
||||
*/
|
||||
interpret(paragraphText) {
|
||||
/** implement this if you want to add a frontend interpreter */
|
||||
throw new Error('AbstractFrontendInterpreter.interpret is not overrided');
|
||||
throw new Error('SpellBase.interpret() should be overrided');
|
||||
}
|
||||
|
||||
/**
|
||||
* return magic for this frontend interpreter.
|
||||
* return magic for this spell.
|
||||
* (e.g `%flowchart`)
|
||||
* @return {string}
|
||||
*/
|
||||
|
|
@ -62,7 +62,7 @@ export class GeneratorWithType {
|
|||
// create `GeneratorWithType` whenever see available display type.
|
||||
for(let i = 0; i < splited.length; i++) {
|
||||
const g = splited[i];
|
||||
const magic = FrontendInterpreterResult.extractMagic(g);
|
||||
const magic = SpellResult.extractMagic(g);
|
||||
|
||||
// create `GeneratorWithType` only if see new magic
|
||||
if (availableMagic(magic) && mergedGens.length > 0) {
|
||||
|
|
@ -109,13 +109,13 @@ export class GeneratorWithType {
|
|||
|
||||
let wrapped;
|
||||
|
||||
if (FrontendInterpreterResult.isFunctionGenerator(generator)) {
|
||||
if (SpellResult.isFunctionGenerator(generator)) {
|
||||
// if generator is a function, we consider it as ELEMENT type.
|
||||
wrapped = new Promise((resolve) => {
|
||||
const result = [new GeneratorWithType(generator, DefaultDisplayType.ELEMENT)];
|
||||
return resolve(result);
|
||||
});
|
||||
} else if (FrontendInterpreterResult.isPromiseGenerator(generator)) {
|
||||
} else if (SpellResult.isPromiseGenerator(generator)) {
|
||||
// if generator is a promise,
|
||||
wrapped = generator.then(generated => {
|
||||
const result =
|
||||
|
|
@ -151,7 +151,7 @@ export class GeneratorWithType {
|
|||
/**
|
||||
* Value of `type` might be empty which means
|
||||
* generator can be splited into multiple generators
|
||||
* by `FrontendInterpreterResult.parseMultipleGenerators()`
|
||||
* by `SpellResult.parseMultipleGenerators()`
|
||||
* @returns {string}
|
||||
*/
|
||||
getType() {
|
||||
|
|
@ -159,7 +159,7 @@ export class GeneratorWithType {
|
|||
}
|
||||
}
|
||||
|
||||
export class FrontendInterpreterResult {
|
||||
export class SpellResult {
|
||||
constructor(resultGenerator, resultType) {
|
||||
this.generatorsWithTypes = [];
|
||||
this.add(resultGenerator, resultType);
|
||||
|
|
@ -175,8 +175,8 @@ export class FrontendInterpreterResult {
|
|||
|
||||
static isObjectGenerator(generator) {
|
||||
return (generator &&
|
||||
!FrontendInterpreterResult.isFunctionGenerator(generator) &&
|
||||
!FrontendInterpreterResult.isPromiseGenerator(generator));
|
||||
!SpellResult.isFunctionGenerator(generator) &&
|
||||
!SpellResult.isPromiseGenerator(generator));
|
||||
}
|
||||
|
||||
static extractMagic(allParagraphText) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
export const HeliumType = {
|
||||
VISUALIZATION: 'VISUALIZATION',
|
||||
FRONTEND_INTERPRETER: 'FRONTEND_INTERPRETER',
|
||||
SPELL: 'SPELL',
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import { HeliumType, } from './helium-type';
|
|||
// name `heliumBundles` should be same as `HelumBundleFactory.HELIUM_BUNDLES_VAR`
|
||||
var heliumBundles = [];
|
||||
// map for `{ magic: interpreter }`
|
||||
let frontendIntpWithMagic = {};
|
||||
let spellPerMagic = {};
|
||||
let visualizationBundles = [];
|
||||
|
||||
// load should be promise
|
||||
|
|
@ -39,9 +39,9 @@ import { HeliumType, } from './helium-type';
|
|||
|
||||
// extract bundles by type
|
||||
heliumBundles.map(b => {
|
||||
if (b.type === HeliumType.FRONTEND_INTERPRETER) {
|
||||
const interpreter = new b.class(); // eslint-disable-line new-cap
|
||||
frontendIntpWithMagic[interpreter.getMagic()] = interpreter;
|
||||
if (b.type === HeliumType.SPELL) {
|
||||
const spell = new b.class(); // eslint-disable-line new-cap
|
||||
spellPerMagic[spell.getMagic()] = spell;
|
||||
} else if (b.type === HeliumType.VISUALIZATION) {
|
||||
visualizationBundles.push(b);
|
||||
}
|
||||
|
|
@ -53,17 +53,17 @@ import { HeliumType, } from './helium-type';
|
|||
|
||||
/**
|
||||
* @param magic {string} e.g `%flowchart`
|
||||
* @returns {FrontendInterpreterBase} undefined for non-available magic
|
||||
* @returns {SpellBase} undefined if magic is not registered
|
||||
*/
|
||||
this.getFrontendInterpreterUsingMagic = function(magic) {
|
||||
return frontendIntpWithMagic[magic];
|
||||
this.getSpellByMagic = function(magic) {
|
||||
return spellPerMagic[magic];
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Object} map for `{ magic : interpreter }`
|
||||
* @returns {Object} map for `{ magic : spell }`
|
||||
*/
|
||||
this.getAvailableFrontendInterpreters = function() {
|
||||
return frontendIntpWithMagic;
|
||||
this.getAllSpells = function() {
|
||||
return spellPerMagic;
|
||||
};
|
||||
|
||||
this.getVisualizationBundles = function() {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class HeliumBundleFactory {
|
|||
private final File workingDirectory;
|
||||
private File tabledataModulePath;
|
||||
private File visualizationModulePath;
|
||||
private File frontendInterpreterModulePath;
|
||||
private File spellModulePath;
|
||||
private Gson gson;
|
||||
|
||||
String bundleCacheKey = "";
|
||||
|
|
@ -62,11 +62,11 @@ public class HeliumBundleFactory {
|
|||
File moduleDownloadPath,
|
||||
File tabledataModulePath,
|
||||
File visualizationModulePath,
|
||||
File frontendInterpreterModulePath) throws TaskRunnerException {
|
||||
File spellModulePath) throws TaskRunnerException {
|
||||
this(moduleDownloadPath);
|
||||
this.tabledataModulePath = tabledataModulePath;
|
||||
this.visualizationModulePath = visualizationModulePath;
|
||||
this.frontendInterpreterModulePath = frontendInterpreterModulePath;
|
||||
this.spellModulePath = spellModulePath;
|
||||
}
|
||||
|
||||
public HeliumBundleFactory(File moduleDownloadPath) throws TaskRunnerException {
|
||||
|
|
@ -252,17 +252,17 @@ public class HeliumBundleFactory {
|
|||
FileUtils.copyDirectory(visualizationModulePath, visModuleInstallPath, npmPackageCopyFilter);
|
||||
}
|
||||
|
||||
// install frontend-interpreter module
|
||||
File frontendInterpreterModuleInstallPath = new File(workingDirectory,
|
||||
"node_modules/zeppelin-frontend-interpreter");
|
||||
if (frontendInterpreterModulePath != null) {
|
||||
if (frontendInterpreterModuleInstallPath.exists()) {
|
||||
FileUtils.deleteDirectory(frontendInterpreterModuleInstallPath);
|
||||
// install spell module
|
||||
File spellModuleInstallPath = new File(workingDirectory,
|
||||
"node_modules/zeppelin-spell");
|
||||
if (spellModulePath != null) {
|
||||
if (spellModuleInstallPath.exists()) {
|
||||
FileUtils.deleteDirectory(spellModuleInstallPath);
|
||||
}
|
||||
|
||||
FileUtils.copyDirectory(
|
||||
frontendInterpreterModulePath,
|
||||
frontendInterpreterModuleInstallPath,
|
||||
spellModulePath,
|
||||
spellModuleInstallPath,
|
||||
npmPackageCopyFilter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class HeliumBundleFactoryTest {
|
|||
hbf = new HeliumBundleFactory(tmpDir,
|
||||
new File(moduleDir, "tabledata"),
|
||||
new File(moduleDir, "visualization"),
|
||||
new File(moduleDir, "frontend-interpreter"));
|
||||
new File(moduleDir, "spell"));
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
|||
Loading…
Reference in a new issue