diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2016-01-24 00:07:27 -0800 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2016-01-24 00:07:27 -0800 |
commit | de889788fbf5fb1232dbf0d252e0aa729246095c (patch) | |
tree | 0d40b34d1946f093fa2a06326eab561933686e9e | |
parent | be8cab5f326231cbfc1347745417c73c5848f570 (diff) |
Only includes core code
-rw-r--r-- | dist/core.js (renamed from dist/text.js) | 173 | ||||
-rw-r--r-- | dist/presentation.js | 10 | ||||
-rw-r--r-- | gulpfile.js | 47 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/Document/Document.js (renamed from src/text/Document/Document.js) | 0 | ||||
-rw-r--r-- | src/Document/Nodes/Image.js (renamed from src/text/Document/Nodes/Image.js) | 0 | ||||
-rw-r--r-- | src/Document/Nodes/Paragraph.js (renamed from src/text/Document/Nodes/Paragraph.js) | 0 | ||||
-rw-r--r-- | src/Document/Nodes/TextSpan.js (renamed from src/text/Document/Nodes/TextSpan.js) | 1 | ||||
-rw-r--r-- | src/Node.js (renamed from src/text/Node.js) | 0 | ||||
-rw-r--r-- | src/NodeHistory.js (renamed from src/text/NodeHistory.js) | 0 | ||||
-rw-r--r-- | src/Transformation/Transformation.js (renamed from src/text/Transformation/Transformation.js) | 0 | ||||
-rw-r--r-- | src/presentation/Voir.jsx | 9 | ||||
-rw-r--r-- | src/presentation/demo.html | 15 |
13 files changed, 109 insertions, 148 deletions
diff --git a/dist/text.js b/dist/core.js index 83d52f6..49c202e 100644 --- a/dist/text.js +++ b/dist/core.js @@ -1,4 +1,44 @@ var ecrit = ecrit || {}; +ecrit.NodeHistory = function () { + this._push = this.push; + this.push = function (element) { + this._push(element); + this.sort(function (a, b) { + return a.timestamp - b.timestamp; + }); + }; +}; + +ecrit.NodeHistory.prototype = Object.create(Array.prototype); + +ecrit.NodeHistory.prototype.withTimestamp = function (stamp) { + for (var i = 0; i < this.length; i++) { + if (this[i].timestamp === stamp) { + return this[i]; + } + } + return null; +}; + +ecrit.NodeHistory.prototype.afterTimestamp = function (stamp) { + var ret = []; + for (var i = 0; i < this.length; i++) { + if (this[i].timestamp > stamp) { + ret.push(this[i]); + } + } + return ret; +}; + +ecrit.NodeHistory.prototype.betweenTimestamps = function (afterStamp, beforeStamp) { + var ret = []; + for (var i = 0; i < this.length; i++) { + if (this[i].timestamp > afterStamp && this[i].timestamp < beforeStamp) { + ret.push(this[i]); + } + } + return ret; +}; ecrit.Node = function (parent, id, nodes) { this.parent = parent; this.id = id; @@ -117,46 +157,6 @@ ecrit.Node.prototype.removeNode = function (node) { this._emit("childRemoved", foundNode); }; -ecrit.NodeHistory = function () { - this._push = this.push; - this.push = function (element) { - this._push(element); - this.sort(function (a, b) { - return a.timestamp - b.timestamp; - }); - }; -}; - -ecrit.NodeHistory.prototype = Object.create(Array.prototype); - -ecrit.NodeHistory.prototype.withTimestamp = function (stamp) { - for (var i = 0; i < this.length; i++) { - if (this[i].timestamp === stamp) { - return this[i]; - } - } - return null; -}; - -ecrit.NodeHistory.prototype.afterTimestamp = function (stamp) { - var ret = []; - for (var i = 0; i < this.length; i++) { - if (this[i].timestamp > stamp) { - ret.push(this[i]); - } - } - return ret; -}; - -ecrit.NodeHistory.prototype.betweenTimestamps = function (afterStamp, beforeStamp) { - var ret = []; - for (var i = 0; i < this.length; i++) { - if (this[i].timestamp > afterStamp && this[i].timestamp < beforeStamp) { - ret.push(this[i]); - } - } - return ret; -}; /** * Represents an ecrit Document. * @constructor @@ -238,52 +238,6 @@ ecrit.Document.prototype.applyTransformation = function (transformation, clone) } } }; -/** - * Represents a transformation to a Document. - * @constructor - * @param {object} data - The transformation data to apply. - */ -ecrit.Transformation = function (data) { - for (var prop in data) { - if (data.hasOwnProperty(prop)) { - this[prop] = data[prop]; - } - } -}; - -/** - * Reverses a transformation. The reversed transformation can be applied as an undo transformation. - * @returns {Transformation} - The reversed transformation - */ -ecrit.Transformation.prototype.reversed = function () { - var reversed = new Transformation(this); - - switch (this.action) { - case "insertText": - reversed.action = "removeText"; - reversed.fromIndex = this.atIndex; - reversed.toIndex = this.atIndex + this.contents.length; - break; - case "removeText": - reversed.action = "insertText"; - reversed.atIndex = this.fromIndex; - break; - - case "removeNode": - reversed.action = "insertNode"; - break; - case "insertNode": - reversed.action = "removeNode"; - break; - - case "modifyFormat": - reversed.add = reversed.remove; - reversed.remove = reversed.add; - break; - } - - return reversed; -}; ecrit.Paragraph = function (parent, id, nodes) { ecrit.Node.call(this, parent, id, nodes); @@ -359,6 +313,7 @@ ecrit.Paragraph.prototype.applyTransformation = function (transformation, clone) } }; ecrit.TextSpan = function (parent, id, options) { + options = options || {}; this.text = options.text || ""; this.formatting = options.formatting || []; @@ -435,4 +390,50 @@ ecrit.TextSpan.prototype.applyTransformation = function (transformation, clone) i--; } } +}; +/** + * Represents a transformation to a Document. + * @constructor + * @param {object} data - The transformation data to apply. + */ +ecrit.Transformation = function (data) { + for (var prop in data) { + if (data.hasOwnProperty(prop)) { + this[prop] = data[prop]; + } + } +}; + +/** + * Reverses a transformation. The reversed transformation can be applied as an undo transformation. + * @returns {Transformation} - The reversed transformation + */ +ecrit.Transformation.prototype.reversed = function () { + var reversed = new Transformation(this); + + switch (this.action) { + case "insertText": + reversed.action = "removeText"; + reversed.fromIndex = this.atIndex; + reversed.toIndex = this.atIndex + this.contents.length; + break; + case "removeText": + reversed.action = "insertText"; + reversed.atIndex = this.fromIndex; + break; + + case "removeNode": + reversed.action = "insertNode"; + break; + case "insertNode": + reversed.action = "removeNode"; + break; + + case "modifyFormat": + reversed.add = reversed.remove; + reversed.remove = reversed.add; + break; + } + + return reversed; };
\ No newline at end of file diff --git a/dist/presentation.js b/dist/presentation.js deleted file mode 100644 index 4c8e361..0000000 --- a/dist/presentation.js +++ /dev/null @@ -1,10 +0,0 @@ -var ecrit = ecrit || {}; -var Voir = React.createClass({displayName: "Voir", - render: function() { - return ( - React.createElement("div", null, - React.createElement("h3", null, "TODO") - ) - ); - } -}); diff --git a/gulpfile.js b/gulpfile.js index 3b68374..a51bb86 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,49 +1,40 @@ var gulp = require("gulp"); -var react = require('gulp-react'); +var order = require("gulp-order"); var concat = require("gulp-concat"); var vm = require("vm"); var fs = require("fs"); gulp.task('text', function () { - return gulp.src(["./src/ecrit.js", "./src/text/**/*.js" ]) - .pipe(concat('text.js')) - .pipe(gulp.dest('./dist/')); + return gulp.src("src/**/*.js") + .pipe(order([ + "ecrit.js", + "NodeHistory.js", + "Node.js", + "**/*.js" + ])) + .pipe(concat('core.js')) + .pipe(gulp.dest('dist/')); }); -gulp.task('presentation-jsx', function () { - return gulp.src("./src/presentation/**/*.jsx") - .pipe(react()) - .pipe(concat("pres-con.js")) - .pipe(gulp.dest('./temp/presentation/')); -}); - -gulp.task('presentation', function () { - gulp.start("presentation-jsx"); - - return gulp.src(["./src/ecrit.js", "./src/presentation/**/*.js", "./temp/presentation/**/*.js"]) - .pipe(concat('presentation.js')) - .pipe(gulp.dest('./dist/')); -}); - -gulp.task('default', ["text", "presentation"]); -gulp.task('build', ["text", "presentation"]); +gulp.task('default', [ "text" ]); +gulp.task('build', [ "text" ]); function assert(val, err) { if (!val) { console.log("FAILED: " + err); return; } - //console.log("Passed: " + err); + console.log("Passed: " + err); } gulp.task('test', function () { gulp.start("default"); - var code = fs.readFileSync("./dist/ecrit.js", 'utf-8'); + var code = fs.readFileSync("./dist/core.js", 'utf-8'); var sandbox = { console: console }; vm.runInNewContext(code, sandbox); - + var doc = new sandbox.ecrit.Document(); assert(doc.id === "root", "Doc ID check"); assert(doc.getChildNodeById("root").id === "root", "getChildNodeById"); @@ -71,11 +62,13 @@ gulp.task('test', function () { }); gulp.task('simple-test', function () { - var code = fs.readFileSync("./Line/line.js", 'utf-8'); + var coreCode = fs.readFileSync("./dist/core.js", 'utf-8'); + var lineCode = fs.readFileSync("./Line/line.js", 'utf-8'); var sandbox = {}; sandbox.console = console; - vm.runInNewContext(code, sandbox); + vm.runInNewContext(coreCode, sandbox); + vm.runInNewContext(lineCode, sandbox); // A test of the "3-Person Collisions" example from Design\Text Manipulation\Collisions.md with timestamps x100 @@ -143,7 +136,7 @@ gulp.task('simple-test', function () { }); gulp.task('watch', function () { - gulp.watch("./src/**/*", function(v) { + gulp.watch("src/**/*", function(v) { gulp.start('default'); }); });
\ No newline at end of file diff --git a/package.json b/package.json index 065d78d..786e754 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,6 @@ "devDependencies": { "gulp": "^3.9.0", "gulp-concat": "^2.6.0", - "gulp-react": "^3.0.1" + "gulp-order": "^1.1.0" } } diff --git a/src/text/Document/Document.js b/src/Document/Document.js index f86ac0e..f86ac0e 100644 --- a/src/text/Document/Document.js +++ b/src/Document/Document.js diff --git a/src/text/Document/Nodes/Image.js b/src/Document/Nodes/Image.js index e69de29..e69de29 100644 --- a/src/text/Document/Nodes/Image.js +++ b/src/Document/Nodes/Image.js diff --git a/src/text/Document/Nodes/Paragraph.js b/src/Document/Nodes/Paragraph.js index de6b19e..de6b19e 100644 --- a/src/text/Document/Nodes/Paragraph.js +++ b/src/Document/Nodes/Paragraph.js diff --git a/src/text/Document/Nodes/TextSpan.js b/src/Document/Nodes/TextSpan.js index 9e5fbd0..7653280 100644 --- a/src/text/Document/Nodes/TextSpan.js +++ b/src/Document/Nodes/TextSpan.js @@ -1,4 +1,5 @@ ecrit.TextSpan = function (parent, id, options) { + options = options || {}; this.text = options.text || ""; this.formatting = options.formatting || []; diff --git a/src/text/Node.js b/src/Node.js index cb3334c..cb3334c 100644 --- a/src/text/Node.js +++ b/src/Node.js diff --git a/src/text/NodeHistory.js b/src/NodeHistory.js index 0366c9f..0366c9f 100644 --- a/src/text/NodeHistory.js +++ b/src/NodeHistory.js diff --git a/src/text/Transformation/Transformation.js b/src/Transformation/Transformation.js index 4dd51b7..4dd51b7 100644 --- a/src/text/Transformation/Transformation.js +++ b/src/Transformation/Transformation.js diff --git a/src/presentation/Voir.jsx b/src/presentation/Voir.jsx deleted file mode 100644 index fe347f9..0000000 --- a/src/presentation/Voir.jsx +++ /dev/null @@ -1,9 +0,0 @@ -var Voir = React.createClass({ - render: function() { - return ( - <div> - <h3>TODO</h3> - </div> - ); - } -}); diff --git a/src/presentation/demo.html b/src/presentation/demo.html deleted file mode 100644 index 02e7471..0000000 --- a/src/presentation/demo.html +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>Ecrit Demo</title> - <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.min.js"></script> - <script type="text/javascript" src="../../dist/text.js"></script> - <script type="text/javascript" src="../../dist/presentation.js"></script> - </head> - <body> - <div id="ecrit-mount"></div> - <script> - React.render(React.createElement(Voir, null), document.getElementById("ecrit-mount")); - </script> - </body> -</html> |