summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuelockwood <deathbearbrown@gmail.com>2013-11-26 14:20:00 -0500
committersuelockwood <deathbearbrown@gmail.com>2013-11-26 14:20:00 -0500
commitc1188d83adf890b0bd31c59d125bf082b21efb63 (patch)
tree48de77cfb68809a96765d6345356ddf2e55d5134
parent4e57f8fd1c8cf788e994cc332bc915d2c11d8c1b (diff)
downloadcouchdb-c1188d83adf890b0bd31c59d125bf082b21efb63.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 42e5e17aa..4af5a0023 100644
--- a/src/fauxton/Gruntfile.js
+++ b/src/fauxton/Gruntfile.js
@@ -325,6 +325,11 @@ module.exports = function(grunt) {
src: "settings.json"
}
},
+ gen_initialize: {
+ "default": {
+ src: "settings.json"
+ }
+ },
mkcouchdb: couch_config,
rmcouchdb: couch_config,
@@ -399,7 +404,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,