From 4f0222f8123d6768220543aeb04e56c15e0d005a Mon Sep 17 00:00:00 2001 From: Doug Fritz Date: Sun, 14 Sep 2014 19:48:00 -0700 Subject: [PATCH] automated style formatting on save of all js files and updated gulp build --- .editorconfig | 2 +- .jscsrc | 44 --- TODO.md | 2 + bower.json | 5 + build/dat-gui.html | 12 +- build/dat-gui.js | 14 +- build/{gui.shim.js => dat-gui.shim.js} | 0 docs/style.styl | 1 - docs/template.html | 4 +- elements/Gui.js | 367 ++++++++++---------- elements/dat-gui-base/dat-gui-base.js | 6 +- elements/dat-gui-boolean/dat-gui-boolean.js | 4 +- elements/dat-gui-number/dat-gui-number.js | 8 +- elements/dat-gui-option/dat-gui-option.js | 14 +- elements/dat-gui-string/dat-gui-string.js | 2 +- elements/dat-gui/dat-gui.js | 2 +- elements/gui-row/gui-row.js | 4 +- elements/shared.css | 0 elements/shim.js | 42 +-- examples/index.html | 5 +- gulpfile.js | 296 ++++++++++------ index.html | 161 ++++----- package.json | 19 +- 23 files changed, 524 insertions(+), 490 deletions(-) delete mode 100644 .jscsrc mode change 100644 => 100755 build/dat-gui.html mode change 100644 => 100755 build/dat-gui.js rename build/{gui.shim.js => dat-gui.shim.js} (100%) delete mode 100644 elements/shared.css diff --git a/.editorconfig b/.editorconfig index 449e280..46940b2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -[*.js] +[*] indent_style = space indent_size = 4 diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 9d3e3ca..0000000 --- a/.jscsrc +++ /dev/null @@ -1,44 +0,0 @@ -{ - - "fileExtensions": [".js", ".json"], - "excludeFiles": ["node_modules/**", "build/**"], - - "maximumLineLength": 120, - "validateLineBreaks": "LF", - "validateIndentation": 4, - - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - - "requireSpaceBeforeBlockStatements": true, - - "requireSpacesInConditionalExpression": { - "afterTest": true, - "beforeConsequent": true, - "afterConsequent": true, - "beforeAlternate": true - }, - - "requireSpacesInsideParentheses": "all", - "requireSpacesInsideObjectBrackets": "all", - "requireSpacesInsideArrayBrackets": "all", - - "requireParenthesesAroundIIFE": true, - - "disallowSpacesInFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - - "disallowKeywords": ["with"], - "disallowImplicitTypeConversion": ["string"] - -} \ No newline at end of file diff --git a/TODO.md b/TODO.md index 20b042d..f74c592 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,7 @@ BUILD - [x] single import - [x] browsersync +- [ ] remove platform, dependent on fix of bug in gulp-vulcanize REFACTOR @@ -9,6 +10,7 @@ REFACTOR - [ ] Gui.js => gui-panel => dat-gui - [x] controller-* => dat-gui-* - [x] kill strict +- [x] Reorg gulpfile and add standardized formatting PARITY diff --git a/bower.json b/bower.json index 47997b5..07a7c6a 100644 --- a/bower.json +++ b/bower.json @@ -20,5 +20,10 @@ "dependencies": { "polymer": "Polymer/polymer#>=0.4.0", "platform": "Polymer/platform#>=0.4.0" + }, + "resolutions": { + "core-action-icons": "0.2.4", + "platform": ">=0.4.0 <1.0.0", + "core-component-page": ">=0.4.0 <1.0.0" } } diff --git a/build/dat-gui.html b/build/dat-gui.html old mode 100644 new mode 100755 index cd99885..c606ccf --- a/build/dat-gui.html +++ b/build/dat-gui.html @@ -1,9 +1,13 @@ + - + diff --git a/build/dat-gui.js b/build/dat-gui.js old mode 100644 new mode 100755 index 447ac2b..ded74ce --- a/build/dat-gui.js +++ b/build/dat-gui.js @@ -1,9 +1,13 @@ -document.write(['', +document.write(['', +'', '', -'', +'', '', '', '', diff --git a/build/gui.shim.js b/build/dat-gui.shim.js similarity index 100% rename from build/gui.shim.js rename to build/dat-gui.shim.js diff --git a/docs/style.styl b/docs/style.styl index 1a362b6..f268f22 100644 --- a/docs/style.styl +++ b/docs/style.styl @@ -28,7 +28,6 @@ h1 margin-bottom unit * 3 h3 - padding unit 0 margin-bottom unit * 2 diff --git a/docs/template.html b/docs/template.html index c081189..6723db3 100644 --- a/docs/template.html +++ b/docs/template.html @@ -15,7 +15,9 @@ -
+
+ <%= contents %> +
diff --git a/elements/Gui.js b/elements/Gui.js index 9a8c7e1..2710c99 100644 --- a/elements/Gui.js +++ b/elements/Gui.js @@ -1,234 +1,231 @@ ( function( scope ) { - /* globals Path */ +/* globals Path */ - var Gui = function( params ) { +var Gui = function( params ) { - if ( !ready ) { - Gui.error( 'Gui not ready. Put your code inside Gui.ready()' ); - } + if ( !ready ) { + Gui.error( 'Gui not ready. Put your code inside Gui.ready()' ); + } - params = params || {}; + params = params || {}; - // Properties + // Properties - this.vars = {}; - this.localStorage = params.localStorage || false; + this.vars = {}; + this.localStorage = params.localStorage || false; - // Make domElement + // Make domElement - this.panel = document.createElement( 'dat-gui' ); - this.panel.autoPlace = params.autoPlace !== false; + this.panel = document.createElement( 'dat-gui' ); + this.panel.autoPlace = params.autoPlace !== false; - if ( this.panel.autoPlace ) { - document.body.appendChild( this.panel ); - } + if ( this.panel.autoPlace ) { + document.body.appendChild( this.panel ); + } +}; + + +// Instance methods +// ------------------------------- + +Gui.prototype.add = function( object, path ) { + + // Make controller + + var value = Path.get( path ).getValueFrom( object ); + + if ( value === null || value === undefined ) { + return Gui.error( object + ' doesn\'t have a value for path "' + path + '".' ); + } + + var args = Array.prototype.slice.call( arguments, 2 ); + var controller; + + if ( args[ 0 ] instanceof Array || typeof args[ 0 ] == 'object' ) { + controller = document.createElement( 'dat-gui-option' ); + } else { + controller = Gui.getController( value ); + } + + if ( !controller ) { + return Gui.error( 'Unrecognized type:', value ); + } + + controller.watch( object, path ); + controller.init.apply( controller, args ); + + // Make row + + var row = document.createElement( 'gui-row' ); + row.name = path; + + controller.row = row; + + controller.name = function( name ) { + row.name = name; }; - - // Instance methods - // ------------------------------- - - Gui.prototype.add = function( object, path ) { - - // Make controller - - var value = Path.get( path ).getValueFrom( object ); - - if ( value === null || value === undefined ) { - return Gui.error( object + ' doesn\'t have a value for path "' + path + '".' ); - } - - var args = Array.prototype.slice.call( arguments, 2 ); - var controller; - - if ( args[ 0 ] instanceof Array || typeof args[ 0 ] == 'object' ) { - controller = document.createElement( 'dat-gui-option' ); - } else { - controller = Gui.getController( value ); - } - - if ( !controller ) { - return Gui.error( 'Unrecognized type:', value ); - } - - controller.watch( object, path ); - controller.init.apply( controller, args ); - - // Make row - - var row = document.createElement( 'gui-row' ); - row.name = path; - - controller.row = row; - - controller.name = function( name ) { - row.name = name; - }; - - controller.comment = function( comment ) { - row.comment = comment; - }; - - row.appendChild( controller ); - this.panel.appendChild( row ); - - return controller; - + controller.comment = function( comment ) { + row.comment = comment; }; - Gui.prototype.remember = function( object ) { + row.appendChild( controller ); + this.panel.appendChild( row ); + return controller; - }; +}; - Gui.prototype.var = function() { +Gui.prototype.remember = function( object ) {}; - var name, initialValue, args; +Gui.prototype.var = function() { - if ( arguments.length == 1 ) { - name = arguments[ 0 ]; - return this.vars[ name ]; - } + var name, initialValue, args; - initialValue = arguments[ 1 ]; + if ( arguments.length == 1 ) { name = arguments[ 0 ]; + return this.vars[ name ]; + } - args = [ this.vars, name ]; - args = args.concat( Array.prototype.slice.call( arguments, 2 ) ); + initialValue = arguments[ 1 ]; + name = arguments[ 0 ]; - this.vars[ name ] = initialValue; + args = [ this.vars, name ]; + args = args.concat( Array.prototype.slice.call( arguments, 2 ) ); - return this.add.apply( this, args ); + this.vars[ name ] = initialValue; - }; + return this.add.apply( this, args ); - Gui.prototype.listenAll = function() { +}; - Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' ); +Gui.prototype.listenAll = function() { - }; + Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' ); + +}; - // Register custom controllers - // ------------------------------- +// Register custom controllers +// ------------------------------- - var controllers = {}; +var controllers = {}; - Gui.register = function( elementName, test ) { +Gui.register = function( elementName, test ) { - controllers[ elementName ] = test; + controllers[ elementName ] = test; - }; +}; - // Returns a controller based on a value - // ------------------------------- +// Returns a controller based on a value +// ------------------------------- - Gui.getController = function( value ) { +Gui.getController = function( value ) { - for ( var type in controllers ) { + for ( var type in controllers ) { - var test = controllers[ type ]; + var test = controllers[ type ]; - if ( test( value ) ) { + if ( test( value ) ) { - return document.createElement( type ); - - } + return document.createElement( type ); } - }; - - - // Gui ready handler ... * shakes fist at polymer * - // ------------------------------- - - var ready = false; - var readyHandlers = []; - - document.addEventListener( 'polymer-ready', function() { - - ready = true; - readyHandlers.forEach( function( fnc ) { - - fnc(); - - } ); - - } ); - - Gui.ready = function( fnc ) { - - if ( ready ) { - fnc(); - } else { - readyHandlers.push( fnc ); - } - - }; - - - // Console - // ------------------------------- - - Gui.error = function() { - var args = Array.prototype.slice.apply( arguments ); - args.unshift( 'dat-gui ::' ); - console.error.apply( console, args ); - }; - - Gui.warn = function() { - var args = Array.prototype.slice.apply( arguments ); - args.unshift( 'dat-gui ::' ); - console.warn.apply( console, args ); - }; - - - // Old namespaces - // ------------------------------- - - var dat = {}; - - dat.gui = {}; - dat.gui.GUI = Gui; - dat.GUI = dat.gui.GUI; - - dat.color = {}; - dat.color.Color = function() {}; - - dat.dom = {}; - dat.dom.dom = function() {}; - - dat.controllers = {}; - dat.controllers.Controller = constructor( 'dat-gui-base' ); - dat.controllers.NumberController = constructor( 'dat-gui-number' ); - dat.controllers.FunctionController = constructor( 'dat-gui-function' ); - dat.controllers.ColorController = constructor( 'dat-gui-color' ); - dat.controllers.BooleanController = constructor( 'dat-gui-boolean' ); - dat.controllers.OptionController = constructor( 'dat-gui-option' ); - - dat.controllers.NumberControllerBox = dat.controllers.NumberController; - dat.controllers.NumberControllerSlider = dat.controllers.NumberController; - - function constructor( elementName ) { - - return function( object, path ) { - var el = document.createElement( elementName ); - el.watch( object, path ); - return el; - }; - } - - // Export - // ------------------------------- - - scope.dat = dat; - scope.Gui = Gui; +}; -} )( this ); +// Gui ready handler ... * shakes fist at polymer * +// ------------------------------- + +var ready = false; +var readyHandlers = []; + +document.addEventListener( 'polymer-ready', function() { + + ready = true; + readyHandlers.forEach( function( fnc ) { + + fnc(); + + } ); + +} ); + +Gui.ready = function( fnc ) { + + if ( ready ) { + fnc(); + } else { + readyHandlers.push( fnc ); + } + +}; + + +// Console +// ------------------------------- + +Gui.error = function() { + var args = Array.prototype.slice.apply( arguments ); + args.unshift( 'dat-gui ::' ); + console.error.apply( console, args ); +}; + +Gui.warn = function() { + var args = Array.prototype.slice.apply( arguments ); + args.unshift( 'dat-gui ::' ); + console.warn.apply( console, args ); +}; + + +// Old namespaces +// ------------------------------- + +var dat = {}; + +dat.gui = {}; +dat.gui.GUI = Gui; +dat.GUI = dat.gui.GUI; + +dat.color = {}; +dat.color.Color = function() {}; + +dat.dom = {}; +dat.dom.dom = function() {}; + +dat.controllers = {}; +dat.controllers.Controller = constructor( 'dat-gui-base' ); +dat.controllers.NumberController = constructor( 'dat-gui-number' ); +dat.controllers.FunctionController = constructor( 'dat-gui-function' ); +dat.controllers.ColorController = constructor( 'dat-gui-color' ); +dat.controllers.BooleanController = constructor( 'dat-gui-boolean' ); +dat.controllers.OptionController = constructor( 'dat-gui-option' ); + +dat.controllers.NumberControllerBox = dat.controllers.NumberController; +dat.controllers.NumberControllerSlider = dat.controllers.NumberController; + +function constructor( elementName ) { + + return function( object, path ) { + var el = document.createElement( elementName ); + el.watch( object, path ); + return el; + }; + +} + + +// Export +// ------------------------------- + +scope.dat = dat; +scope.Gui = Gui; + + +})( this ); diff --git a/elements/dat-gui-base/dat-gui-base.js b/elements/dat-gui-base/dat-gui-base.js index 1022fdd..2cf489c 100644 --- a/elements/dat-gui-base/dat-gui-base.js +++ b/elements/dat-gui-base/dat-gui-base.js @@ -47,7 +47,7 @@ Polymer( 'dat-gui-base', { map: function( x, a, b, c, d ) { return ( x - a ) / ( b - a ) * ( d - c ) + c; }, - + // Legacy // ------------------------------- @@ -55,7 +55,7 @@ Polymer( 'dat-gui-base', { listen: function() { Gui.warn( 'controller.listen() is deprecated. All controllers are listened for free.' ); - + return this; }, @@ -76,7 +76,7 @@ Polymer( 'dat-gui-base', { onChange: function( v ) { this.addEventListener( 'change', function( e ) { - + v( e.detail ); } ); diff --git a/elements/dat-gui-boolean/dat-gui-boolean.js b/elements/dat-gui-boolean/dat-gui-boolean.js index f587614..6da720f 100644 --- a/elements/dat-gui-boolean/dat-gui-boolean.js +++ b/elements/dat-gui-boolean/dat-gui-boolean.js @@ -9,9 +9,7 @@ Gui.register( 'dat-gui-boolean', function( value ) { Polymer( 'dat-gui-boolean', { - ready: function() { - - }, + ready: function() {}, toggle: function() { diff --git a/elements/dat-gui-number/dat-gui-number.js b/elements/dat-gui-number/dat-gui-number.js index 27f4d1d..0f3e7aa 100644 --- a/elements/dat-gui-number/dat-gui-number.js +++ b/elements/dat-gui-number/dat-gui-number.js @@ -158,7 +158,9 @@ Polymer( 'dat-gui-number', { e.preventDefault(); this._rect = this.$.track.getBoundingClientRect(); - if ( !this._alt ) { this.value = this.valueFromX( e.x ); } + if ( !this._alt ) { + this.value = this.valueFromX( e.x ); + } this.fire( 'sliderDown' ); @@ -184,7 +186,9 @@ Polymer( 'dat-gui-number', { var dv = this.valueFromDX( e.ddx ); - if ( this._alt ) { dv /= 10; } + if ( this._alt ) { + dv /= 10; + } this.value += dv * this._dragFriction; diff --git a/elements/dat-gui-option/dat-gui-option.js b/elements/dat-gui-option/dat-gui-option.js index dde1ea2..66e12e7 100644 --- a/elements/dat-gui-option/dat-gui-option.js +++ b/elements/dat-gui-option/dat-gui-option.js @@ -6,7 +6,7 @@ Polymer( 'dat-gui-option', { key: null, ready: function() { - + this.options = {}; }, @@ -22,7 +22,7 @@ Polymer( 'dat-gui-option', { }, this ); } else { - + this.options = options; } @@ -30,7 +30,7 @@ Polymer( 'dat-gui-option', { }, valueChanged: function() { - + for ( var i in this.options ) { if ( this.options[ i ] === this.value ) { this.key = i; @@ -39,7 +39,7 @@ Polymer( 'dat-gui-option', { } this.super(); - + }, keyChanged: function() { @@ -51,12 +51,12 @@ Polymer( 'dat-gui-option', { keys: function( object ) { if ( object ) { - + return Object.keys( object ); - + } } - + } ); diff --git a/elements/dat-gui-string/dat-gui-string.js b/elements/dat-gui-string/dat-gui-string.js index 7e1d671..f371a36 100644 --- a/elements/dat-gui-string/dat-gui-string.js +++ b/elements/dat-gui-string/dat-gui-string.js @@ -20,7 +20,7 @@ Polymer( 'dat-gui-string', { if ( e.keyCode == 13 ) { this.$.input.blur(); - + } } diff --git a/elements/dat-gui/dat-gui.js b/elements/dat-gui/dat-gui.js index 8fafd3d..44847a5 100644 --- a/elements/dat-gui/dat-gui.js +++ b/elements/dat-gui/dat-gui.js @@ -9,7 +9,7 @@ Polymer( 'dat-gui', { open: true, touch: ( 'ontouchstart' in window ) || ( !!window.DocumentTouch && document instanceof window.DocumentTouch ), - + // Observers // ------------------------------- diff --git a/elements/gui-row/gui-row.js b/elements/gui-row/gui-row.js index 6cb7159..e2433f9 100644 --- a/elements/gui-row/gui-row.js +++ b/elements/gui-row/gui-row.js @@ -5,9 +5,7 @@ Polymer( 'gui-row', { comment: null, commentOpen: false, - ready: function() { - - }, + ready: function() {}, openComment: function() { this.commentOpen = true; diff --git a/elements/shared.css b/elements/shared.css deleted file mode 100644 index e69de29..0000000 diff --git a/elements/shim.js b/elements/shim.js index 0fdcb44..928d3e0 100644 --- a/elements/shim.js +++ b/elements/shim.js @@ -1,38 +1,40 @@ // Use gui.shim.js in production when you want to use dat.gui to recall values without any of the interface. ( function( scope ) { - 'use strict'; +'use strict'; - var Gui = function() { +var Gui = function() { - this.vars = {}; + this.vars = {}; - }; +}; - Gui.ready = function( fnc ) { +Gui.ready = function( fnc ) { - fnc(); + fnc(); - }; +}; - Gui.prototype.var = function( name, value ) { +Gui.prototype.var = function( name, value ) { - this.vars[ name ] = value; - return controllerShim; + this.vars[ name ] = value; + return controllerShim; - }; +}; - Gui.prototype.add = function( object, path ) { +Gui.prototype.add = function( object, path ) { - return controllerShim; + return controllerShim; - }; +}; - var identity = function() { return this; }; +var identity = function() { + return this; +}; - var controllerShim = { - on: identity - }; +var controllerShim = { + on: identity +}; - scope.Gui = Gui; +scope.Gui = Gui; -} )( this ); +})( this ); diff --git a/examples/index.html b/examples/index.html index 8a22c48..b58a1b6 100644 --- a/examples/index.html +++ b/examples/index.html @@ -7,7 +7,7 @@ @@ -25,6 +25,7 @@ body content. "\n' ) ) + // must use the latest version of gulp-vulcanize otherwise it grabs the file from disk + .pipe( $.insert.prepend( '\n' ) ) .pipe( $.vulcanize( { dest: 'build', inline: true, strip: true } ) ) - // clean up some vulcanize ... - .pipe( $.replace( /\n\n/gm, '' ) ) - .pipe( $.replace( //gm, '' ) ) - .pipe( $.replace( /^