You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by de...@apache.org on 2013/12/04 21:06:06 UTC

[3/4] git commit: updated refs/heads/master to 1ba9aa3

Clean up app settings gen


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/72c78107
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/72c78107
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/72c78107

Branch: refs/heads/master
Commit: 72c781076216107bf7bb1de6d17853ae0e784efb
Parents: 1ab2408
Author: Garren Smith <ga...@gmail.com>
Authored: Wed Nov 27 13:15:28 2013 +0200
Committer: suelockwood <de...@apache.org>
Committed: Wed Dec 4 14:55:47 2013 -0500

----------------------------------------------------------------------
 src/fauxton/Gruntfile.js                 | 13 ++---
 src/fauxton/app/app.js                   | 71 +++++++++++++++++++--------
 src/fauxton/app/initialize.js            | 61 +++++------------------
 src/fauxton/app/initialize.js.underscore | 61 +++++------------------
 src/fauxton/settings.json.default        | 10 ++++
 src/fauxton/tasks/fauxton.js             | 65 +++++++++++++-----------
 6 files changed, 127 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/Gruntfile.js
----------------------------------------------------------------------
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 5e6c56e..75fcc5d 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -326,11 +326,12 @@ module.exports = function(grunt) {
         src: "settings.json"
       }
     },
-    gen_initialize: {
+    gen_initialize: templateSettings,
+    /*gen_initialize: {
       "default": {
         src: "settings.json"
       }
-    },
+    },*/
 
     mkcouchdb: couch_config,
     rmcouchdb: couch_config,
@@ -405,7 +406,7 @@ module.exports = function(grunt) {
   grunt.registerTask('lint', ['clean', 'jshint']);
   grunt.registerTask('test', ['lint', 'mochaSetup','jst', 'concat:test_config_js', 'mocha_phantomjs']);
   // Fetch dependencies (from git or local dir), lint them and make load_addons
-  grunt.registerTask('dependencies', ['get_deps', 'gen_load_addons:default', "gen_initialize:default"]);
+  grunt.registerTask('dependencies', ['get_deps', 'gen_load_addons:default']);
   // build templates, js and css
   grunt.registerTask('build', ['less', 'concat:index_css', 'jst', 'requirejs', 'concat:requirejs', 'template:release']);
   // minify code and css, ready for release.
@@ -417,12 +418,12 @@ module.exports = function(grunt) {
   // dev server
   grunt.registerTask('dev', ['debugDev', 'couchserver']);
   // build a debug release
-  grunt.registerTask('debug', ['lint', 'dependencies', 'concat:requirejs','less', 'concat:index_css', 'template:development', 'copy:debug']);
-  grunt.registerTask('debugDev', ['clean', 'dependencies','jshint','less', 'concat:index_css', 'template:development', 'copy:debug']);
+  grunt.registerTask('debug', ['lint', 'dependencies', "gen_initialize:development", 'concat:requirejs','less', 'concat:index_css', 'template:development', 'copy:debug']);
+  grunt.registerTask('debugDev', ['clean', 'dependencies', "gen_initialize:development",'jshint','less', 'concat:index_css', 'template:development', 'copy:debug']);
 
   grunt.registerTask('watchRun', ['clean:watch', 'dependencies', 'jshint']);
   // build a release
-  grunt.registerTask('release', ['clean' ,'dependencies','jshint', 'build', 'minify', 'copy:dist']);
+  grunt.registerTask('release', ['clean' ,'dependencies', "gen_initialize:release", 'jshint', 'build', 'minify', 'copy:dist']);
 
   /*
    * Install into CouchDB in either debug, release, or couchapp mode

http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/app/app.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js
index ac3c0c4..0a51410 100644
--- a/src/fauxton/app/app.js
+++ b/src/fauxton/app/app.js
@@ -11,22 +11,27 @@
 // the License.
 
 define([
-  // Libraries.
+  // Application.
+  "initialize",
+
+  // Libraries
   "jquery",
   "lodash",
   "backbone",
+  "bootstrap",
 
   "helpers",
   "mixins",
 
-  // Plugins.
+   // Plugins.
   "plugins/backbone.layoutmanager",
   "plugins/jquery.form"
+
 ],
 
-function($, _, Backbone, Helpers, Mixins) {
+function(app, $, _, Backbone, Bootstrap, Helpers, Mixins) {
 
-  // Make sure we have a console.log
+   // Make sure we have a console.log
   if (typeof console == "undefined") {
     console = {
       log: function(){}
@@ -34,17 +39,47 @@ function($, _, Backbone, Helpers, Mixins) {
   }
 
   // Provide a global location to place configuration settings and module
-  // creation.
-  var app = {
-    // The root path to run the application.
-    root: "/",
-    version: "0.0.1",
+  // creation also mix in Backbone.Events
+  _.extend(app, Backbone.Events, {
     mixins: Mixins,
-    // move this to here otherwise every once in a while,
-    // the footer fails to configure as the url for it is not configured.
-    // Having the host declared here fixes it
-    host: window.location.protocol + "//" + window.location.host,
-  };
+
+    renderView: function(baseView, selector, view, options, callback) {
+      baseView.setView(selector, new view(options)).render().then(callback);
+    },
+
+    // Create a custom object with a nested Views object.
+    module: function(additionalProps) {
+      return _.extend({ Views: {} }, additionalProps);
+    },
+
+    // Thanks to: http://stackoverflow.com/a/2880929
+    getParams: function(queryString) {
+      if (queryString) {
+        // I think this could be combined into one if
+        if (queryString.substring(0,1) === "?") {
+          queryString = queryString.substring(1);
+        } else if (queryString.indexOf('?') > -1) {
+          queryString = queryString.split('?')[1];
+        }
+      }
+      var hash = window.location.hash.split('?')[1];
+      queryString = queryString || hash || window.location.search.substring(1);
+      var match,
+      urlParams = {},
+      pl     = /\+/g,  // Regex for replacing addition symbol with a space
+      search = /([^&=]+)=?([^&]*)/g,
+      decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
+      query  = queryString;
+
+      if (queryString) {
+        while ((match = search.exec(query))) {
+          urlParams[decode(match[1])] = decode(match[2]);
+        }
+      }
+
+      return urlParams;
+    }
+  });
 
   // Localize or create a new JavaScript Template object.
   var JST = window.JST = window.JST || {};
@@ -82,12 +117,6 @@ function($, _, Backbone, Helpers, Mixins) {
     }
   });
 
-  // Mix Backbone.Events, and modules into the app object.
-  return _.extend(app, {
-    // Create a custom object with a nested Views object.
-    module: function(additionalProps) {
-      return _.extend({ Views: {} }, additionalProps);
-    }
-  }, Backbone.Events);
 
+  return app;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/app/initialize.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js
index e374352..7a4a1c1 100644
--- a/src/fauxton/app/initialize.js
+++ b/src/fauxton/app/initialize.js
@@ -10,61 +10,24 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-
 /*
  * ::WARNING::
  * THIS IS A GENERATED FILE. DO NOT EDIT.
  */
 
-define([
-  // Application.
-  "app",
-
-  // Libraries
-  "lodash",
-  "bootstrap"
-],
-
-function(app, _, Bootstrap) {
 
+define([],
+function() {
   // Provide a global location to place configuration settings and module
   // creation.
-  _.extend(app, {
-    // The root path to run the application through.
-    // TODO: pick this up wither at build time or from the browser
-    root: "/dashboard.beta/dashboard.assets/",
-
-    renderView: function(baseView, selector, view, options, callback) {
-      baseView.setView(selector, new view(options)).render().then(callback);
-    },
-
-    // Thanks to: http://stackoverflow.com/a/2880929
-    getParams: function(queryString) {
-      if (queryString) {
-        // I think this could be combined into one if
-        if (queryString.substring(0,1) === "?") {
-          queryString = queryString.substring(1);
-        } else if (queryString.indexOf('?') > -1) {
-          queryString = queryString.split('?')[1];
-        }
-      }
-      var hash = window.location.hash.split('?')[1];
-      queryString = queryString || hash || window.location.search.substring(1);
-      var match,
-      urlParams = {},
-      pl     = /\+/g,  // Regex for replacing addition symbol with a space
-      search = /([^&=]+)=?([^&]*)/g,
-      decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
-      query  = queryString;
-
-      if (queryString) {
-        while ((match = search.exec(query))) {
-          urlParams[decode(match[1])] = decode(match[2]);
-        }
-      }
-
-      return urlParams;
-    }
-  });
-
+  var app = {
+    // The root path to run the application.
+    root: "/utils/fauxton/",
+    version: "1.0",
+    // Host is used as prefix for urls
+    host: "../.." ,
+  };
+
+  return app; 
 });
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/app/initialize.js.underscore
----------------------------------------------------------------------
diff --git a/src/fauxton/app/initialize.js.underscore b/src/fauxton/app/initialize.js.underscore
index cc0ea58..02689a1 100644
--- a/src/fauxton/app/initialize.js.underscore
+++ b/src/fauxton/app/initialize.js.underscore
@@ -10,61 +10,24 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-
 /*
  * ::WARNING::
  * THIS IS A GENERATED FILE. DO NOT EDIT.
  */
 
-define([
-  // Application.
-  "app",
-
-  // Libraries
-  "lodash",
-  "bootstrap"
-],
-
-function(app, _, Bootstrap) {
 
+define([],
+function() {
   // Provide a global location to place configuration settings and module
   // creation.
-  _.extend(app, {
-    // The root path to run the application through.
-    // TODO: pick this up wither at build time or from the browser
-    root: <%= '"' +root+ '"' %>,
-
-    renderView: function(baseView, selector, view, options, callback) {
-      baseView.setView(selector, new view(options)).render().then(callback);
-    },
-
-    // Thanks to: http://stackoverflow.com/a/2880929
-    getParams: function(queryString) {
-      if (queryString) {
-        // I think this could be combined into one if
-        if (queryString.substring(0,1) === "?") {
-          queryString = queryString.substring(1);
-        } else if (queryString.indexOf('?') > -1) {
-          queryString = queryString.split('?')[1];
-        }
-      }
-      var hash = window.location.hash.split('?')[1];
-      queryString = queryString || hash || window.location.search.substring(1);
-      var match,
-      urlParams = {},
-      pl     = /\+/g,  // Regex for replacing addition symbol with a space
-      search = /([^&=]+)=?([^&]*)/g,
-      decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
-      query  = queryString;
-
-      if (queryString) {
-        while ((match = search.exec(query))) {
-          urlParams[decode(match[1])] = decode(match[2]);
-        }
-      }
-
-      return urlParams;
-    }
-  });
-
+  var app = {
+    // The root path to run the application.
+    root: "<%= root %>",
+    version: "<%= version %>",
+    // Host is used as prefix for urls
+    host: "<%= host %>" ,
+  };
+
+  return app; 
 });
+

http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/settings.json.default
----------------------------------------------------------------------
diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default
index 1b68911..27cd38f 100644
--- a/src/fauxton/settings.json.default
+++ b/src/fauxton/settings.json.default
@@ -20,6 +20,11 @@
           "requirejs": "/assets/js/libs/require.js",
           "css": "./css/index.css",
           "base": null
+        },
+        "app": {
+          "root": "/",
+          "host": "../..",
+          "version": "1.0.dev"
         }
       },
       "release": {
@@ -29,6 +34,11 @@
           "requirejs": "./js/require.js",
           "css": "./css/index.css",
           "base": null
+        },
+        "app": {
+          "root": "/utils/fauxton/",
+          "host": "../..",
+          "version": "1.0"
         }
       }
     },

http://git-wip-us.apache.org/repos/asf/couchdb/blob/72c78107/src/fauxton/tasks/fauxton.js
----------------------------------------------------------------------
diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js
index f43546c..bb68ddb 100644
--- a/src/fauxton/tasks/fauxton.js
+++ b/src/fauxton/tasks/fauxton.js
@@ -14,9 +14,10 @@ module.exports = function(grunt) {
   var _ = grunt.util._;
 
   grunt.registerMultiTask('template', 'generates an html file from a specified template', function(){
-    var data = this.data;
-    var _ = grunt.util._;
-    var tmpl = _.template(grunt.file.read(data.src), null, data.variables);
+    var data = this.data,
+        _ = grunt.util._,
+        tmpl = _.template(grunt.file.read(data.src), null, data.variables);
+
     grunt.file.write(data.dest, tmpl(data.variables));
   });
 
@@ -24,12 +25,12 @@ module.exports = function(grunt) {
     grunt.log.writeln("Fetching external dependencies");
 
     var path = require('path');
-    var done = this.async();
-    var data = this.data;
-    var target = data.target || "app/addons/";
-    var settingsFile = path.existsSync(data.src) ? data.src : "settings.json.default";
-    var settings = grunt.file.readJSON(settingsFile);
-    var _ = grunt.util._;
+        done = this.async(),
+        data = this.data,
+        target = data.target || "app/addons/",
+        settingsFile = path.existsSync(data.src) ? data.src : "settings.json.default",
+        settings = grunt.file.readJSON(settingsFile),
+        _ = grunt.util._;
 
     // This should probably be a helper, though they seem to have been removed
     var fetch = function(deps, command){
@@ -76,30 +77,36 @@ module.exports = function(grunt) {
 
   grunt.registerMultiTask('gen_load_addons', 'Generate the load_addons.js file', function() {
     var path = require('path');
-    var data = this.data;
-    var _ = grunt.util._;
-    var settingsFile = path.existsSync(data.src) ? data.src : "settings.json.default";
-    var settings = grunt.file.readJSON(settingsFile);
-    var template = "app/load_addons.js.underscore";
-    var dest = "app/load_addons.js";
-    var deps = _.map(settings.deps, function(dep) {
-      return "addons/" + dep.name + "/base";
-    });
+        data = this.data,
+        _ = grunt.util._,
+        settingsFile = path.existsSync(data.src) ? data.src : "settings.json.default",
+        settings = grunt.file.readJSON(settingsFile),
+        template = "app/load_addons.js.underscore",
+        dest = "app/load_addons.js",
+        deps = _.map(settings.deps, function(dep) {
+          return "addons/" + dep.name + "/base";
+        });
+
     var tmpl = _.template(grunt.file.read(template));
     grunt.file.write(dest, tmpl({deps: deps}));
   });
 
-  grunt.registerMultiTask('gen_initialize', 'Generate the initialize.js file', function() {
-    var path = require('path');
-    var data = this.data;
-    var _ = grunt.util._;
-    var settingsFile = path.existsSync(data.src) ? data.src : "settings.json.default";
-    var settings = grunt.file.readJSON(settingsFile);
-    var template = "app/initialize.js.underscore";
-    var dest = "app/initialize.js";
-    var root = settings.root || "/";
-    var tmpl = _.template(grunt.file.read(template));
-    grunt.file.write(dest, tmpl({root: root}));
+  grunt.registerMultiTask('gen_initialize', 'Generate the app.js file', function() {
+    var _ = grunt.util._,
+        settings = this.data,
+        template = "app/initialize.js.underscore",
+        dest = "app/initialize.js"
+        tmpl = _.template(grunt.file.read(template)),
+        app = {};
+      
+
+    _.defaults(app, settings.app, {
+      root: '/',
+      host: '../../',
+      version: "0.0"
+    });
+
+    grunt.file.write(dest, tmpl(app));
   });
 
   grunt.registerMultiTask('mochaSetup','Generate a config.js and runner.html for tests', function(){