summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2013-11-27 13:15:28 +0200
committerGarren Smith <garren.smith@gmail.com>2013-11-27 13:15:28 +0200
commitd7849ef75723d4b493280003286ce6c6bd850f44 (patch)
treeecaf0581750a6ca52f0cf6e56f303e950a9bc64f
parent753a74816ed1b9f1b7fd1f0604a03c1d862ee590 (diff)
downloadcouchdb-generate-root-from-settings.tar.gz
Clean up app settings gengenerate-root-from-settings
-rw-r--r--src/fauxton/Gruntfile.js13
-rw-r--r--src/fauxton/app/app.js71
-rw-r--r--src/fauxton/app/initialize.js61
-rw-r--r--src/fauxton/app/initialize.js.underscore61
-rw-r--r--src/fauxton/settings.json.default10
-rw-r--r--src/fauxton/tasks/fauxton.js65
6 files changed, 127 insertions, 154 deletions
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 4af5a0023..e7b6cd813 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -325,11 +325,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,
@@ -404,7 +405,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.
@@ -416,12 +417,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
diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js
index ac3c0c449..0a51410ef 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;
});
diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js
index e37435220..7a4a1c187 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;
});
+
diff --git a/src/fauxton/app/initialize.js.underscore b/src/fauxton/app/initialize.js.underscore
index cc0ea582b..02689a11f 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;
});
+
diff --git a/src/fauxton/settings.json.default b/src/fauxton/settings.json.default
index 1b6891170..27cd38fa5 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"
}
}
},
diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js
index f43546c2b..bb68ddb9a 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(){