mirror of https://github.com/zulip/zulip.git
zjsunit: Remove render.js.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
3c3471b720
commit
8761e09eed
|
@ -146,10 +146,6 @@ people.initialize_current_user(me.user_id);
|
|||
const real_update_huddles = activity.update_huddles;
|
||||
activity.update_huddles = () => {};
|
||||
|
||||
global.compile_template('user_presence_row');
|
||||
global.compile_template('user_presence_rows');
|
||||
global.compile_template('group_pms');
|
||||
|
||||
const presence_info = {};
|
||||
presence_info[alice.user_id] = { status: 'inactive' };
|
||||
presence_info[fred.user_id] = { status: 'active' };
|
||||
|
|
|
@ -167,8 +167,6 @@ set_global('pygments_data', {langs:
|
|||
{python: 0, javscript: 1, html: 2, css: 3},
|
||||
});
|
||||
|
||||
global.compile_template('typeahead_list_item');
|
||||
|
||||
var hamlet = {
|
||||
email: 'hamlet@zulip.com',
|
||||
user_id: 100,
|
||||
|
|
|
@ -4,7 +4,6 @@ zrequire('input_pill');
|
|||
|
||||
zrequire('Handlebars', 'handlebars');
|
||||
zrequire('templates');
|
||||
global.compile_template('input_pill');
|
||||
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
set_global('document', {});
|
||||
|
|
|
@ -124,7 +124,6 @@ function set_up() {
|
|||
};
|
||||
return mock_children;
|
||||
};
|
||||
global.compile_template('embedded_bot_config_item');
|
||||
avatar.build_bot_create_widget = () => {};
|
||||
avatar.build_bot_edit_widget = () => {};
|
||||
|
||||
|
|
|
@ -17,19 +17,6 @@ function render(template_name, args) {
|
|||
return global.render_template(template_name, args);
|
||||
}
|
||||
|
||||
run_test('finding_partials', () => {
|
||||
var fns = global.find_included_partials('settings_tab');
|
||||
assert.deepEqual(fns, [
|
||||
'settings/account_settings',
|
||||
'settings/display_settings',
|
||||
'settings/notification_settings',
|
||||
'settings/bot_settings',
|
||||
'settings/alert_word_settings',
|
||||
'settings/attachments_settings',
|
||||
'settings/muted_topics_settings',
|
||||
]);
|
||||
});
|
||||
|
||||
run_test('handlebars_bug', () => {
|
||||
// There was a bug in 1.0.9 where identically structured
|
||||
// blocks get confused, so when foo is false, it still
|
||||
|
|
|
@ -56,11 +56,7 @@ var stub = require('./stub.js');
|
|||
global.with_stub = stub.with_stub;
|
||||
|
||||
// Set up helpers to render templates.
|
||||
var render = require('./render.js');
|
||||
global.find_included_partials = render.find_included_partials;
|
||||
global.compile_template = render.compile_template;
|
||||
global.render_template = render.render_template;
|
||||
global.walk = render.walk;
|
||||
global.render_template = (name, args) => global.templates.render(name, args);
|
||||
|
||||
// Set up fake jQuery
|
||||
global.make_zjquery = require('./zjquery.js').make_zjquery;
|
||||
|
@ -123,7 +119,6 @@ try {
|
|||
_.throttle = immediate;
|
||||
_.debounce = immediate;
|
||||
|
||||
render.init();
|
||||
run_one_module(file);
|
||||
namespace.restore();
|
||||
});
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
var render = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
var fs = require('fs');
|
||||
var _ = require('underscore/underscore.js');
|
||||
var Handlebars = require('handlebars');
|
||||
|
||||
function template_dir() {
|
||||
return __dirname + '/../../static/templates';
|
||||
}
|
||||
|
||||
exports.init = function () {
|
||||
Handlebars.templates = {};
|
||||
};
|
||||
|
||||
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 = {};
|
||||
}
|
||||
|
||||
if (_.has(Handlebars.template, name)) {
|
||||
// we already compile the template
|
||||
return;
|
||||
}
|
||||
|
||||
var file = exports.template_finder.get(name);
|
||||
var data = fs.readFileSync(file.url).toString();
|
||||
Handlebars.templates[name] = Handlebars.compile(data);
|
||||
};
|
||||
|
||||
// list all files in a directory and it's subdirectories in a recursive sync way.
|
||||
exports.walk = function (dir, filelist) {
|
||||
filelist = filelist || [];
|
||||
|
||||
// grab files one level deep.
|
||||
var files = fs.readdirSync(dir);
|
||||
|
||||
// for each file, check if it's a directory. If so, continue recursion.
|
||||
// if not add to the file list.
|
||||
files.forEach(function (file) {
|
||||
if (fs.statSync(dir + "/" + file).isDirectory()) {
|
||||
filelist = exports.walk(dir + "/" + file, filelist);
|
||||
} else {
|
||||
var url = dir + "/" + file;
|
||||
// Get the file path starting after static/templates/
|
||||
var name = url.replace(/^.+static\/templates\//, '');
|
||||
filelist.push({ url, name });
|
||||
}
|
||||
});
|
||||
|
||||
// return all recursively found files.
|
||||
return filelist;
|
||||
};
|
||||
|
||||
exports.template_finder = (function () {
|
||||
// This class lets you find template files in our file system.
|
||||
// It may be slightly overkill for our flat directory system;
|
||||
// it might make more sense to just do something more like
|
||||
// this: get_template_dir() + name + '.hbs'
|
||||
|
||||
var self = {};
|
||||
|
||||
// get all files and then map them into friendlier names.
|
||||
var all_files = exports.walk(template_dir());
|
||||
var files = all_files
|
||||
.filter(function (file) {
|
||||
return (/\.hbs$/).test(file.name);
|
||||
})
|
||||
.map(function (file) {
|
||||
return {
|
||||
url: file.url,
|
||||
name: file.name.replace(/\.hbs$/, ""),
|
||||
};
|
||||
});
|
||||
|
||||
self.get = function (name) {
|
||||
var file = files.find(function (file) {
|
||||
return file.name === name;
|
||||
});
|
||||
assert(file);
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
self.get_all = function () {
|
||||
return files;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
module.exports = render;
|
Loading…
Reference in New Issue