mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
node tests: Extract render.find_included_partials().
This commit is contained in:
@@ -42,6 +42,18 @@ fs.readdirSync(path.join(__dirname, "../../static/templates/", "settings")).forE
|
||||
render(o.replace(/\.handlebars/, ""));
|
||||
});
|
||||
|
||||
(function test_finding_partials () {
|
||||
var fns = global.find_included_partials('settings_tab');
|
||||
assert.deepEqual(fns, [
|
||||
'account-settings',
|
||||
'display-settings',
|
||||
'notification-settings',
|
||||
'bot-settings',
|
||||
'alert-word-settings',
|
||||
'ui-settings'
|
||||
]);
|
||||
}());
|
||||
|
||||
(function test_handlebars_bug () {
|
||||
// There was a bug in 1.0.9 where identically structured
|
||||
// blocks get confused, so when foo is false, it still
|
||||
|
||||
@@ -24,6 +24,7 @@ var render = require('./render.js');
|
||||
global.use_template = render.use_template;
|
||||
global.make_sure_all_templates_have_been_compiled = render.make_sure_all_templates_have_been_compiled;
|
||||
global.partial_finder = render.partial_finder;
|
||||
global.find_included_partials = render.find_included_partials;
|
||||
global.walk = render.walk;
|
||||
|
||||
// Set up helpers to output HTML
|
||||
|
||||
@@ -112,6 +112,27 @@ exports.template_finder = (function () {
|
||||
return self;
|
||||
}());
|
||||
|
||||
exports.find_included_partials = function (name) {
|
||||
|
||||
var file = exports.template_finder.get(name);
|
||||
|
||||
assert(file);
|
||||
|
||||
var template = fs.readFileSync(file.url, "utf8");
|
||||
|
||||
var lst = [];
|
||||
|
||||
// match partial tags.
|
||||
// this uses String.prototype.replace which is kind of hacky but
|
||||
// it is the only JS function IIRC that allows you to match all
|
||||
// instances of a pattern AND return capture groups.
|
||||
template.replace(/\{\{\s*partial\s*"(.+?)"/ig, function (match, $1) {
|
||||
lst.push($1);
|
||||
});
|
||||
|
||||
return lst;
|
||||
};
|
||||
|
||||
exports.partial_finder = (function () {
|
||||
var meta = {
|
||||
read: []
|
||||
@@ -128,20 +149,12 @@ exports.partial_finder = (function () {
|
||||
}
|
||||
|
||||
meta.read.push(name);
|
||||
var included_fns = exports.find_included_partials(name);
|
||||
|
||||
var file = exports.template_finder.get(name);
|
||||
_.each(included_fns, function (fn) {
|
||||
__prototype__(fn, callback);
|
||||
});
|
||||
|
||||
if (file) {
|
||||
var template = fs.readFileSync(file.url, "utf8");
|
||||
|
||||
// match partial tags.
|
||||
// this uses String.prototype.replace which is kind of hacky but
|
||||
// it is the only JS function IIRC that allows you to match all
|
||||
// instances of a pattern AND return capture groups.
|
||||
template.replace(/\{\{\s*partial\s*"(.+?)"/ig, function (match, $1) {
|
||||
__prototype__($1, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user