diff --git a/.gitignore b/.gitignore index eb6565c..8d1e25c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,9 @@ doc/_build doc/jsdoc patches/doc/jsdoc core-packages/*/doc/jsdoc +site-packages *.pyc *.old *.orig *(Autosaved)* +*.sublime-* diff --git a/context.jsx b/context.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/exceptions/index.jsx b/core-packages/__future__/lib/exceptions/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/ideas.txt b/core-packages/__future__/lib/ideas.txt old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/persistence/engines.jsx b/core-packages/__future__/lib/persistence/engines.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/persistence/index.jsx b/core-packages/__future__/lib/persistence/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/__future__/lib/preview/idea.txt b/core-packages/__future__/lib/preview/idea.txt old mode 100644 new mode 100755 diff --git a/core-packages/http/doc/readme.rst b/core-packages/http/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/auth.jsx b/core-packages/http/lib/auth.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/browser.jsx b/core-packages/http/lib/browser.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/index.jsx b/core-packages/http/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/lib/url.jsx b/core-packages/http/lib/url.jsx old mode 100644 new mode 100755 diff --git a/core-packages/http/test/http.specs b/core-packages/http/test/http.specs old mode 100644 new mode 100755 diff --git a/core-packages/io/lib/index.jsx b/core-packages/io/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/io/lib/octals.jsx b/core-packages/io/lib/octals.jsx old mode 100644 new mode 100755 diff --git a/core-packages/io/test/io.specs b/core-packages/io/test/io.specs old mode 100644 new mode 100755 diff --git a/core-packages/logging/doc/readme.rst b/core-packages/logging/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/logging/lib/index.jsx b/core-packages/logging/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/logging/test/logging.specs b/core-packages/logging/test/logging.specs old mode 100644 new mode 100755 diff --git a/core-packages/persistence/lib/index.jsx b/core-packages/persistence/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/templating/doc/readme.rst b/core-packages/templating/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/templating/lib/index.jsx b/core-packages/templating/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/templating/test/templating.specs b/core-packages/templating/test/templating.specs old mode 100644 new mode 100755 diff --git a/core-packages/testing/doc/readme.rst b/core-packages/testing/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/testing/doc/unit-testing.png b/core-packages/testing/doc/unit-testing.png old mode 100644 new mode 100755 diff --git a/core-packages/testing/lib/index.jsx b/core-packages/testing/lib/index.jsx old mode 100644 new mode 100755 index 1b98897..6b8a75e --- a/core-packages/testing/lib/index.jsx +++ b/core-packages/testing/lib/index.jsx @@ -17,34 +17,64 @@ var Template = require("templating").Template; var TestRunner = function () { this._clean_results = function (suites, results) { + var self = this var cleaned_results = suites.map(function(suite) { - var total = suite.children.length; - var passed = suite.children.filter(function(spec) { - return (results[spec.id].result == "passed"); - }).length; + + var specs = suite.children.map(function (spec) { - return {'name': spec.name, - 'result': results[spec.id].result, - 'messages': results[spec.id].messages + if(spec.type === 'suite'){ + return self._clean_results([spec], results)[0] + } + else { + + return { + 'name': spec.name, + 'result': results[spec.id].result, + 'messages': results[spec.id].messages, + 'type': 'spec' } + } }); + var total = specs.reduce(function(a,b){ + if(b.type === 'suite'){ + return a + b.total + } else { + return a + 1 + } + }, 0); + var passed = specs.reduce(function(a,b){ + if(b.type === 'suite'){ + return a + b.total + } else { + if(b.result == "passed"){ + return a + 1 + } else { + return a; + } + } + }, 0); + return { 'name': suite.name, 'passed': passed, 'failed': new Number(total - passed), 'total': total, - 'specs': specs + 'specs': specs, + 'type': 'suite' }; }); return cleaned_results; } this.run = function () { + if(this.results) return this.results; + var reporter = new jasmine.JsApiReporter(); jasmine.getEnv().addReporter(reporter); jasmine.getEnv().execute(); - return this._clean_results(reporter.suites_, reporter.results()); + this.results = this._clean_results(reporter.suites_, reporter.results()); + return this.results } this.get_environment = function () { @@ -62,20 +92,35 @@ var TestRunner = function () { }); } - // we'll add this into the html representation, + // we'll add this into the html representation, // so people can upload structured test reports to our central server. this.as_json = function () { - + + } + + this.print_suite = function(suite){ + var self = this; + suite.specs.forEach(function(spec) { + if(spec.type == 'suite'){ + self.print_suite(spec) + } + else { + $.writeln("\t" + spec.result.toUpperCase() + "\t" + spec.name); + if(spec.result != 'passed'){ + $.writeln('\t\t'+spec.messages.join('\n\t\t')) + } + } + }); } this.to_console = function () { var results = this.run(); - + var self = this results.forEach(function(suite) { - $.writeln("\nSuite: {} \tran {} tests, {} failure(s)".format(suite.name, suite.total, suite.failed)); - suite.specs.forEach(function(spec) { - $.writeln("\t" + spec.result.toUpperCase() + "\t" + spec.name); - }); + var passed = suite.specs.filter(function(s){ return s.result == 'passed' }).length || '0'; + var failed = suite.specs.filter(function(s){ return s.result != 'passed' }).length || '0'; + $.writeln("\nSuite: {} \tran {} tests, {} success, {} failure(s)".format(suite.name, suite.total, passed, failed)); + self.print_suite(suite) }); } @@ -83,18 +128,36 @@ var TestRunner = function () { // todo } + this.flatten = function(specs, res) { + res = res || []; + var self = this + specs.forEach(function(el){ + if(el.type === 'suite'){ + self.flatten(el.specs, res) + } else { + res.push(el) + } + }) + + return res; + } + this.to_html = function (filename) { // some background info var datetime = new Date(); var date = datetime.toDateString(); var time = "{}:{}".format(datetime.getHours(), datetime.getMinutes()); - var environment = this.get_environment(); + var environment = this.get_environment(); // run tests var results = this.run(); - + var self = this + // tidy up results results.forEach(function(suite) { + var prevSpecs = self.flatten(suite.specs); + + suite.specs = prevSpecs; suite.specs.forEach(function(spec) { if (spec.result == 'failed') { var messages = spec.messages.reject(function (message) { @@ -106,15 +169,15 @@ var TestRunner = function () { } }); }); - + var duration = ((new Date().getTime() - datetime.getTime())/1000).toFixed(2); - var template = new Template("report.html", module); + var template = new Template("report.html", module); template.render({ - 'date': date, - 'time': time, - 'duration': duration, - 'suites': results, + 'date': date, + 'time': time, + 'duration': duration, + 'suites': results, 'total': results.sum('total'), 'fails': results.sum('failed'), 'passes': results.sum('passed'), @@ -130,4 +193,4 @@ var TestRunner = function () { } } -exports.tests = new TestRunner(); \ No newline at end of file +exports.tests = new TestRunner(); diff --git a/core-packages/testing/templates/partial.environment.html b/core-packages/testing/templates/partial.environment.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/partial.suite.html b/core-packages/testing/templates/partial.suite.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/partial.test.html b/core-packages/testing/templates/partial.test.html old mode 100644 new mode 100755 diff --git a/core-packages/testing/templates/report.html b/core-packages/testing/templates/report.html old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/layout.png b/core-packages/ui/doc/layout.png old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/readme.rst b/core-packages/ui/doc/readme.rst old mode 100644 new mode 100755 diff --git a/core-packages/ui/doc/reference.rst b/core-packages/ui/doc/reference.rst old mode 100644 new mode 100755 diff --git a/core-packages/ui/lib/_ideas_.jsx b/core-packages/ui/lib/_ideas_.jsx old mode 100644 new mode 100755 diff --git a/core-packages/ui/lib/index.jsx b/core-packages/ui/lib/index.jsx old mode 100644 new mode 100755 index 69c2601..fbd8c6c --- a/core-packages/ui/lib/index.jsx +++ b/core-packages/ui/lib/index.jsx @@ -21,7 +21,7 @@ function ControlMixins () { } else { this[property] = mixin[property]; } - } + } } } @@ -33,22 +33,22 @@ function ControlMixins () { function UIShortcuts () { /* CONTAINER TYPES */ - + /** @desc adds a group, displayed as a row */ this.row = function (name) { - var group = this.add_group(name); + var group = this.add_group(name); group.window.orientation = 'row'; return group; } /** @desc adds a group, displayed as a column */ this.column = function (name) { - var group = this.add_group(name); - group.window.orientation = 'column'; + var group = this.add_group(name); + group.window.orientation = 'column'; return group; } /** @desc adds a group, displayed as a stack */ this.stack = function (name) { - var group = this.add_group(name); + var group = this.add_group(name); group.window.orientation = 'stack'; return group; } @@ -58,16 +58,17 @@ function UIShortcuts () { * @param {String} name The name this panel will take on within the dialog object * @param {Object} [properties] any other properties you want to pass along on creation */ - this.panel = function (name, properties) { + this.panel = function (name, label, properties) { var properties = properties || {}; - return this.add_container(name, 'panel', properties); + return this.add_container(name, 'panel', label, properties); } - /** + + /** * @desc adds a list, equivalent to ``listbox`` in plain ScriptUI * @param {String} name The name this list will take on within the dialog object * @param {String[]|Number} [headers] - * Either just a number of columns, or an array with + * Either just a number of columns, or an array with * header names. Once set, you may not add list items * with more columns than available in the header. * @param {Object} [properties] any other properties you want to pass along on creation @@ -79,8 +80,8 @@ function UIShortcuts () { properties.merge({'numberOfColumns': headers}); } else { properties.merge({ - 'numberOfColumns': headers.length, - 'showHeaders': true, + 'numberOfColumns': headers.length, + 'showHeaders': true, 'columnTitles': headers }); } @@ -88,71 +89,84 @@ function UIShortcuts () { return this.add_list(name, properties); } + /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ + // this.tree = function (name, text, options) { + // return this.add_control(name, 'treeview', text, options); + // } + + this.tree = function(name, properties) { + var properties = properties || {}; + return this.add_tree(name, properties); + } + /* SIMPLE TYPES */ /** @desc adds a button */ - this.button = function (name, text) { - return this.add_control(name, 'button', text); + this.button = function (name, text, options) { + return this.add_control(name, 'button', text, options); } /** @desc adds a checkbox */ - this.checkbox = function (name, text) { - return this.add_control(name, 'checkbox', text); + this.checkbox = function (name, text, value, options) { + if(typeof value === 'object') { + options = value; + value = false; + } + var checkbox = this.add_control(name, 'checkbox', text, options); + this[name].value = value + return checkbox + } /** @desc adds a dropdown, equivalent to ``dropdownlist`` in plain ScriptUI */ - this.dropdown = function (name, text) { - return this.add_control(name, 'dropdownlist', text); + this.dropdown = function (name, text, options) { + return this.add_control(name, 'dropdownlist', text, options); } /** @desc adds an input field, equivalent to ``edittext`` in plain ScriptUI */ - this.input = function (name, text) { - return this.add_control(name, 'edittext', text); + this.input = function (name, text, options) { + return this.add_control(name, 'edittext', text, options); } /** @desc adds an item (part of a list) */ this.item = function (name, values) { - return this.add_item(name, values); + return this.add_item(name, values); } /** @desc adds a flash element, equivalent to ``flashplayer`` in plain ScriptUI */ - this.flash = function (name, text) { - return this.add_control(name, 'flashplayer', text); + this.flash = function (name, text, options) { + return this.add_control(name, 'flashplayer', text, options); } /** @desc adds an icon button, equivalent to ``iconbutton`` in plain ScriptUI */ - this.icon = function (name, text) { - return this.add_control(name, 'iconbutton', text); + this.icon = function (name, text, options) { + return this.add_control(name, 'iconbutton', text, options); } /** @desc adds an image */ - this.image = function (name, text) { - return this.add_control(name, 'image', text); + this.image = function (name, text, options) { + return this.add_control(name, 'image', text, options); } /** @desc adds a progress bar */ - this.progressbar = function (name, text) { - return this.add_control(name, 'progressbar', text); + this.progressbar = function (name, text, options) { + return this.add_control(name, 'progressbar', text, options); } /** @desc adds a radio button, equivalent to ``radiobutton`` in plain ScriptUI */ - this.radio = function (name, text) { - return this.add_control(name, 'radiobutton', text); + this.radio = function (name, text, options) { + return this.add_control(name, 'radiobutton', text, options); } /** @desc adds a scrollbar */ - this.scrollbar = function (name, text) { - return this.add_control(name, 'scrollbar', text); + this.scrollbar = function (name, text, options) { + return this.add_control(name, 'scrollbar', text, options); } /** @desc adds a slider */ - this.slider = function (name, text) { - return this.add_control(name, 'slider', text); + this.slider = function (name, text, options) { + return this.add_control(name, 'slider', text, options); } /** @desc adds a text element, equivalent to ``statictext`` in plain ScriptUI */ - this.text = function (name, text) { - return this.add_control(name, 'statictext', text); + this.text = function (name, text, options) { + return this.add_control(name, 'statictext', text, options); } /** @desc adds a tab (part of a tabs control) */ - this.tab = function (name, text) { - return this.add_control(name, 'tab', text); + this.tab = function (name, text, options) { + return this.add_container(name, 'tab', text, options); } /** @desc adds a tabs container, equivalent to ``tabbedpanel`` in plain ScriptUI */ - this.tabs = function (name, text) { - return this.add_control(name, 'tabbedpanel', text); - } - /** @desc adds a tree, equivalent to ``treeview`` in plain ScriptUI */ - this.tree = function (name, text) { - return this.add_control(name, 'treeview', text); + this.tabs = function (name, text, options) { + return this.add_container(name, 'tabbedpanel', text, options); } } @@ -162,16 +176,16 @@ function UIShortcuts () { * Don't instantiate this class directly. */ -function UI () { - var self = this; - +function UI () { + var self = this; + this.mixins = {}; this.merge(new UIShortcuts()); // this variable is continually updated to reflect the last added layout element this._last_added = this; - + /** * @desc To make ``UI`` methods chainable, they return the entire * ``UI`` object instead of any control element you may have just created; @@ -200,7 +214,7 @@ function UI () { */ this.using = function () { // arguments may be passed either as variable arguments or as an array - var mixin_names = arguments.to('array').flatten(); + var mixin_names = arguments.to('array').flatten(); mixin_names.forEach(function(mixin_name){ var mixin = self.mixins[mixin_name]; if (mixin == undefined) { @@ -217,7 +231,7 @@ function UI () { } this.add_item = function (name, values) { - if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); + //if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); if (!values.is(Array)) throw new TypeError("A list item expects an array of text labels, not a string"); var control = self.window.add('item', values.shift()); values.forEach(function (value, i) { @@ -227,15 +241,15 @@ function UI () { control.merge(new ControlMixins()); this[name] = control; self._last_added = control; - return this; + return this; } - + this.add_control = function (name, type, text, properties) { - // people can add controls to this object willy-nilly, + // people can add controls to this object willy-nilly, // so we check whether they're not overriding any existing - // methods, attributes or controls. + // methods, attributes or controls. if (this[name] != undefined) throw new Error("{} is a reserved name.".format(name)); - + var control = self.window.add(type, undefined, text, properties); control.merge(new ControlMixins()); this[name] = control; @@ -243,21 +257,25 @@ function UI () { return this; } - this.add_group = function (name, properties) { - return this.add_container(name, 'group', properties); + this.add_group = function (name, label, properties) { + return this.add_container(name, 'group', label, properties); } this.add_list = function (name, properties) { - return this.add_container(name, 'listbox', properties); + return this.add_container(name, 'listbox', null, properties); } - this.add_container = function (name, type, properties) { + this.add_tree = function (name, properties) { + return this.add_container(name, 'treeview', null, properties); + } + + this.add_container = function (name, type, label, properties) { var ui = new UI(); - ui.window = this.add_control(name, type, undefined, properties).el(); + ui.window = this.add_control(name, type, label, properties).el(); ui._last_added = ui.window; ui.mixins = this.mixins; this[name] = ui; - return ui; + return ui; } } @@ -266,12 +284,12 @@ function UI () { exports.Dialog = function (title) { var ui = new UI(); - ui.window = new Window('dialog', title); + ui.window = new Window('dialog', title); return ui; } exports.Palette = function (title) { var ui = new UI(); - ui.window = new Window('palette', title); + ui.window = new Window('palette', title); return ui; -} \ No newline at end of file +} diff --git a/core-packages/ui/test/mixins.specs b/core-packages/ui/test/mixins.specs old mode 100644 new mode 100755 diff --git a/core-packages/ui/test/ui.specs b/core-packages/ui/test/ui.specs old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/array.jsx b/core-packages/utils/lib/array.jsx old mode 100644 new mode 100755 index 4837a51..ede1818 --- a/core-packages/utils/lib/array.jsx +++ b/core-packages/utils/lib/array.jsx @@ -8,7 +8,7 @@ var utils = require("utils/object"); * @desc Returns the first index at which a given element can be found in the selfay, or -1 if it is not present. * * @param {Object} element - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf */ @@ -47,12 +47,12 @@ exports.indexAfter = function (obj, element) { } /** - * @desc Returns the last index at which a given element can be found in the selfay, + * @desc Returns the last index at which a given element can be found in the selfay, * or -1 if it is not present. The selfay is searched backwards, starting at from_index. * * @param {Object} element * @param {Number} from_index - * + * * @see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/lastIndexOf */ @@ -89,7 +89,7 @@ exports.lastIndexOf = function(self, elt /*, from*/) * @desc Tests whether all elements in the selfay pass the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every */ @@ -111,7 +111,7 @@ exports.every = function(self, fun /*, thisp*/) { /** * @desc Creates a new selfay with all elements that pass the test implemented by the provided function. - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter */ @@ -140,7 +140,7 @@ exports.filter = function(self, fun /*, thisp*/) * @desc Executes a provided function once per selfay element. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach */ @@ -162,7 +162,7 @@ exports.filter = function(self, fun /*, thisp*/) * @desc Creates a new selfay with the results of calling a provided function on every element in this selfay. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map */ @@ -186,7 +186,7 @@ exports.map = function(self, fun /*, thisp*/) { * @desc Tests whether some element in the selfay passes the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some */ @@ -212,11 +212,11 @@ exports.some = function(self, fun /*, thisp*/) /* Javascript 1.8 Array extras, courtesy of Mozilla */ /** - * @desc Apply a function against an accumulator and + * @desc Apply a function against an accumulator and * each value of the selfay (from left-to-right) as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce */ @@ -266,7 +266,7 @@ exports.some = function(self, fun /*, thisp*/) * as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight */ @@ -353,7 +353,7 @@ exports.max = function (self, salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -374,7 +374,7 @@ exports.min = function (self, salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -406,7 +406,7 @@ exports.sum = function (self, salient) { } var features = exports.map(self, mapper); - return exports.reduce(features, function (a, b) { return a + b; }); + return exports.reduce(features, function (a, b) { return a + b; }); } /** @@ -478,4 +478,10 @@ exports.last = function (self) { exports.contains = function (self, obj) { return exports.indexOf(self, obj) != -1; -} \ No newline at end of file +} + +exports.log = function(self, dump) { + return '[' + exports.map(self, function(item) { + item.log ? item.inspect(dump) : item.toString() + }).join(', ') + ']' +} diff --git a/core-packages/utils/lib/date.jsx b/core-packages/utils/lib/date.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/error.jsx b/core-packages/utils/lib/error.jsx old mode 100644 new mode 100755 index 9627e4b..ba0934c --- a/core-packages/utils/lib/error.jsx +++ b/core-packages/utils/lib/error.jsx @@ -1,7 +1,7 @@ /** * @desc This method overloads :func:`Object#is` to combat a problem with some versions of ExtendScript * that leads to all error types being considered the base class Error. This problem makes it impossible to - * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous + * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous * expression should return false but will return true. * * When testing whether you're dealing with a specific kind of error, use this method, and refrain @@ -167,4 +167,4 @@ if (is_indesign) { * @name ValidationError */ ValidationError.prototype._type = ValidationError; -} \ No newline at end of file +} diff --git a/core-packages/utils/lib/file.jsx b/core-packages/utils/lib/file.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/folder.jsx b/core-packages/utils/lib/folder.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/index.jsx b/core-packages/utils/lib/index.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/math.jsx b/core-packages/utils/lib/math.jsx old mode 100644 new mode 100755 diff --git a/core-packages/utils/lib/object.conversions.jsx b/core-packages/utils/lib/object.conversions.jsx old mode 100644 new mode 100755 index e4623df..7de8021 --- a/core-packages/utils/lib/object.conversions.jsx +++ b/core-packages/utils/lib/object.conversions.jsx @@ -1,4 +1,4 @@ -var exports = {}; +var exports = exports || {}; var base64 = exports; #include "../dependencies/base64.js" #include "../dependencies/json2.js" @@ -31,12 +31,12 @@ keyvalue.decode = function (str, options) { pair = pair.split(separator); obj[pair[0]] = pair[1]; }); - return obj; + return obj; } /** * @desc Object serialization. - * + * * The result of serialization followed by deserialization is the original object, whereas * a conversion is not reversible. * @@ -89,11 +89,11 @@ exports.deserialize = function (self, type, options) { } /** - * @desc Provides easy shortcuts to a number of common conversions, like lowercasing a string or + * @desc Provides easy shortcuts to a number of common conversions, like lowercasing a string or * converting the ``arguments`` object to an array. - * + * * All of these conversions return a new object, they do not modify the original. - * + * * A ``slug`` is a string that's usable as a filename or in an URL: it's * a lowercased string with all non-alphanumeric characters stripped out, and spaces replaced by * hyphens. @@ -115,7 +115,7 @@ exports.deserialize = function (self, type, options) { exports.to = function (self, type) { // never, ever modify the original object var result = object.clone(self); - + var conversions = { /* types */ // REFACTOR: 'int' should be 'number', to correspond to the class name! @@ -137,4 +137,4 @@ exports.to = function (self, type) { } else { throw RangeError(string.format("This method cannot convert from {} to {}", self.prototype.name, type)); } -} \ No newline at end of file +} diff --git a/core-packages/utils/lib/object.jsx b/core-packages/utils/lib/object.jsx old mode 100644 new mode 100755 index db4323c..6b051b2 --- a/core-packages/utils/lib/object.jsx +++ b/core-packages/utils/lib/object.jsx @@ -1,12 +1,12 @@ -/* - * Patches for functional programming. - * Inspired by and sometimes copied from underscore.js +/* + * Patches for functional programming. + * Inspired by and sometimes copied from underscore.js */ /** * @desc Merge two objects together. This modifies the original object. * First use :func:`Object#clone` on the object if you want to keep the original object intact. - * + * * @param {Object} obj The object to merge into this one. * * @returns {Object} Returns the merged object (``this``); @@ -14,7 +14,7 @@ exports.merge = function (self, obj) { if (!obj) return; - + var merged_obj = self; for (var name in obj) { merged_obj[name] = obj[name]; @@ -46,7 +46,7 @@ exports.clone = function (self) { /** * @desc * Returns only the keys (also known as 'names') of an object or associative array. - * Will filter out any functions, as these are presumed to be object methods. + * Will filter out any functions, as these are presumed to be object methods. * @returns {Array} An array with all the keys. */ @@ -74,7 +74,7 @@ exports.values = function (self) { for (var i = 0; i < keys.length; i++) { values.push(self[keys[i]]); } - + return values; } @@ -98,8 +98,8 @@ exports.is = function(self, type) { exports.has = function (self, key) { // could be just null or an invalid object // either way, has() should return false - if (self == null || self[key] == null) return false; - + if (self == null || self[key] == null) return false; + if (key in self) { return new Boolean(self[key]) != false; } else { @@ -125,6 +125,11 @@ exports.has_own = function (self, key) { */ exports.log = function (self, dump) { + var out = exports.inspect(self, dump); + return $.writeln(out); +} + +exports.inspect = function(self, dump) { if (dump) { var props = exports.keys(self.reflect.properties); for (var i = 0; i < props.length; i++) { @@ -135,5 +140,5 @@ exports.log = function (self, dump) { } else { var out = self.toString(); } - return $.writeln(out); -} \ No newline at end of file + return out; +} diff --git a/core-packages/utils/lib/string.jsx b/core-packages/utils/lib/string.jsx old mode 100644 new mode 100755 diff --git a/dependencies/base64.js b/dependencies/base64.js index b21bd59..68271da 100644 --- a/dependencies/base64.js +++ b/dependencies/base64.js @@ -1,4 +1,5 @@ -exports.encode64 = encoder('+/'); +exports = exports || {} +exports.encode64 = encoder('+/'); exports.decode64 = decoder('+/'); exports.urlsafeEncode64 = encoder('-_'); exports.urlsafeDecode64 = decoder('-_'); @@ -78,4 +79,4 @@ function alphabet(extra) { function regexp_escape(expr) { return expr.replace(/([\^\$\/\.\*\-\+\?\|\(\)\[\]\{\}\\])/, '\\$1'); -} \ No newline at end of file +} diff --git a/dependencies/jasmine.js b/dependencies/jasmine.js index 1adab61..dd5b18e 100644 --- a/dependencies/jasmine.js +++ b/dependencies/jasmine.js @@ -1,4 +1,4 @@ -/** +/** * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. * * @namespace @@ -126,7 +126,7 @@ jasmine.getEnv = function() { * @returns {Boolean} */ jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); + return jasmine.isA_("Array", value); }; /** @@ -973,7 +973,7 @@ jasmine.Block = function(env, func, spec) { this.spec = spec; }; -jasmine.Block.prototype.execute = function(onComplete) { +jasmine.Block.prototype.execute = function(onComplete) { try { this.func.apply(this.spec); } catch (e) { @@ -1009,11 +1009,11 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { var isSuite = suiteOrSpec instanceof jasmine.Suite; var summary = { id: suiteOrSpec.id, - name: suiteOrSpec.description, + name: suiteOrSpec.getFullName(), type: isSuite ? 'suite' : 'spec', children: [] }; - + if (isSuite) { var children = suiteOrSpec.children(); for (var i = 0; i < children.length; i++) { @@ -1714,7 +1714,7 @@ jasmine.Queue.prototype.next_ = function() { while (goAgain) { goAgain = false; - + if (self.index < self.blocks.length && !this.abort) { var calledSynchronously = true; var completedSynchronously = false; @@ -1752,7 +1752,7 @@ jasmine.Queue.prototype.next_ = function() { if (completedSynchronously) { onComplete(); } - + } else { self.running = false; if (self.onComplete) { @@ -2428,4 +2428,4 @@ jasmine.version_= { "minor": 0, "build": 0, "revision": 1284494074 -}; \ No newline at end of file +}; diff --git a/extendables.jsx b/extendables.jsx old mode 100644 new mode 100755 index 0c0188c..cbf4544 --- a/extendables.jsx +++ b/extendables.jsx @@ -1,29 +1,33 @@ -// we need to log somethings before the log module is loaded, +// we need to log somethings before the log module is loaded, // so we buffer these messages var log_buffer = []; #include "patches/__all__.jsx"; -var default_settings = new File("settings.jsx").at(Folder.extendables); -var project_specific_settings = new File("settings.jsx").at(Folder.extendables.parent); -if (project_specific_settings.exists) { - // allows for project-specific settings, so nobody - // has to override anything within /extendables - // (this feature is currently undocumented) - log_buffer.push([4, "Loading Extendables with project-specific settings at {}", project_specific_settings]); - $.evalFile(project_specific_settings); -} else { - log_buffer.push([4, "Loading Extendables with default settings"]); - $.evalFile(default_settings); -} -#include "loader.jsx"; -load_modules(settings.package_directories); -#include "context.jsx"; -// write away buffered log messages +if(!this.standalone){ + var default_settings = new File("settings.jsx").at(Folder.extendables); + var project_specific_settings = new File("settings.jsx").at(Folder.extendables.parent); + + if (project_specific_settings.exists) { + // allows for project-specific settings, so nobody + // has to override anything within /extendables + // (this feature is currently undocumented) + log_buffer.push([4, "Loading Extendables with project-specific settings at {}", project_specific_settings]); + $.evalFile(project_specific_settings); + } else { + log_buffer.push([4, "Loading Extendables with default settings"]); + $.evalFile(default_settings); + } + #include "loader.jsx"; + load_modules(settings.package_directories); + #include "context.jsx"; -var logging = require("logging"); -var syslog = new logging.Log("extendables.log"); + // write away buffered log messages -log_buffer.forEach(function (message) { - syslog.log.apply(null, message); -}); \ No newline at end of file + var logging = require("logging"); + var syslog = new logging.Log("extendables.log"); + + log_buffer.forEach(function (message) { + syslog.log.apply(null, message); + }); +} diff --git a/loader.jsx b/loader.jsx old mode 100644 new mode 100755 index 53a9992..4ed7280 --- a/loader.jsx +++ b/loader.jsx @@ -4,15 +4,16 @@ */ var __modules__ = {}; +var __cache__ = {} function require (module_id) { // CommonJS: A module identifier is a String of "terms" var terms = module_id.split('/'); var module = terms.shift(); if (__modules__.hasOwnProperty(module)) { if (terms.length) { - return __modules__[module].get_submodule(terms).load().exports; + return __cache__[module_id] = __cache__[module_id] || __modules__[module].get_submodule(terms).load().exports; } else { - return __modules__[module].load().exports; + return __cache__[module] = __cache__[module] || __modules__[module].load().exports; } } else { throw Error("No package named " + module_id); @@ -32,9 +33,9 @@ function _is_valid_module (file_or_folder) { return file_or_folder.is(Folder) || file_or_folder.name.endswith(".jsx"); } -function Module (file_or_folder, is_package) { +function Module (file_or_folder, is_package) { var self = this; - + this.eval = function (file) { var exports = {}; var module = { @@ -45,9 +46,27 @@ function Module (file_or_folder, is_package) { try { $.evalFile(file); } catch (error) { - log_buffer.push([3, "Could not fully load " + module.id + "\n" + error]); + log_buffer.push([3, "Could not fully load " + module.id + "\n" + error]); } - return exports; + if(exports.wrap_methods_with_try_catch){ + var props = exports.keys() + props.forEach(function(k){ + + if(typeof exports[k] === 'function' && k[0].toLowerCase() === k[0]){ + var original = exports[k] + + exports[k] = function(){ + try { + return original.apply(this, arguments) + } + catch(e){ + throw e + } + } + } + }) + } + return exports; }; this.extract_submodules = function () { @@ -56,7 +75,7 @@ function Module (file_or_folder, is_package) { base.changePath("./lib"); } var submodule_files = base.getFiles(_is_valid_module); - + submodule_files.forEach(function(submodule) { var submodule = new Module(submodule); self.submodules[submodule.id] = submodule; @@ -99,7 +118,7 @@ function Module (file_or_folder, is_package) { } return self } - + /* init */ this.id = file_or_folder.displayName.split('.')[0]; this.uri = file_or_folder.absoluteURI; @@ -118,13 +137,13 @@ function load_modules (packagefolders) { var folder = packagefolder; } var packages = folder.getFiles(_is_valid_module); - + packages.forEach(function(file_or_folder) { // An alias regists as a file in ExtendScript, even if it refers to a folder. // Check if the file is an alias and, if so, resolve it. if (file_or_folder.alias) file_or_folder = file_or_folder.resolve(); var module = new Module(file_or_folder, true); __modules__[module.id] = module; - }); + }); }); -} \ No newline at end of file +} diff --git a/patches/array.jsx b/patches/array.jsx index b467bf7..7e3e23b 100644 --- a/patches/array.jsx +++ b/patches/array.jsx @@ -6,7 +6,7 @@ * @desc Returns the first index at which a given element can be found in the array, or -1 if it is not present. * * @param {Object} element - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf */ @@ -45,12 +45,12 @@ Array.prototype.indexAfter = function (element) { } /** - * @desc Returns the last index at which a given element can be found in the array, + * @desc Returns the last index at which a given element can be found in the array, * or -1 if it is not present. The array is searched backwards, starting at from_index. * * @param {Object} element * @param {Number} from_index - * + * * @see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/lastIndexOf */ @@ -87,7 +87,7 @@ Array.prototype.indexAfter = function (element) { * @desc Tests whether all elements in the array pass the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every */ @@ -110,7 +110,7 @@ Array.prototype.indexAfter = function (element) { /** * @desc Creates a new array with all elements that pass the test implemented by the provided function. - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter */ @@ -139,7 +139,7 @@ Array.prototype.indexAfter = function (element) { * @desc Executes a provided function once per array element. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach */ @@ -161,7 +161,7 @@ Array.prototype.indexAfter = function (element) { * @desc Creates a new array with the results of calling a provided function on every element in this array. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map */ @@ -186,7 +186,7 @@ Array.prototype.indexAfter = function (element) { * @desc Tests whether some element in the array passes the test implemented by the provided function. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some */ @@ -212,11 +212,11 @@ Array.prototype.indexAfter = function (element) { /* Javascript 1.8 Array extras, courtesy of Mozilla */ /** - * @desc Apply a function against an accumulator and + * @desc Apply a function against an accumulator and * each value of the array (from left-to-right) as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce */ @@ -266,7 +266,7 @@ Array.prototype.indexAfter = function (element) { * as to reduce it to a single value. * * @param {Function} function - * + * * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/ReduceRight */ @@ -353,7 +353,7 @@ Array.prototype.max = function (salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -374,7 +374,7 @@ Array.prototype.min = function (salient) { } else { var mapper = salient || function (obj) { return obj; } } - + function fn (a, b) { return mapper(a) > mapper(b); } @@ -406,8 +406,8 @@ Array.prototype.sum = function (salient) { } var features = this.map(mapper); - - return features.reduce(function (a, b) { return a + b; }); + + return features.reduce(function (a, b) { return a + b; }); } /** @@ -479,4 +479,14 @@ Array.prototype.last = function () { Array.prototype.contains = function (obj) { return this.indexOf(obj) != -1; -} \ No newline at end of file +} + +Array.prototype.inspect = function(dump) { + return '[' + this.map(function(item) { + return item.inspect ? item.inspect(dump) : item.toString() + }).join(', ') + ']' +} + +Array.prototype.log = function(dump) { + $.writeln(this.inspect(dump)); +} diff --git a/patches/error.jsx b/patches/error.jsx index 84772d3..80b2126 100644 --- a/patches/error.jsx +++ b/patches/error.jsx @@ -1,7 +1,7 @@ /** * @desc This method overloads :func:`Object#is` to combat a problem with some versions of ExtendScript * that leads to all error types being considered the base class Error. This problem makes it impossible to - * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous + * do simple comparisons on errors, for example ``new EvalError() instanceof SyntaxError``. The previous * expression should return false but will return true. * * When testing whether you're dealing with a specific kind of error, use this method, and refrain @@ -35,6 +35,23 @@ Error.prototype.is = function (type) { } } +Error.prototype.toString = function() { + if (typeof this.stack === "undefined" || this.stack === null) { + this.stack = []; + // The previous line is needed because the next line may indirectly call this method. + this.stack = $.stack; + } + return this.formatErrorMessage(); +} + +Error.prototype.formatErrorMessage = function() { + var res = '' + res += this.message + '\n' + res += 'line: ' + this.line + ', file: ' + this.fileName + '\n' + res += this.stack ? this.stack : '' + return res; +} + /** * @desc Use this classmethod to make sure your custom error types work * just like the built-in ones. @@ -165,4 +182,4 @@ if (app.name.to('lower').contains("indesign")) { * @name ValidationError */ ValidationError.prototype._type = ValidationError; -} \ No newline at end of file +} diff --git a/patches/object.jsx b/patches/object.jsx index e484f55..adf67b8 100644 --- a/patches/object.jsx +++ b/patches/object.jsx @@ -1,12 +1,12 @@ -/* - * Patches for functional programming. - * Inspired by and sometimes copied from underscore.js +/* + * Patches for functional programming. + * Inspired by and sometimes copied from underscore.js */ /** * @desc Merge two objects together. This modifies the original object. * First use :func:`Object#clone` on the object if you want to keep the original object intact. - * + * * @param {Object} obj The object to merge into this one. * * @returns {Object} Returns the merged object (``this``); @@ -14,7 +14,7 @@ Object.prototype.merge = function (obj) { if (!obj) return; - + var merged_obj = this; for (var name in obj) { merged_obj[name] = obj[name]; @@ -46,7 +46,7 @@ Object.prototype.clone = function () { /** * @desc * Returns only the keys (also known as 'names') of an object or associative array. - * Will filter out any functions, as these are presumed to be object methods. + * Will filter out any functions, as these are presumed to be object methods. * @returns {Array} An array with all the keys. */ @@ -95,8 +95,8 @@ Object.prototype.is = function(type) { Object.prototype.has = function (key) { // could be just null or an invalid object // either way, has() should return false - if (this == null || this[key] == null) return false; - + if (this == null || this[key] == null) return false; + if (key in this) { return new Boolean(this[key]) != false; } else { @@ -125,10 +125,29 @@ Object.prototype.to_console = function (dump) { if (dump) { var obj = this; var out = obj.reflect.properties.map(function (property) { - return property.name + "\t => " + obj[property.name]; + return property.name + "\t => " + obj[property.name]; }).join("\n"); } else { var out = this.toString(); } return $.writeln(out); -} \ No newline at end of file +} + +Object.prototype.log = function (dump) { + var out = this.inspect(dump); + return $.writeln(out); +} + +Object.prototype.inspect = function(dump) { + if (dump) { + var props = this.keys(); + for (var i = 0; i < props.length; i++) { + var property = props[i]; + props[i] = property + ": " + this[property]; + } + var out = "{" + props.join(", ") + "}"; + } else { + var out = this.toString(); + } + return out; +} diff --git a/settings.jsx b/settings.jsx old mode 100644 new mode 100755