Permalink
Browse files

Helpers also can change the last modified

  • Loading branch information...
1 parent 6771a6f commit 59be0a8678c82fe959759c817687f0bf3775757a @laktek committed Aug 25, 2012
View
2 lib/asset_bundler.js
@@ -167,7 +167,7 @@ module.exports = {
return traverse_bundled_files();
}
- var current_mtime = template.last_modified.getTime();
+ var current_mtime = template.last_modified;
if (current_mtime > bundle_mtime) {
bundle_mtime = current_mtime;
}
View
2 lib/content_handler.js
@@ -293,7 +293,7 @@ module.exports = {
last_modified = modified_date;
var run_callback = function(){
- return callback(null, collected_contents, last_modified, content_options);
+ return callback(null, collected_contents, content_options, last_modified);
};
//fetch shared content
View
10 lib/helpers/asset_bundle_helper.js
@@ -9,6 +9,8 @@ var bundles = {};
var bundle_fingerprints = {};
+var bundles_last_modified = null;
+
var bundling_disabled = false;
var skip_hosts = [];
@@ -17,7 +19,7 @@ var build_bundle_tag = function(template_tag, bundle) {
var file_extension = path_utils.getExtension(bundle, null);
var request_basename = path_utils.getBasename(bundle, file_extension);
- var fingerprinted_path = (request_basename + "-" + bundle_fingerprints[bundle] + file_extension);
+ var fingerprinted_path = (request_basename + "-" + bundle_fingerprints[bundle].getTime() + file_extension);
return util.format(template_tag, fingerprinted_path);
};
@@ -33,6 +35,10 @@ var refresh_all_bundle_fingerprints = function(callback) {
asset_bundler.statBundle(request_basename, file_extension, function(err, stat) {
bundle_fingerprints[bundle] = stat.mtime;
+ if (stat.mtime > bundles_last_modified) {
+ bundles_last_modified = stat.mtime;
+ }
+
return refresh_bundle_fingerprint();
});
} else {
@@ -102,7 +108,7 @@ module.exports = {
bundling_disabled = !!( (options.host && options.host.length) && is_bundling_disabled_host(options.host) );
refresh_all_bundle_fingerprints(function() {
- return callback(null, tag_helpers, block_helpers, {});
+ return callback(null, { "tag": tag_helpers, "block": block_helpers }, {}, bundles_last_modified);
});
},
View
2 lib/helpers/datetime_helper.js
@@ -63,7 +63,7 @@ module.exports = {
get: function(basepath, content_type, options, callback){
var self = this;
- return callback(null, tag_helpers, block_helpers, {});
+ return callback(null, { "tag": tag_helpers, "block": block_helpers }, {});
}
};
View
2 lib/helpers/list_helper.js
@@ -69,7 +69,7 @@ module.exports = {
get: function(basepath, content_type, options, callback){
var self = this;
- return callback(null, tag_helpers, block_helpers, {});
+ return callback(null, { "tag": tag_helpers, "block": block_helpers }, {});
}
};
View
2 lib/helpers/text_helper.js
@@ -94,7 +94,7 @@ module.exports = {
get: function(basepath, content_type, options, callback){
var self = this;
- return callback(null, tag_helpers, block_helpers, {});
+ return callback(null, { "tag": tag_helpers, "block": block_helpers }, {});
}
};
View
23 lib/page_renderer.js
@@ -40,16 +40,21 @@ module.exports = {
getHelpers: function(basepath, output_extension, options, callback) {
var self = this;
- var collected_helpers = { "tag_helpers": {}, "block_helpers": {} };
+ var collected_helpers = { "tag": {}, "block": {} };
var collected_helper_options = {};
+ var collected_helpers_last_modified = null;
var cloned_helpers = self.helpers.slice(0);
var get_helper_content = function(helper, helper_callback){
- helper.get(basepath, output_extension, options, function(err, tag_helpers, block_helpers, helper_options){
- if(!err){
- collected_helpers["tag_helpers"] = _.extend(collected_helpers["tag_helpers"], tag_helpers);
- collected_helpers["block_helpers"] = _.extend(collected_helpers["block_helpers"], block_helpers);
+ helper.get(basepath, output_extension, options, function(err, helper_tags, helper_options, last_modified){
+ if (!err) {
+ collected_helpers["tag"] = _.extend(collected_helpers["tag"], helper_tags["tag"]);
+ collected_helpers["block"] = _.extend(collected_helpers["block"], helper_tags["block"]);
collected_helper_options = _.extend(collected_helper_options, helper_options);
+
+ if (last_modified > collected_helpers_last_modified) {
+ collected_helpers_last_modified = last_modified;
+ }
}
return helper_callback();
@@ -60,7 +65,7 @@ module.exports = {
if (cloned_helpers.length) {
return get_helper_content(cloned_helpers.shift(), get_helper_callback);
} else {
- return callback(null, collected_helpers, collected_helper_options);
+ return callback(null, collected_helpers, collected_helper_options, collected_helpers_last_modified);
}
};
return get_helper_callback();
@@ -168,7 +173,7 @@ module.exports = {
return callback(null, { "body": null, "modified": true, "options": { "status": status_code, "log": { "message": err } } });
});
- self.contents.negotiateContent(basepath, output_extension, options, function(err, content_obj, content_last_modified, content_options) {
+ self.contents.negotiateContent(basepath, output_extension, options, function(err, content_obj, content_options, content_last_modified) {
response_options = _.extend(response_options, content_options);
if (!err) {
return template_engine.setContent(content_obj, content_last_modified);
@@ -189,10 +194,10 @@ module.exports = {
return template_engine.setPartials(partials, partials_last_modified);
});
- self.getHelpers(basepath, output_extension, options, function(err, helper_obj, helper_options) {
+ self.getHelpers(basepath, output_extension, options, function(err, helper_obj, helper_options, helper_last_modified) {
response_options = _.extend(response_options, helper_options);
if (!err) {
- return template_engine.setHelpers(helper_obj, helper_options);
+ return template_engine.setHelpers(helper_obj, helper_last_modified);
}
});
},
View
6 lib/template_engines/base_engine.js
@@ -58,10 +58,14 @@ BaseEngine.prototype.setPartials = function(partials, last_modified) {
return self.render();
};
-BaseEngine.prototype.setHelpers = function(helpers) {
+BaseEngine.prototype.setHelpers = function(helpers, last_modified) {
var self = this;
self.helpers = helpers;
+ if (last_modified > self.lastModified) {
+ self.lastModified = last_modified;
+ }
+
return self.render();
};
View
4 lib/template_engines/mustache_engine.js
@@ -23,9 +23,9 @@ MustacheEngine.extension = ".mustache";
MustacheEngine.renderFunction = function(template, content, partials, helpers) {
// since mustache doesn't have built-in support helpers,
// we'll extend the content object with helpers.
- var content_with_helpers = _.extend({}, content, helpers.tag_helpers);
+ var content_with_helpers = _.extend({}, content, helpers.tag);
- _.each(helpers.block_helpers, function(helper_function, name) {
+ _.each(helpers.block, function(helper_function, name) {
content_with_helpers[name] = function() {
return function(text, render) {
try {
View
2 spec/asset_bundler.spec.js
@@ -118,7 +118,7 @@ describe("get the stat of a bundle", function() {
var spyCallback = jasmine.createSpy();
asset_bundler.statBundle("path/all", ".js", spyCallback);
- expect(spyCallback).toHaveBeenCalledWith(null, { "mtime": new Date(2012, 7, 25).getTime() });
+ expect(spyCallback).toHaveBeenCalledWith(null, { "mtime": new Date(2012, 7, 25) });
});
});
View
3 spec/content_handler.spec.js
@@ -333,7 +333,7 @@ describe("negotiate content", function(){
var spyCallback = jasmine.createSpy();
default_handler.negotiateContent("path/test", ".html", {}, spyCallback);
- expect(spyCallback).toHaveBeenCalledWith(null, { "content_key": "content_value", "shared_key": "shared_value" }, new Date(2012, 6, 18), {});
+ expect(spyCallback).toHaveBeenCalledWith(null, { "content_key": "content_value", "shared_key": "shared_value" }, {}, new Date(2012, 6, 18));
});
it("call the callback with an error object, if content for path doesn't exist", function(){
@@ -416,4 +416,5 @@ describe("get contents", function(){
expect(spyCallback).toHaveBeenCalledWith("error", []);
});
+
});
View
12 spec/helpers/asset_bundle_helper.spec.js
@@ -9,21 +9,21 @@ describe("stylesheet bundle tag", function(){
spyOn(asset_bundler, "setup");
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": 1337 });
+ return callback(null, { "mtime": new Date(2012, 7, 25) });
});
asset_bundle_helper_obj.setup( { "skip_asset_bundling": ["localhost", "127.0.0.1", ".local"], "bundles": { "/assets/all.css": [ "/assets/initial.css", "/assets/site.css" ]} });
var spyCallback = jasmine.createSpy();
asset_bundle_helper_obj.get( "/path/test", ".html", { "host": "" }, spyCallback);
- expect(asset_bundle_helper.stylesheet_bundle("/assets/all.css")).toEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/assets/all-1337.css\">");
+ expect(asset_bundle_helper.stylesheet_bundle("/assets/all.css")).toEqual("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/assets/all-" + new Date(2012, 7, 25).getTime() + ".css\">");
});
it("output tags for individual files in bundle when host is a local", function(){
spyOn(asset_bundler, "setup");
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": 1337 });
+ return callback(null, { "mtime": new Date(2012, 7, 25) });
});
asset_bundle_helper_obj.setup( { "skip_asset_bundling": ["localhost", "127.0.0.1", ".local"], "bundles": { "/assets/all.css": [ "/assets/initial.css", "/assets/site.css" ]} });
@@ -41,21 +41,21 @@ describe("javascript bundle tag", function(){
spyOn(asset_bundler, "setup");
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": 1337 });
+ return callback(null, { "mtime": new Date(2012, 7, 25) });
});
asset_bundle_helper_obj.setup( { "skip_asset_bundling": ["localhost", "127.0.0.1", ".local"], "bundles": { "/assets/all.js": [ "/assets/jquery.js", "/assets/site.js" ]} });
var spyCallback = jasmine.createSpy();
asset_bundle_helper_obj.get( "/path/test", ".html", { "host": undefined }, spyCallback);
- expect(asset_bundle_helper.javascript_bundle("/assets/all.js")).toEqual("<script src=\"/assets/all-1337.js\"></script>");
+ expect(asset_bundle_helper.javascript_bundle("/assets/all.js")).toEqual("<script src=\"/assets/all-" + new Date(2012, 7, 25).getTime() + ".js\"></script>");
});
it("output tags for individual files in bundle when host is a local", function(){
spyOn(asset_bundler, "setup");
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": 1337 });
+ return callback(null, { "mtime": new Date(2012, 7, 25) });
});
asset_bundle_helper_obj.setup( { "skip_asset_bundling": ["localhost", "127.0.0.1", ".local"], "bundles": { "/assets/all.js": [ "/assets/jquery.js", "/assets/site.js" ]} });
View
10 spec/page_renderer.spec.js
@@ -689,13 +689,13 @@ describe("render content", function(){
var spyHelperObj = jasmine.createSpy();
var spyHelperOptions = jasmine.createSpy();
spyOn(renderer, "getHelpers").andCallFake(function(basepath, extension, options, callback) {
- return callback(null, spyHelperObj, spyHelperOptions);
+ return callback(null, spyHelperObj, spyHelperOptions, new Date(2012, 7, 25));
});
var spyCallback = jasmine.createSpy();
renderer.renderContent("path/test.html", ".html", new Date(2012, 6, 18), {}, spyCallback);
- expect(spySetHelpers).toHaveBeenCalledWith(spyHelperObj, spyHelperOptions);
+ expect(spySetHelpers).toHaveBeenCalledWith(spyHelperObj, new Date(2012, 7, 25));
});
});
@@ -717,12 +717,12 @@ describe("get helpers", function() {
it("call the callback with all content collected by helpers", function(){
var spyHelperGet1 = jasmine.createSpy();
spyHelperGet1.andCallFake(function(path, content_type, options, callback){
- return callback(null, { "tag_helper1": "value" }, { "block_helper1": "value"}, { "opt1": "value" });
+ return callback(null, { "tag": { "tag_helper1": "value" }, "block": { "block_helper1": "value"} }, { "opt1": "value" }, new Date(2012, 7, 25));
});
var spyHelperGet2 = jasmine.createSpy();
spyHelperGet2.andCallFake(function(path, content_type, options, callback){
- return callback(null, { "tag_helper2": "value" }, { "block_helper2": "value"}, { "opt2": "value" });
+ return callback(null, { "tag": { "tag_helper2": "value" }, "block": { "block_helper2": "value"} }, { "opt2": "value" }, new Date(2012, 7, 27));
});
renderer.helpers = [{ "get": spyHelperGet1 }, { "get": spyHelperGet2 }];
@@ -731,7 +731,7 @@ describe("get helpers", function() {
var spyOptions = jasmine.createSpy();
renderer.getHelpers("path/test", "html", spyOptions, spyCallback);
- expect(spyCallback).toHaveBeenCalledWith(null, { "tag_helpers": { "tag_helper1": "value", "tag_helper2": "value" }, "block_helpers": { "block_helper1": "value", "block_helper2": "value" } }, { "opt1": "value", "opt2": "value" });
+ expect(spyCallback).toHaveBeenCalledWith(null, { "tag": { "tag_helper1": "value", "tag_helper2": "value" }, "block": { "block_helper1": "value", "block_helper2": "value" } }, { "opt1": "value", "opt2": "value" }, new Date(2012, 7, 27));
});
});
View
4 spec/template_engines/mustache_engine.spec.js
@@ -34,7 +34,7 @@ describe("calling render", function(){
mustache_instance.template = "template";
mustache_instance.content = { "content_key": "content_value" };
mustache_instance.partials = {};
- mustache_instance.helpers = { "tag_helpers": { "tag_helper": "tag_helper_value" }, "block_helpers": { "block_helper": "block_helper_value" }};
+ mustache_instance.helpers = { "tag": { "tag_helper": "tag_helper_value" }, "block": { "block_helper": "block_helper_value" }};
mustache_instance.lastModified = new Date(2012, 6, 18);
spyOn(mustache_instance, "emit");
@@ -55,7 +55,7 @@ describe("calling render", function(){
}
};
- var render_output = MustacheEngine.renderFunction("", {}, {}, {"tag_helpers": {}, "block_helpers": { "dummy_helper": dummy_helper }});
+ var render_output = MustacheEngine.renderFunction("", {}, {}, {"tag": {}, "block": { "dummy_helper": dummy_helper }});
expect(render_output).toEqual("helper text");
});

0 comments on commit 59be0a8

Please sign in to comment.