Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated package.json

Updated .gitignore
Updated Makefile
Added stitch build script.
Updated demos to work with commonjs stitch modules.
Added wrapper to underscore to use global underscore when available. This is better for use on the web, as underscore can be loaded separately and cached.
Added new parsePage script.
Moved out test-server.
  • Loading branch information...
commit 7978331923da6ebfa4a0c2faf1fe5f898a88cfaf 1 parent 562660c
Jacob Beard authored
3  .gitignore
View
@@ -6,3 +6,6 @@ node_modules
build
src/demo/node-repl/build/
src/demo/nodejs/build/
+scion.js
+scion-min.js
+TODO
25 Makefile
View
@@ -0,0 +1,25 @@
+js = lib/scion.js lib/util/browser \
+ lib/util/browser/parsePage.js \
+ lib/util/browser/parseOnLoad.js \
+ lib/util/annotate-scxml-json.js \
+ lib/util/underscore-wrapper.js \
+ lib/scxml/SCXML.js \
+ lib/scxml/default-transition-selector.js \
+ lib/scxml/state-kinds-enum.js \
+ lib/scxml/setup-default-opts.js \
+ lib/scxml/model.js \
+ lib/scxml/scxml-dynamic-name-match-transition-selector.js \
+ lib/scxml/json2model.js \
+ lib/scxml/set/ArraySet.js
+
+scion.js : $(js)
+ mkdir -p build/
+ node build-lib/stitch.js
+
+scion-min.js : scion.js
+ uglifyjs scion.js > scion-min.js
+
+clean :
+ rm scion.js scion-min.js
+
+.PHONY : clean
13 build-lib/stitch.js
View
@@ -0,0 +1,13 @@
+var stitch = require('stitch');
+var fs = require('fs');
+
+var package = stitch.createPackage({
+ paths: [__dirname + '/../lib']
+});
+
+package.compile(function (err, source){
+ fs.writeFile('scion.js', source, function (err) {
+ if (err) throw err;
+ console.log('Compiled package.js');
+ })
+})
12 demo/drag-and-drop/drag-and-drop.xhtml
View
@@ -37,12 +37,13 @@ using SCXML:
padding: 0;
}
</style>
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/1.0.1/require.min.js"></script>
- <script type="text/javascript" src="http://jbeard4.github.com/SCION/builds/scion-browser-0.1.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
+ <script src="https://raw.github.com/mckamey/jsonml/master/jsonml-dom.js"></script>
+ <script type="text/javascript" src="/scion.js"></script>
<script type="text/javascript">
- require(['util/browser/parseOnLoad'],function(parseOnLoad){
- parseOnLoad()
- });
+ var parsepage = require('util/browser/parsePage');
+ $(document).ready(parsepage);
</script>
</head>
@@ -55,7 +56,6 @@ using SCXML:
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0"
profile="ecmascript"
- id="scxmlRoot"
initial="idle"
scion:domEventsToConnect="mousedown,mouseup,mousemove">
148 demo/drag-and-drop/drag-and-drop2.xhtml
View
@@ -33,14 +33,18 @@ own state.
}
</style>
<!-- we use jquery for jQuery.get and jQuery.globalEval (globalEval can optionally be used by the statechart) -->
- <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/1.0.1/require.min.js"></script>
- <script type="text/javascript" src="http://jbeard4.github.com/SCION/builds/scion-browser-0.1.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
+ <script src="https://raw.github.com/mckamey/jsonml/master/jsonml-dom.js"></script>
+ <script type="text/javascript" src="/scion.js"></script>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="99%" id="canvas"/>
<button id="elementButton" style="position:absolute;bottom:0px;left:0px;">Make draggable SVG Element</button>
<script><![CDATA[
+
+ var scion = require('scion');
+
var svgCanvas = document.getElementById("canvas"),
elementButton = document.getElementById("elementButton"),
SVG_NS = "http://www.w3.org/2000/svg";
@@ -48,87 +52,81 @@ own state.
//hook up minimal console api
if(typeof console == "undefined"){
console = {};
- ["log","info","error","dirxml"].forEach(function(m){console[m] = console[m] || function(){} });
+ ["log","info","error"].forEach(function(m){console[m] = console[m] || function(){} });
}
- //the steps 1-7 referenced here are described in full detail in src/main/coffeescript/util/browser/parseOnLoad.coffee
- require(["scxml/SCXML","util/annotate-scxml-json","scxml/json2model","scxml/event","lib/JsonML_DOM"],function(scxml,jsonAnnotator,json2model,Event,JsonML){
- var BrowserInterpreter = scxml.BrowserInterpreter;
-
- //step 1 - get the scxml document
- jQuery.get("drag-and-drop2.xml" , function(scxmlToTransform, textStatus, jqXHR){
-
- console.log("scxmlToTransform",scxmlToTransform);
+ //step 1 - get the scxml document
+ jQuery.get("drag-and-drop2.xml" , function(scxmlToTransform, textStatus, jqXHR){
- //step 2 - transform scxmlToTransform to JSON
- var arr = JsonML.parseDOM(scxmlToTransform);
- var scxmlJson = arr[1];
- console.log("scxmlJson",scxmlJson);
+ console.log("scxmlToTransform",scxmlToTransform);
- //step 3 - transform the parsed JSON model so it is friendlier to interpretation
- var annotatedScxmlJson = jsonAnnotator(scxmlJson);
- console.log("annotatedScxmlJson",annotatedScxmlJson);
+ //step 2 - transform scxmlToTransform to JSON
+ var arr = JsonML.parseDOM(scxmlToTransform);
+ var scxmlJson = arr[1];
+ console.log("scxmlJson",scxmlJson);
- //step 4 - initialize sc object model
- var model = json2model(annotatedScxmlJson);
- console.log("model",model);
+ //step 3 - transform the parsed JSON model so it is friendlier to interpretation
+ var annotatedScxmlJson = scion.annotator.transform(scxmlJson,true,true,true,true);
+ console.log("annotatedScxmlJson",annotatedScxmlJson);
+ //step 4 - initialize sc object model
+ var model = scion.json2model(annotatedScxmlJson);
+ console.log("model",model);
- //just for fun, random color generator, courtesy of http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
- function get_random_color() {
- var letters = '0123456789ABCDEF'.split('');
- var color = '#';
- for (var i = 0; i < 6; i++ ) {
- color += letters[Math.round(Math.random() * 15)];
- }
- return color;
+ //just for fun, random color generator, courtesy of http://stackoverflow.com/questions/1484506/random-color-generator-in-javascript
+ function get_random_color() {
+ var letters = '0123456789ABCDEF'.split('');
+ var color = '#';
+ for (var i = 0; i < 6; i++ ) {
+ color += letters[Math.round(Math.random() * 15)];
}
-
- //hook up button UI control
- elementButton.addEventListener("click",function(e){
-
- //do DOM stuff- create new blue circle
- var newGNode = document.createElementNS(SVG_NS,"g");
- var newTextNode = document.createElementNS(SVG_NS,"text");
- var newNode = document.createElementNS(SVG_NS,"circle");
- newNode.setAttributeNS(null,"cx",50);
- newNode.setAttributeNS(null,"cy",50);
- newNode.setAttributeNS(null,"r",50);
- newNode.setAttributeNS(null,"fill",get_random_color());
- newNode.setAttributeNS(null,"stroke","black");
-
- newGNode.appendChild(newNode);
- newGNode.appendChild(newTextNode);
-
- //step 5 - instantiate statechart
- var interpreter = new BrowserInterpreter(model,
- {
- //globalEval is used to execute any top-level script children of the scxml element
- //use of jQuery's global-eval is optional
- //TODO: cite that blog post about global-eval
- globalEval : jQuery.globalEval
- });
- console.log("interpreter",interpreter);
-
- //step 6 - connect all relevant event listeners
- ["mousedown","mouseup","mousemove"].forEach(function(eventName){
- newGNode.addEventListener( eventName, function(e){
- e.preventDefault();
- interpreter.gen(new Event(eventName,e))
- },false)
+ return color;
+ }
+
+ //hook up button UI control
+ elementButton.addEventListener("click",function(e){
+
+ //do DOM stuff- create new blue circle
+ var newGNode = document.createElementNS(SVG_NS,"g");
+ var newTextNode = document.createElementNS(SVG_NS,"text");
+ var newNode = document.createElementNS(SVG_NS,"circle");
+ newNode.setAttributeNS(null,"cx",50);
+ newNode.setAttributeNS(null,"cy",50);
+ newNode.setAttributeNS(null,"r",50);
+ newNode.setAttributeNS(null,"fill",get_random_color());
+ newNode.setAttributeNS(null,"stroke","black");
+
+ newGNode.appendChild(newNode);
+ newGNode.appendChild(newTextNode);
+
+ //step 5 - instantiate statechart
+ var interpreter = new scion.scxml.BrowserInterpreter(model,
+ {
+ //globalEval is used to execute any top-level script children of the scxml element
+ //use of jQuery's global-eval is optional
+ //TODO: cite that blog post about global-eval
+ globalEval : jQuery.globalEval
});
-
- //step 7 - start statechart
- interpreter.start()
-
- //step 8 - initialize his variables by sending an "init" event and passing the nodes in as data
- interpreter.gen(new Event("init",{rawNode:newGNode,textNode:newTextNode}));
-
- svgCanvas.appendChild(newGNode);
- },false);
-
- },"xml");
- });
+ console.log("interpreter",interpreter);
+
+ //step 6 - connect all relevant event listeners
+ ["mousedown","mouseup","mousemove"].forEach(function(eventName){
+ newGNode.addEventListener( eventName, function(e){
+ e.preventDefault();
+ interpreter.gen({name : eventName,data: e});
+ },false)
+ });
+
+ //step 7 - start statechart
+ interpreter.start()
+
+ //step 8 - initialize his variables by sending an "init" event and passing the nodes in as data
+ interpreter.gen({name : "init", data : {rawNode:newGNode,textNode:newTextNode}});
+
+ svgCanvas.appendChild(newGNode);
+ },false);
+
+ },"xml");
]]></script>
</body>
</html>
132 demo/drawing-tool/drawing-tool.html
View
@@ -50,9 +50,10 @@
</style>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/1.0.1/require.min.js"></script>
- <script type="text/javascript" src="http://jbeard4.github.com/SCION/builds/scion-browser-0.1.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+ <script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
+ <script src="https://raw.github.com/mckamey/jsonml/master/jsonml-dom.js"></script>
+ <script type="text/javascript" src="/scion.js"></script>
<script src="lib/jquery.svg.js" type="text/javascript"></script>
<script src="lib/jquery.svgdom.js" type="text/javascript"></script>
@@ -151,72 +152,69 @@
})
+ var scion = require('scion');
//the steps 1-7 referenced here are described in full detail in src/main/coffeescript/util/browser/parseOnLoad.coffee
- require(["scxml/SCXML","util/annotate-scxml-json","scxml/json2model","scxml/event","lib/JsonML_DOM"],function(scxml,jsonAnnotator,json2model,SCEvent,JsonML){
- var BrowserInterpreter = scxml.BrowserInterpreter;
-
- function hookUpDOMEvents(node,interpreter){
- //hook up DOM events
- ["mousedown","mouseup","mousemove"].forEach(function(eventName){
- node.addEventListener(eventName,function(e){
- e.preventDefault();
- interpreter.gen(new SCEvent(eventName,e));
- },false);
- });
- }
-
-
- //step 1 - get the scxml document
- jQuery.get("behaviour/canvas.xml" , function(scxmlToTransform, textStatus, jqXHR){
-
- console.log("scxmlToTransform",scxmlToTransform);
-
- //step 2 - transform scxmlToTransform to JSON
- var arr = JsonML.parseDOM(scxmlToTransform);
- var scxmlJson = arr[1];
- console.log("scxmlJson",scxmlJson);
-
- //step 3 - transform the parsed JSON model so it is friendlier to interpretation
- var annotatedScxmlJson = jsonAnnotator(scxmlJson);
- console.log("annotatedScxmlJson",annotatedScxmlJson);
-
- //step 4 - initialize sc object model
- var model = json2model(annotatedScxmlJson);
- console.log("model",model);
-
- //step 5 - instantiate statechart
- var interpreter = new BrowserInterpreter(model,
- {
- //globalEval is used to execute any top-level script children of the scxml element
- //use of jQuery's global-eval is optional
- //TODO: cite that blog post about global-eval
- globalEval : jQuery.globalEval
- });
- console.log("interpreter",interpreter);
-
-
- svg.statechart = interpreter; //hook up dom node reference
-
- //step 7 - start statechart
- interpreter.start()
-
- hookUpDOMEvents(svg.root(),interpreter);
- hookUpDOMEvents(toolbar.root(),interpreter);
-
- //pass in reference to rect
- interpreter.gen(new SCEvent("init",{
- svg:svg,
- transformModule:svgLib,
- scaleHandle:scaleHandle,
- rotationHandle:rotationHandle,
- ellipseButton:ellipseButton,
- rectButton:rectButton,
- transformButton:transformButton,
- ellipseIcon:ellipseButtonIcon,
- rectIcon:rectButtonIcon,
- transformIcon:transformButtonIcon
- }));
+ function hookUpDOMEvents(node,interpreter){
+ //hook up DOM events
+ ["mousedown","mouseup","mousemove"].forEach(function(eventName){
+ node.addEventListener(eventName,function(e){
+ e.preventDefault();
+ interpreter.gen({name : eventName,data : e});
+ },false);
});
+ }
+
+
+ //step 1 - get the scxml document
+ jQuery.get("behaviour/canvas.xml" , function(scxmlToTransform, textStatus, jqXHR){
+
+ console.log("scxmlToTransform",scxmlToTransform);
+
+ //step 2 - transform scxmlToTransform to JSON
+ var arr = JsonML.parseDOM(scxmlToTransform);
+ var scxmlJson = arr[1];
+ console.log("scxmlJson",scxmlJson);
+
+ //step 3 - transform the parsed JSON model so it is friendlier to interpretation
+ var annotatedScxmlJson = scion.annotator.transform(scxmlJson,true,true,true,true);
+ console.log("annotatedScxmlJson",annotatedScxmlJson);
+
+ //step 4 - initialize sc object model
+ var model = scion.json2model(annotatedScxmlJson);
+ console.log("model",model);
+
+ //step 5 - instantiate statechart
+ var interpreter = new scion.scxml.BrowserInterpreter(model,
+ {
+ //globalEval is used to execute any top-level script children of the scxml element
+ //use of jQuery's global-eval is optional
+ //TODO: cite that blog post about global-eval
+ globalEval : jQuery.globalEval
+ });
+ console.log("interpreter",interpreter);
+
+
+ svg.statechart = interpreter; //hook up dom node reference
+
+ //step 7 - start statechart
+ interpreter.start()
+
+ hookUpDOMEvents(svg.root(),interpreter);
+ hookUpDOMEvents(toolbar.root(),interpreter);
+
+ //pass in reference to rect
+ interpreter.gen({name : "init", data : {
+ svg:svg,
+ transformModule:svgLib,
+ scaleHandle:scaleHandle,
+ rotationHandle:rotationHandle,
+ ellipseButton:ellipseButton,
+ rectButton:rectButton,
+ transformButton:transformButton,
+ ellipseIcon:ellipseButtonIcon,
+ rectIcon:rectButtonIcon,
+ transformIcon:transformButtonIcon
+ }});
});
}
0  lib/index.js → lib/scion.js
View
File renamed without changes
7 lib/scxml/SCXML.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../util/underscore-wrapper');
var ArraySet = require('./set/ArraySet'),
stateKinds = require('./state-kinds-enum'),
@@ -80,11 +80,11 @@ SCXMLInterpreter.prototype = {
//eval top-level scripts
//we treat these differently than other scripts. they get evaled in global scope, and without explicit scripting interface
//this is necessary in order to, e.g., allow js function declarations that are visible to scxml script tags later.
- _(this.model.scripts).forEach(function(script){
+ _(this.model.scripts).forEach(_.bind(function(script){
/*jsl:ignore*/
with(this._datamodel){ this.opts.globalEval.call(null,script) };
/*jsl:end*/
- });
+ },this));
//initialize top-level datamodel expressions. simple eval
for(var k in this._datamodel){
@@ -287,7 +287,6 @@ SCXMLInterpreter.prototype = {
console.log(this._eval(action, datamodelForNextStep, eventSet));
break;
case "send":
- debugger;
if (this._send) {
this._send({
target: action.targetexpr ? this._eval(action.targetexpr, datamodelForNextStep, eventSet) : action.target,
2  lib/scxml/default-transition-selector.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../util/underscore-wrapper');
module.exports = function(state,eventNames,evaluator){
return _.filter(state.transitions,function(t){
2  lib/scxml/json2model.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../util/underscore-wrapper');
function getDelayInMs(delayString){
if (!delayString) {
2  lib/scxml/model.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../util/underscore-wrapper');
var stateKinds = require('./state-kinds-enum');
2  lib/scxml/scxml-dynamic-name-match-transition-selector.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../util/underscore-wrapper');
var eventNameReCache = {};
2  lib/scxml/set/ArraySet.js
View
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require('underscore');
+var _ = require('../../util/underscore-wrapper');
module.exports = function(l) {
l = l || [];
4 lib/util/annotate-scxml-json.js
View
@@ -63,7 +63,7 @@ Example SCXML document basic1.scxml stripped of whitespace and converted to Json
]
*/
-var _ = require('underscore');
+var _ = require('./underscore-wrapper');
var stateKinds = require("../scxml/state-kinds-enum");
@@ -179,7 +179,7 @@ function deconstructNode(node, filterText) {
return [tagName, attributes, children];
}
-var stripStarFromEventNameRe = /^((([a-zA-Z0-9]+)\.)*([a-zA-Z0-9]+))(\.\*)?$/;
+var stripStarFromEventNameRe = /^((([_a-zA-Z0-9]+)\.)*([_a-zA-Z0-9]+))(\.\*)?$/;
function transformTransitionNode (transitionNode, parentState, genDepth, genAncestors, genDescendants, genLCA) {
82 lib/util/browser/parseOnLoad.coffee
View
@@ -1,82 +0,0 @@
-#TODO: this will be the browser entry point. need to figure out domReady, and converting to JsonML in the browser
-
-#returns a function that should be called on load
-define ["lib/domReady","scxml/SCXML","util/annotate-scxml-json","scxml/json2model","scxml/event","lib/JsonML_DOM","browser/print"], (domReady,{BrowserInterpreter : BrowserInterpreter},jsonAnnotator,json2model,Event,JsonML) -> domReady ->
- #TODO: I should also try this module in some versions of IE, and see how well it does with regular HTML content
-
- """
- A statechart is initialized from an XML document as follows:
- 1. Get the SCXML document.
- 2. Convert the XML to JsonML using XSLT or DOM, and parse the JSON to
- an SCXML-JSON document.
- 3. Annotate and transform the SCXML-JSON document so that it is in a
- form more congenial to interpretation, creating an annotated SCXML-JSON
- document
- 4. Convert the SCXML-JSON document to a statechart object model. This
- step essentially converts id labels to object references, parses JavaScript
- scripts and expressions embedded in the SCXML as js functions, and does some
- validation for correctness.
- 5. Use the statechart object model to instantiate an instance of the
- statechart interpreter. Optionally, we can pass to the construct an object to
- be used as the context object (the 'this' object) in script evaluation. Lots of
- other parameters are available.
- 6. Connect relevant event listeners to the statechart instance.
- 7. Call the start method on the new intrepreter instance to start
- execution of the statechart.
-
- Also note that steps 1-3 can be done ahead-of-time. The annotated
- SCXML-JSON object can be serialized as JSON and sent across the wire before
- being converted to a statechart object model in step 4.
- """
- scxmlElements = document.getElementsByTagName "scxml"
-
- for scxml in scxmlElements
- console.log "scxml",scxml
-
- #step 1 - get the scxml document
- domNodeToHookUp = scxml.parentNode
- console.log "domNodeToHookUp",domNodeToHookUp
-
- #prep scxml document to transform by pulling the scxml node into its own document
- scxmlns = "http://www.w3.org/2005/07/scxml"
- scxmlToTransform = document.implementation.createDocument scxmlns,"scxml",null
- newNode = scxmlToTransform.importNode scxml.cloneNode(true),true
- scxmlToTransform.replaceChild newNode,scxmlToTransform.documentElement
- console.log "newNode",newNode
-
- #step 2 - transform scxmlToTransform to JSON
- [emptyTag, scxmlJson] = JsonML.parseDOM scxmlToTransform
- console.log "scxmlJson",scxmlJson
-
- #step 3 - transform the parsed JSON model so it is friendlier to interpretation
- annotatedScxmlJson = jsonAnnotator scxmlJson
- console.log "annotatedScxmlJson",annotatedScxmlJson
-
- #step 4 - initialize sc object model
- model = json2model annotatedScxmlJson
- console.log "model",model
-
- #step 5 - instantiate statechart
- interpreter = new BrowserInterpreter model,{evaluationContext : domNodeToHookUp}
- console.log "interpreter",interpreter
-
- #step 6 - connect all relevant event listeners - maybe encoded in DOM?
- #we use DOM to allow this to be set up declaratively
-
- scionNS ="https://github.com/jbeard4/SCION"
-
- if scxml.hasAttributeNS(scionNS,"domEventsToConnect")
- eventsString = scxml.getAttributeNS(scionNS,"domEventsToConnect")
- eventsToConnect = (event.trim() for event in eventsString.split(","))
-
- for eventName in eventsToConnect
- do (eventName) ->
- domNodeToHookUp.addEventListener(
- eventName,
- ((e) ->
- e.preventDefault()
- interpreter.gen(new Event(eventName,e))),
- false)
-
- #step 7 - start statechart
- interpreter.start()
90 lib/util/browser/parsePage.js
View
@@ -0,0 +1,90 @@
+/*
+
+This module exists to parse the SCXML from an HTML/SVG page once it's loaded.
+
+A statechart is initialized from an XML document as follows:
+1. Get the SCXML document.
+2. Convert the XML to JsonML using XSLT or DOM, and parse the JSON to
+ an SCXML-JSON document.
+3. Annotate and transform the SCXML-JSON document so that it is in a
+ form more congenial to interpretation, creating an annotated SCXML-JSON
+ document
+4. Convert the SCXML-JSON document to a statechart object model. This
+ step essentially converts id labels to object references, parses JavaScript
+ scripts and expressions embedded in the SCXML as js functions, and does some
+ validation for correctness.
+5. Use the statechart object model to instantiate an instance of the
+ statechart interpreter. Optionally, we can pass to the construct an object to
+ be used as the context object (the 'this' object) in script evaluation. Lots of
+ other parameters are available.
+6. Connect relevant event listeners to the statechart instance.
+7. Call the start method on the new intrepreter instance to start
+ execution of the statechart.
+
+Also note that steps 1-3 can be done ahead-of-time. The annotated
+ SCXML-JSON object can be serialized as JSON and sent across the wire before
+ being converted to a statechart object model in step 4.
+*/
+
+
+var scion = require('../../scion'),
+ _ = require('../underscore-wrapper');
+
+module.exports = function(){
+
+ var scxmlElements = document.getElementsByTagName("scxml");
+
+ _(scxmlElements).forEach(function(scxml){
+ console.log("scxml",scxml);
+
+ //step 1 - get the scxml document
+ var domNodeToHookUp = scxml.parentNode;
+ console.log("domNodeToHookUp",domNodeToHookUp);
+
+ //prep scxml document to transform by pulling the scxml node into its own document
+ var scxmlns = "http://www.w3.org/2005/07/scxml";
+ var scxmlToTransform = document.implementation.createDocument(scxmlns,"scxml",null);
+ var newNode = scxmlToTransform.importNode(scxml.cloneNode(true),true);
+ scxmlToTransform.replaceChild(newNode,scxmlToTransform.documentElement);
+ console.log("newNode",newNode);
+
+ //step 2 - transform scxmlToTransform to JSON
+ var scxmlJson = JsonML.parseDOM(scxmlToTransform)[1];
+ console.log("scxmlJson",scxmlJson);
+
+ //step 3 - transform the parsed JSON model so it is friendlier to interpretation
+ var annotatedScxmlJson = scion.annotator.transform(scxmlJson,true,true,true,true);
+ console.log("annotatedScxmlJson",annotatedScxmlJson);
+
+ //step 4 - initialize sc object model
+ var model = scion.json2model(annotatedScxmlJson);
+ console.log("model",model);
+
+ //step 5 - instantiate statechart
+ var interpreter = new scion.scxml.BrowserInterpreter(model,{evaluationContext : domNodeToHookUp});
+ console.log("interpreter",interpreter);
+
+ //step 6 - connect all relevant event listeners - maybe encoded in DOM?
+ //we use DOM to allow this to be set up declaratively
+
+ var scionNS ="https://github.com/jbeard4/SCION"
+
+ if(scxml.hasAttributeNS(scionNS,"domEventsToConnect")){
+ var eventsString = scxml.getAttributeNS(scionNS,"domEventsToConnect");
+ var eventsToConnect = eventsString.split(/\s*,\s*/);
+
+ _(eventsToConnect).forEach(function(eventName){
+ domNodeToHookUp.addEventListener(
+ eventName,
+ function(e){
+ e.preventDefault();
+ interpreter.gen({name : eventName,data:e});
+ },
+ false);
+ });
+ }
+
+ //step 7 - start statechart
+ interpreter.start()
+ });
+};
2  lib/util/underscore-wrapper.js
View
@@ -0,0 +1,2 @@
+//tiny wrapper module so that we can use underscore from CDN (better for caching)
+module.exports = this._ || require('underscore');
84 package.json
View
@@ -1,44 +1,44 @@
{
- "name": "scion",
- "version": "0.0.2",
- "description": "StateCharts Interpretation and Optimization eNgine (SCION) is an implementation of SCXML/Statecharts targeting JavaScript environments.",
- "keywords": [
- "scxml",
- "statecharts",
- "w3c",
- "javascript"
- ],
- "maintainers": [{
- "name": "Jacob Beard",
- "email": "jbeard4@cs.mcgill.ca",
- "url": "http://echo-flow.com"
- }],
- "bugs": {
- "email": "jbeard4@cs.mcgill.ca",
- "url": "https://github.com/jbeard4/SCION/issues"
- },
- "licenses": [
- {
- "type": "Apache-2.0",
- "url": "https://github.com/jbeard4/SCION/blob/master/LICENSE.txt"
- }
- ],
- "repositories": [
- {
- "type": "git",
- "url": "https://github.com/jbeard4/SCION.git"
- }
- ],
- "implements": [
- "http://www.w3.org/TR/scxml/"
- ],
- "dependencies": {
- "requirejs" : "*"
- },
- "engines" : { "node" : ">=0.4.7" },
- "bin": {
- "scxml-to-json" : "./src/main/bash/util/scxml-to-json.sh",
- "annotate-scxml-json": "./src/test-scripts/annotate-scxml-json.sh"
- },
- "main": "./target/core/node/index"
+ "name": "scion",
+ "version": "0.0.3",
+ "description": "StateCharts Interpretation and Optimization eNgine (SCION) is an implementation of SCXML/Statecharts in JavaScript.",
+ "keywords": [
+ "scxml",
+ "statecharts",
+ "w3c",
+ "javascript"
+ ],
+ "maintainers": [{
+ "name": "Jacob Beard",
+ "email": "jbeard4@cs.mcgill.ca",
+ "url": "http://echo-flow.com"
+ }],
+ "bugs": {
+ "email": "jbeard4@cs.mcgill.ca",
+ "url": "https://github.com/jbeard4/SCION/issues"
+ },
+ "licenses": [
+ {
+ "type": "Apache-2.0",
+ "url": "https://github.com/jbeard4/SCION/blob/master/LICENSE.txt"
+ }
+ ],
+ "repositories": [
+ {
+ "type": "git",
+ "url": "https://github.com/jbeard4/SCION.git"
+ }
+ ],
+ "implements": [
+ "http://www.w3.org/TR/scxml/"
+ ],
+ "dependencies": {
+ "underscore" : "*"
+ },
+ "devDependencies":{
+ "stitch" : "*",
+ "uglify" : "*"
+ },
+ "engines" : { "node" : ">=0.4.7" },
+ "main": "./lib/scion"
}
0  lib/util/test-server.js → test/test-server.js
View
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.