Permalink
Browse files

Fix ClientSide variable inside payload, add jsonify script and expose…

… vendor folder
  • Loading branch information...
1 parent 15c568d commit d15da4cf6f7df3d2068d0f91cadd4fdcda3699ad Jelle De Loecker committed Dec 4, 2013
Showing with 46 additions and 18 deletions.
  1. +15 −10 lib/hawkejs-client.js
  2. +5 −2 lib/hawkejs-server.js
  3. +3 −3 lib/hawkejs.js
  4. +3 −3 lib/helpers.js
  5. +20 −0 vendor/jsonify.js
View
@@ -3,17 +3,22 @@ window.hawkejs = (function(){
var ClientSide = true;
function require(p){
- if ('fs' == p) return {};
+
+ if ('fs' == p) return {};
if ('cheerio' == p) return {};
- var path = require.resolve(p)
- , mod = require.modules[path];
- if (!mod) throw new Error('failed to require "' + p + '"');
- if (!mod.exports) {
- mod.exports = {};
- mod.call(mod.exports, mod, mod.exports, require.relative(path));
- }
- return mod.exports;
- }
+
+ var path = require.resolve(p),
+ mod = require.modules[path];
+
+ if (!mod) throw new Error('failed to require "' + p + '"');
+
+ if (!mod.exports) {
+ mod.exports = {};
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
+ }
+
+ return mod.exports;
+ }
require.modules = {};
View
@@ -290,9 +290,9 @@ module.exports = function (hawkejs) {
* Enable client-side suport
* This is a blocking feature, but only runs at server boot
*
- * @author Jelle De Loecker <jelle@kipdola.be>
+ * @author Jelle De Loecker <jelle@codedor.be>
* @since 0.0.1
- * @version 0.0.8
+ * @version 0.0.10
*
* @param {Object} app The express app
* @param {Object} express
@@ -310,6 +310,9 @@ module.exports = function (hawkejs) {
// Expose these to the public
app.use('/hawkejs', express.static(filepath));
+ // Also expode the vendor folder
+ app.use('/hawkejs/vendor', express.static(path.resolve(__dirname, '..', 'vendor')));
+
// Set the temporary path
tempPath = filepath;
View
@@ -449,6 +449,9 @@ hawkejs.render = function render (template, variables, $update, callback) {
return payload;
}
+ // Let us know if this is the ClientSide
+ payload.ClientSide = ClientSide;
+
// Render the ejs template
thisHawk._renderTemplates(template, payload, $update, function($result) {
@@ -814,9 +817,6 @@ hawkejs._preparePayload = function _preparePayload (variables, template, forAjax
// See if we need to enable debugging on the client side
if (ClientSide && variables.hawkejs.debug) this._debug = true;
- // Let us know if this is the ClientSide
- variables.ClientSide = ClientSide;
-
// If the __hasBeenPrepared value is set, we don't need to do anything more
if (variables.__hasBeenPrepared) {
View
@@ -1050,7 +1050,7 @@ module.exports = function helpers (hawkejs) {
// Set the value if needed, and return nothing
if (typeof value !== 'undefined') {
if (this.ClientSide) {
- window.storage[name] = value;
+ window.hawkejs.storage[name] = value;
} else {
this.__storageVars[name] = value;
}
@@ -1063,13 +1063,13 @@ module.exports = function helpers (hawkejs) {
if (name in this.__storageVars) {
retval = this.__storageVars[name];
} else {
- retval = window.storage[name];
+ retval = window.hawkejs.storage[name];
}
// If the value isn't set, but a default value has been given,
// set and return that
if (typeof retval === 'undefined' && typeof defaultValue !== 'undefined') {
- window.storage[name] = defaultValue;
+ window.hawkejs.storage[name] = defaultValue;
return defaultValue;
} else {
return retval;
View
@@ -0,0 +1,20 @@
+(function($) {
+$.fn.jsonify = function(options) {
+ var settings = $.extend({
+ stringify : false
+ }, options);
+ var json = {};
+ $.each(this.serializeArray(), function() {
+ if (json[this.name]) {
+ if (!json[this.name].push)
+ json[this.name] = [json[this.name]];
+ json[this.name].push(this.value || '');
+ } else
+ json[this.name] = this.value || '';
+ });
+ if(settings.stringify)
+ return JSON.stringify(json);
+ else
+ return json;
+};
+})(jQuery);

0 comments on commit d15da4c

Please sign in to comment.