diff --git a/frontend_tests/node_tests/i18n.js b/frontend_tests/node_tests/i18n.js index 54a4de8a8a..829c851150 100644 --- a/frontend_tests/node_tests/i18n.js +++ b/frontend_tests/node_tests/i18n.js @@ -30,14 +30,6 @@ var window = jsdom.jsdom().defaultView; global.$ = require('jquery')(window); var _ = global._; -// When writing these tests, the following command might be helpful: -// ./tools/get-handlebar-vars static/templates/*.handlebars - -function render(template_name, args) { - global.use_template(template_name); - return global.templates.render(template_name, args); -} - (function test_t_tag() { var args = { "message": { @@ -53,7 +45,7 @@ function render(template_name, args) { }; var html = '
'; - html += render('actions_popover_content', args); + html += global.render_template('actions_popover_content', args); html += "
"; var link = $(html).find("a.respond_button"); assert.equal(link.text().trim(), 'French'); @@ -84,10 +76,10 @@ function render(template_name, args) { }; fs.readdirSync(path.join(__dirname, "../../static/templates/", "settings")).forEach(function (o) { - render(o.replace(/\.handlebars/, "")); + global.render_template(o.replace(/\.handlebars/, "")); }); - var html = render('settings_tab', args); + var html = global.render_template('settings_tab', args); var div = $(html).find("div.notification-reminder"); assert.equal(div.text().trim(), 'Some French text with Zulip'); global.write_test_output("test_tr_tag settings", html); diff --git a/frontend_tests/node_tests/presence_list_performance.js b/frontend_tests/node_tests/presence_list_performance.js index 69cfb21f27..8ad0892b32 100644 --- a/frontend_tests/node_tests/presence_list_performance.js +++ b/frontend_tests/node_tests/presence_list_performance.js @@ -32,8 +32,8 @@ $.fn.expectOne = function () { return this; }; -global.use_template('user_presence_row'); -global.use_template('user_presence_rows'); +global.compile_template('user_presence_row'); +global.compile_template('user_presence_rows'); var people = require("js/people.js"); var activity = require('js/activity.js'); diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 67e45ce07b..2dddd5f9c4 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -29,10 +29,10 @@ $.fn.expectOne = function () { return this; }; -global.use_template('sidebar_private_message_list'); -global.use_template('stream_sidebar_row'); -global.use_template('stream_privacy'); -global.use_template('topic_list_item'); +global.compile_template('sidebar_private_message_list'); +global.compile_template('stream_sidebar_row'); +global.compile_template('stream_privacy'); +global.compile_template('topic_list_item'); (function test_topic_list_build_widget() { var stream = "devel"; diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index 23032a8a88..abfa29a6e3 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -32,10 +32,7 @@ var _ = global._; // ./tools/get-handlebar-vars static/templates/*.handlebars function render(template_name, args) { - global.partial_finder(template_name, function (name) { - global.use_template(name); - }); - return global.templates.render(template_name, args); + return global.render_template(template_name, args); } fs.readdirSync(path.join(__dirname, "../../static/templates/", "settings")).forEach(function (o) { diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index b1fdcbf3d0..35bee2a7c6 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -21,10 +21,10 @@ global.stub_out_jquery = namespace.stub_out_jquery; // Set up helpers to render templates. 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.compile_template = render.compile_template; +global.render_template = render.render_template; global.walk = render.walk; // Set up helpers to output HTML diff --git a/frontend_tests/zjsunit/render.js b/frontend_tests/zjsunit/render.js index 6fcd127553..04d816cdd7 100644 --- a/frontend_tests/zjsunit/render.js +++ b/frontend_tests/zjsunit/render.js @@ -35,7 +35,18 @@ exports.make_sure_all_templates_have_been_compiled = function () { }); }; -exports.use_template = function (name) { +exports.render_template = function (name, args) { + exports.compile_template(name); + return global.templates.render(name, args); +}; + +exports.compile_template = function (name) { + var included_fns = exports.find_included_partials(name); + + _.each(included_fns, function (fn) { + exports.compile_template(fn); + }); + if (Handlebars.templates === undefined) { Handlebars.templates = {}; } @@ -138,38 +149,6 @@ exports.find_included_partials = function (name) { return lst; }; -exports.partial_finder = (function () { - var meta = { - read: [] - }; - - // this is the external function that is called that will recursively search - // for partials in a file and partials inside partials until it finds them all. - // it then adds them to a maintenance list of already read partials so that - // they don't have to be read/searched again. - var __prototype__ = function (name, callback) { - if (meta.read.indexOf(name) === -1) { - if (callback) { - callback(name); - } - - meta.read.push(name); - var included_fns = exports.find_included_partials(name); - - _.each(included_fns, function (fn) { - __prototype__(fn, callback); - }); - - } - }; - - return __prototype__; -}()); - -fs.readdirSync(path.join(__dirname, "../../static/templates/", "settings")).forEach(function (o) { - exports.use_template(o.replace(/\.handlebars/, "")); -}); - return exports; }()); module.exports = render;