summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuelockwood <deathbearbrown@gmail.com>2013-11-26 14:20:00 -0500
committersuelockwood <deathbear@apache.org>2013-12-04 14:55:46 -0500
commitb153e6af50421c61e08e4027f4ca842ed78d76c9 (patch)
tree4e49d775341ac2d7079ee02019d54a192563a9bb
parentf5a5862a72214d292ccf5b61159bd10dedf5faff (diff)
downloadcouchdb-b153e6af50421c61e08e4027f4ca842ed78d76c9.tar.gz
Adding the initialize task to be able to set app.root
-rw-r--r--src/fauxton/Gruntfile.js7
-rw-r--r--src/fauxton/app/initialize.js9
-rw-r--r--src/fauxton/app/initialize.js.underscore70
-rw-r--r--src/fauxton/tasks/fauxton.js13
4 files changed, 96 insertions, 3 deletions
diff --git a/src/fauxton/Gruntfile.js b/src/fauxton/Gruntfile.js
index 6a8a73a5b..5e6c56e51 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -326,6 +326,11 @@ module.exports = function(grunt) {
src: "settings.json"
}
},
+ gen_initialize: {
+ "default": {
+ src: "settings.json"
+ }
+ },
mkcouchdb: couch_config,
rmcouchdb: couch_config,
@@ -400,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']);
+ grunt.registerTask('dependencies', ['get_deps', 'gen_load_addons:default', "gen_initialize: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.
diff --git a/src/fauxton/app/initialize.js b/src/fauxton/app/initialize.js
index c0cca4446..e37435220 100644
--- a/src/fauxton/app/initialize.js
+++ b/src/fauxton/app/initialize.js
@@ -10,6 +10,12 @@
// License for the specific language governing permissions and limitations under
// the License.
+
+/*
+ * ::WARNING::
+ * THIS IS A GENERATED FILE. DO NOT EDIT.
+ */
+
define([
// Application.
"app",
@@ -26,8 +32,7 @@ function(app, _, Bootstrap) {
_.extend(app, {
// The root path to run the application through.
// TODO: pick this up wither at build time or from the browser
- root: "/_utils/fauxton/",
-
+ root: "/dashboard.beta/dashboard.assets/",
renderView: function(baseView, selector, view, options, callback) {
baseView.setView(selector, new view(options)).render().then(callback);
diff --git a/src/fauxton/app/initialize.js.underscore b/src/fauxton/app/initialize.js.underscore
new file mode 100644
index 000000000..cc0ea582b
--- /dev/null
+++ b/src/fauxton/app/initialize.js.underscore
@@ -0,0 +1,70 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// 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) {
+
+ // 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;
+ }
+ });
+
+});
diff --git a/src/fauxton/tasks/fauxton.js b/src/fauxton/tasks/fauxton.js
index 833a86d2b..e466c9f92 100644
--- a/src/fauxton/tasks/fauxton.js
+++ b/src/fauxton/tasks/fauxton.js
@@ -89,6 +89,19 @@ module.exports = function(grunt) {
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('mochaSetup','Generate a config.js and runner.html for tests', function(){
var data = this.data,
configInfo,