From db0b33842cd81571c46eb22d3f8abd9e607936c2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 9 Jul 2019 12:24:00 -0700 Subject: [PATCH] templates: Replace templates.render with require calls. This removes an unnecessary layer of indirection and allows webpack to catch filename mistakes. Signed-off-by: Anders Kaseorg --- docs/subsystems/html-templates.md | 13 --------- frontend_tests/node_tests/i18n.js | 4 +-- frontend_tests/node_tests/input_pill.js | 2 +- frontend_tests/node_tests/templates.js | 2 +- frontend_tests/zjsunit/handlebars.js | 2 -- frontend_tests/zjsunit/index.js | 3 -- static/js/activity.js | 3 +- static/js/admin.js | 4 ++- static/js/alert_words_ui.js | 14 +++++++--- static/js/archive.js | 4 ++- static/js/attachments_ui.js | 7 +++-- static/js/buddy_list.js | 7 +++-- static/js/compose.js | 16 +++++++---- static/js/confirm_dialog.js | 4 ++- static/js/drafts.js | 4 ++- static/js/emoji_picker.js | 13 ++++++--- static/js/feedback_widget.js | 4 ++- static/js/hotspots.js | 7 +++-- static/js/input_pill.js | 4 ++- static/js/invite.js | 10 +++++-- static/js/loading.js | 4 ++- static/js/message_edit.js | 30 +++++++++++--------- static/js/message_list_view.js | 13 ++++++--- static/js/muting_ui.js | 7 +++-- static/js/notifications.js | 15 ++++++---- static/js/pm_list.js | 7 +++-- static/js/poll_widget.js | 7 +++-- static/js/popovers.js | 35 +++++++++++++++-------- static/js/reactions.js | 3 +- static/js/settings.js | 4 ++- static/js/settings_account.js | 7 +++-- static/js/settings_bots.js | 23 ++++++++++----- static/js/settings_emoji.js | 7 +++-- static/js/settings_invites.js | 7 +++-- static/js/settings_linkifiers.js | 20 ++++++------- static/js/settings_org.js | 19 +++++++++---- static/js/settings_profile_fields.js | 37 +++++++++++++------------ static/js/settings_streams.js | 6 +++- static/js/settings_user_groups.js | 7 +++-- static/js/settings_users.js | 14 ++++++---- static/js/stream_create.js | 15 ++++++---- static/js/stream_edit.js | 18 ++++++++---- static/js/stream_list.js | 6 ++-- static/js/stream_popover.js | 31 +++++++++++---------- static/js/stream_ui_updates.js | 10 +++++-- static/js/subs.js | 16 +++++++---- static/js/tab_bar.js | 4 ++- static/js/templates.js | 14 +--------- static/js/tictactoe_widget.js | 4 ++- static/js/todo_widget.js | 7 +++-- static/js/topic_list.js | 6 ++-- static/js/typeahead_helper.js | 3 +- static/js/typing_events.js | 4 ++- static/js/unread_ui.js | 4 ++- static/js/zform.js | 4 ++- tools/linter_lib/custom_check.py | 2 +- 56 files changed, 340 insertions(+), 207 deletions(-) diff --git a/docs/subsystems/html-templates.md b/docs/subsystems/html-templates.md index c70990a8d1..1fad687712 100644 --- a/docs/subsystems/html-templates.md +++ b/docs/subsystems/html-templates.md @@ -62,19 +62,6 @@ found [here][hconditionals]. There's no equivalent of `zulip_default_context` for the Handlebars templates. -In order to find the context definition, you should grep without using -the file extension. For example, to find where -`invite_subscription.hbs` is rendered, you should run something -like this: - -``` -$ git grep "render('invite_subscription" 'static/js' -frontend_tests/node_tests/templates.js: var html = render('invite_subscription', args); -static/js/invite.js: $('#streams_to_add').html(templates.render('invite_subscription', {streams: streams})); -``` - -The second argument to `templates.render` is the context. - ### Toolchain Handlebars is in our `package.json` and thus ends up in `node_modules`; We use diff --git a/frontend_tests/node_tests/i18n.js b/frontend_tests/node_tests/i18n.js index 596208736a..53a6f46e52 100644 --- a/frontend_tests/node_tests/i18n.js +++ b/frontend_tests/node_tests/i18n.js @@ -35,7 +35,7 @@ run_test('t_tag', () => { narrowed: true, }; - var html = global.render_template('actions_popover_content', args); + var html = require('../../static/templates/actions_popover_content.hbs')(args); assert(html.indexOf("French translation") > 0); }); @@ -59,6 +59,6 @@ run_test('tr_tag', () => { }, }; - var html = global.render_template('settings_tab', args); + var html = require('../../static/templates/settings_tab.hbs')(args); assert(html.indexOf('Some French text') > 0); }); diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index da74c7e297..ff8b92cf73 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -48,7 +48,7 @@ function pill_html(value, data_id, img_src) { opts.img_src = img_src; } - return templates.render('input_pill', opts); + return require('../../static/templates/input_pill.hbs')(opts); } run_test('basics', () => { diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index 43be39a676..a8d3827ebb 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -14,7 +14,7 @@ global.$ = require('jquery')(window); // ./tools/get-handlebar-vars static/templates/*.hbs function render(template_name, args) { - return global.render_template(template_name, args); + return require('../../static/templates/' + template_name + '.hbs')(args); } run_test('handlebars_bug', () => { diff --git a/frontend_tests/zjsunit/handlebars.js b/frontend_tests/zjsunit/handlebars.js index dee96638d3..ad06f58650 100644 --- a/frontend_tests/zjsunit/handlebars.js +++ b/frontend_tests/zjsunit/handlebars.js @@ -22,8 +22,6 @@ module.exports.make_handlebars = () => { }; module.exports.stub_templates = stub => { - set_global("Handlebars", module.exports.make_handlebars()); - zrequire("templates"); render = (filename, ...args) => { const name = path.relative(templates_path, filename).slice(0, -".hbs".length); return stub(name, ...args); diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index 47913fbca1..058e5b559c 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -55,9 +55,6 @@ global.with_overrides = namespace.with_overrides; var stub = require('./stub.js'); global.with_stub = stub.with_stub; -// Set up helpers to render templates. -global.render_template = (name, args) => global.templates.render(name, args); - // Set up fake jQuery global.make_zjquery = require('./zjquery.js').make_zjquery; diff --git a/static/js/activity.js b/static/js/activity.js index f0404c6879..cb553aa64b 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -1,3 +1,4 @@ +var render_group_pms = require('../templates/group_pms.hbs'); var Dict = require('./dict').Dict; var activity = (function () { @@ -250,7 +251,7 @@ exports.update_huddles = function () { }; }); - var html = templates.render('group_pms', {group_pms: group_pms}); + var html = render_group_pms({group_pms: group_pms}); ui.get_content_element($('#group-pms')).html(html); _.each(huddles, function (user_ids_string) { diff --git a/static/js/admin.js b/static/js/admin.js index f7f60a2b3f..9ff69ebea0 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -1,3 +1,5 @@ +var render_admin_tab = require('../templates/admin_tab.hbs'); + var admin = (function () { var exports = {}; @@ -86,7 +88,7 @@ exports.build_page = function () { options.realm_night_logo_url = options.realm_logo_url; } - var rendered_admin_tab = templates.render('admin_tab', options); + var rendered_admin_tab = render_admin_tab(options); $("#settings_content .organization-box").html(rendered_admin_tab); $("#settings_content .alert").removeClass("show"); diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js index 0446bb34f0..d80af92248 100644 --- a/static/js/alert_words_ui.js +++ b/static/js/alert_words_ui.js @@ -1,3 +1,5 @@ +var render_alert_word_settings_item = require('../templates/alert_word_settings_item.hbs'); + var alert_words_ui = (function () { var exports = {}; @@ -8,12 +10,16 @@ exports.render_alert_words_ui = function () { word_list.find('.alert-word-item').remove(); _.each(words, function (alert_word) { - var rendered_alert_word = templates.render('alert_word_settings_item', - {word: alert_word, editing: false}); + var rendered_alert_word = render_alert_word_settings_item({ + word: alert_word, + editing: false, + }); word_list.append(rendered_alert_word); }); - var new_alert_word_form = templates.render('alert_word_settings_item', - {word: '', editing: true}); + var new_alert_word_form = render_alert_word_settings_item({ + word: '', + editing: true, + }); word_list.append(new_alert_word_form); // Focus new alert word name text box. diff --git a/static/js/archive.js b/static/js/archive.js index 83378e27e8..38a921a559 100644 --- a/static/js/archive.js +++ b/static/js/archive.js @@ -1,3 +1,5 @@ +var render_archive_message_group = require('../templates/archive_message_group.hbs'); + var archive = (function () { var exports = {}; @@ -70,7 +72,7 @@ exports.initialize = function () { var context = { message_groups: all_message_groups, }; - var message_groups_html = templates.render('archive_message_group', context); + var message_groups_html = render_archive_message_group(context); $('.message_row').each(function () { $(this).detach(); }); diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js index 0d1dde7dba..999c37f624 100644 --- a/static/js/attachments_ui.js +++ b/static/js/attachments_ui.js @@ -1,3 +1,6 @@ +var render_settings_upload_space_stats = require("../templates/settings/upload_space_stats.hbs"); +var render_uploaded_files_list = require("../templates/uploaded_files_list.hbs"); + var attachments_ui = (function () { var exports = {}; @@ -38,7 +41,7 @@ function set_upload_space_stats() { percent_used: exports.percentage_used_space(upload_space_used), upload_quota: attachments_ui.bytes_to_size(page_params.realm_upload_quota, true), }; - var rendered_upload_stats_html = templates.render("settings/upload_space_stats", args); + var rendered_upload_stats_html = render_settings_upload_space_stats(args); $("#attachment-stats-holder").html(rendered_upload_stats_html); } @@ -65,7 +68,7 @@ function render_attachments_ui() { var list = list_render.create(uploaded_files_table, attachments, { name: "uploaded-files-list", modifier: function (attachment) { - return templates.render("uploaded_files_list", { attachment: attachment }); + return render_uploaded_files_list({ attachment: attachment }); }, filter: { element: $search_input, diff --git a/static/js/buddy_list.js b/static/js/buddy_list.js index c870782f04..67fa702057 100644 --- a/static/js/buddy_list.js +++ b/static/js/buddy_list.js @@ -1,3 +1,6 @@ +var render_user_presence_row = require('../templates/user_presence_row.hbs'); +var render_user_presence_rows = require('../templates/user_presence_rows.hbs'); + var buddy_list = (function () { function buddy_list_conf() { @@ -10,12 +13,12 @@ function buddy_list_conf() { conf.items_to_html = function (opts) { var user_info = opts.items; - var html = templates.render('user_presence_rows', {users: user_info}); + var html = render_user_presence_rows({users: user_info}); return html; }; conf.item_to_html = function (opts) { - var html = templates.render('user_presence_row', opts.item); + var html = render_user_presence_row(opts.item); return html; }; diff --git a/static/js/compose.js b/static/js/compose.js index a7f96a1389..fb8c42b07d 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -1,3 +1,9 @@ +var render_compose_all_everyone = require("../templates/compose_all_everyone.hbs"); +var render_compose_announce = require("../templates/compose_announce.hbs"); +var render_compose_invite_users = require("../templates/compose_invite_users.hbs"); +var render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs"); +var render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs"); + var compose = (function () { // Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html @@ -29,7 +35,7 @@ function make_uploads_relative(content) { function show_all_everyone_warnings() { var stream_count = stream_data.get_subscriber_count(compose_state.stream_name()) || 0; - var all_everyone_template = templates.render("compose_all_everyone", {count: stream_count}); + var all_everyone_template = render_compose_all_everyone({count: stream_count}); var error_area_all_everyone = $("#compose-all-everyone"); // only show one error for any number of @all or @everyone mentions @@ -58,7 +64,7 @@ function show_sending_indicator(whats_happening) { function show_announce_warnings() { var stream_count = stream_data.get_subscriber_count(compose_state.stream_name()) || 0; - var announce_template = templates.render("compose_announce", {count: stream_count}); + var announce_template = render_compose_announce({count: stream_count}); var error_area_announce = $("#compose-announce"); if (!error_area_announce.is(':visible')) { @@ -498,7 +504,7 @@ exports.validation_error = function (error_type, stream_name) { return false; case "not-subscribed": var sub = stream_data.get_sub(stream_name); - var new_row = templates.render("compose_not_subscribed", { + var new_row = render_compose_not_subscribed({ should_display_sub_button: sub.should_display_subscription_button}); compose_not_subscribed_error(new_row, $('#stream_message_recipient_stream')); return false; @@ -835,7 +841,7 @@ exports.initialize = function () { name: data.mentioned.full_name, can_subscribe_other_users: page_params.can_subscribe_other_users, }; - var new_row = templates.render("compose_invite_users", context); + var new_row = render_compose_invite_users(context); error_area.append(new_row); } @@ -978,7 +984,7 @@ exports.initialize = function () { var warning_area = $("#compose_private_stream_alert"); var context = { stream_name: stream_name }; - var new_row = templates.render("compose_private_stream_alert", context); + var new_row = render_compose_private_stream_alert(context); warning_area.append(new_row); warning_area.show(); diff --git a/static/js/confirm_dialog.js b/static/js/confirm_dialog.js index ac9ceab044..6f3ebe15a9 100644 --- a/static/js/confirm_dialog.js +++ b/static/js/confirm_dialog.js @@ -1,3 +1,5 @@ +var render_confirm_dialog = require("../templates/confirm_dialog.hbs"); + var confirm_dialog = (function () { var exports = {}; @@ -28,7 +30,7 @@ var exports = {}; */ exports.launch = function (conf) { - var html = templates.render("confirm_dialog"); + var html = render_confirm_dialog(); var confirm_dialog = $(html); var conf_fields = [ diff --git a/static/js/drafts.js b/static/js/drafts.js index 65155ac054..376e07c4bb 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -1,3 +1,5 @@ +var render_draft_table_body = require('../templates/draft_table_body.hbs'); + var drafts = (function () { var exports = {}; @@ -314,7 +316,7 @@ exports.launch = function () { function render_widgets(drafts) { $('#drafts_table').empty(); - var rendered = templates.render('draft_table_body', { + var rendered = render_draft_table_body({ drafts: drafts, draft_lifetime: DRAFT_LIFETIME, }); diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js index 4d97da6c05..3bd054bfc7 100644 --- a/static/js/emoji_picker.js +++ b/static/js/emoji_picker.js @@ -1,3 +1,8 @@ +var render_emoji_popover = require('../templates/emoji_popover.hbs'); +var render_emoji_popover_content = require('../templates/emoji_popover_content.hbs'); +var render_emoji_popover_search_results = require('../templates/emoji_popover_search_results.hbs'); +var render_emoji_showcase = require("../templates/emoji_showcase.hbs"); + var emoji_picker = (function () { var exports = {}; @@ -151,7 +156,7 @@ var generate_emoji_picker_content = function (id) { }); }); - return templates.render('emoji_popover_content', { + return render_emoji_popover_content({ message_id: id, emoji_categories: exports.complete_emoji_catalog, }); @@ -220,7 +225,7 @@ function filter_emojis() { }); }); }); - var rendered_search_results = templates.render('emoji_popover_search_results', { + var rendered_search_results = render_emoji_popover_search_results({ search_results: search_results, message_id: message_id, }); @@ -316,7 +321,7 @@ function update_emoji_showcase($focused_emoji) { var emoji_dict = _.extend({}, focused_emoji_dict, { name: focused_emoji_name.replace(/_/g, ' '), }); - var rendered_showcase = templates.render("emoji_showcase", { + var rendered_showcase = render_emoji_showcase({ emoji_dict: emoji_dict, }); @@ -578,7 +583,7 @@ exports.render_emoji_popover = function (elt, id) { placement = 'left'; } - var template = templates.render('emoji_popover', template_args); + var template = render_emoji_popover(template_args); // if the window is mobile sized, add the `.popover-flex` wrapper to the emoji // popover so that it will be wrapped in flex and centered in the screen. diff --git a/static/js/feedback_widget.js b/static/js/feedback_widget.js index f6bf8845bb..041eed57b4 100644 --- a/static/js/feedback_widget.js +++ b/static/js/feedback_widget.js @@ -1,3 +1,5 @@ +var render_feedback_container = require('../templates/feedback_container.hbs'); + var feedback_widget = (function () { var exports = {}; @@ -121,7 +123,7 @@ exports.show = function (opts) { meta.$container = $('#feedback_container'); - var html = templates.render('feedback_container'); + var html = render_feedback_container(); meta.$container.html(html); set_up_handlers(); diff --git a/static/js/hotspots.js b/static/js/hotspots.js index 956f831c9c..83ccc50f61 100644 --- a/static/js/hotspots.js +++ b/static/js/hotspots.js @@ -1,3 +1,6 @@ +var render_hotspot_overlay = require('../templates/hotspot_overlay.hbs'); +var render_intro_reply_hotspot = require('../templates/intro_reply_hotspot.hbs'); + var hotspots = (function () { var exports = {}; @@ -186,11 +189,11 @@ function place_popover(hotspot) { function insert_hotspot_into_DOM(hotspot) { if (hotspot.name === "intro_reply") { - $('#bottom_whitespace').append(templates.render('intro_reply_hotspot', {})); + $('#bottom_whitespace').append(render_intro_reply_hotspot({})); return; } - var hotspot_overlay_HTML = templates.render('hotspot_overlay', { + var hotspot_overlay_HTML = render_hotspot_overlay({ name: hotspot.name, title: hotspot.title, description: hotspot.description, diff --git a/static/js/input_pill.js b/static/js/input_pill.js index eebd15815d..a0a65afdcd 100644 --- a/static/js/input_pill.js +++ b/static/js/input_pill.js @@ -1,3 +1,5 @@ +var render_input_pill = require('../templates/input_pill.hbs'); + // See https://zulip.readthedocs.io/en/latest/subsystems/input-pills.html var input_pill = (function () { @@ -114,7 +116,7 @@ exports.create = function (opts) { opts.img_src = item.img_src; } - var pill_html = templates.render('input_pill', opts); + var pill_html = render_input_pill(opts); payload.$element = $(pill_html); store.$input.before(payload.$element); }, diff --git a/static/js/invite.js b/static/js/invite.js index 4a9ce192e2..edb9b4a5e4 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -1,3 +1,7 @@ +var render_invitation_failed_error = require("../templates/invitation_failed_error.hbs"); +var render_invite_subscription = require('../templates/invite_subscription.hbs'); +var render_settings_dev_env_email_access = require('../templates/settings/dev_env_email_access.hbs'); + var invite = (function () { var exports = {}; @@ -56,7 +60,7 @@ function submit_invitation_form() { invitee_emails.val(''); if (page_params.development_environment) { - var rendered_email_msg = templates.render('settings/dev_env_email_access'); + var rendered_email_msg = render_settings_dev_env_email_access(); $('#dev_env_msg').html(rendered_email_msg).addClass('alert-info').show(); } @@ -75,7 +79,7 @@ function submit_invitation_form() { invitee_emails_errored.push(value[0]); }); - var error_response = templates.render("invitation_failed_error", { + var error_response = render_invitation_failed_error({ error_message: arr.msg, error_list: error_list, }); @@ -128,7 +132,7 @@ exports.get_invite_streams = function () { function update_subscription_checkboxes() { var data = {streams: exports.get_invite_streams()}; - var html = templates.render('invite_subscription', data); + var html = render_invite_subscription(data); $('#streams_to_add').html(html); } diff --git a/static/js/loading.js b/static/js/loading.js index 6e5bab5a40..6e4a4d16c3 100644 --- a/static/js/loading.js +++ b/static/js/loading.js @@ -1,3 +1,5 @@ +var render_loader = require("../templates/loader.hbs"); + var loading = (function () { var exports = {}; @@ -29,7 +31,7 @@ exports.make_indicator = function (outer_container, opts) { } var spinner_elem = $('
'); - spinner_elem.html(templates.render("loader", { container_id: outer_container.attr("id") })); + spinner_elem.html(render_loader({ container_id: outer_container.attr("id") })); container.append(spinner_elem); var text_width = 0; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 57c0163c2b..8ecab101ae 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -1,3 +1,7 @@ +var render_message_edit_form = require('../templates/message_edit_form.hbs'); +var render_message_edit_history = require('../templates/message_edit_history.hbs'); +var render_topic_edit_form = require('../templates/topic_edit_form.hbs'); + var message_edit = (function () { var exports = {}; var currently_editing_messages = {}; @@ -281,17 +285,17 @@ function edit_message(row, raw_content) { file_upload_enabled = true; } - var form = $(templates.render( - 'message_edit_form', - {is_stream: message.type === 'stream', - message_id: message.id, - is_editable: is_editable, - is_content_editable: editability === message_edit.editability_types.FULL, - has_been_editable: editability !== editability_types.NO, - topic: util.get_message_topic(message), - content: raw_content, - file_upload_enabled: file_upload_enabled, - minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60)})); + var form = $(render_message_edit_form({ + is_stream: message.type === 'stream', + message_id: message.id, + is_editable: is_editable, + is_content_editable: editability === message_edit.editability_types.FULL, + has_been_editable: editability !== editability_types.NO, + topic: util.get_message_topic(message), + content: raw_content, + file_upload_enabled: file_upload_enabled, + minutes_to_edit: Math.floor(page_params.realm_message_content_edit_limit_seconds / 60), + })); var edit_obj = {form: form, raw_content: raw_content}; currently_editing_messages[message.id] = edit_obj; @@ -474,7 +478,7 @@ exports.start = function (row, edit_box_open_callback) { }; exports.start_topic_edit = function (recipient_row) { - var form = $(templates.render('topic_edit_form')); + var form = $(render_topic_edit_form()); current_msg_list.show_edit_topic(recipient_row, form); form.keydown(_.partial(handle_edit_keydown, true)); var msg_id = rows.id_for_recipient_row(recipient_row); @@ -608,7 +612,7 @@ exports.show_history = function (message) { content_edit_history.push(item); }); - $('#message-history').html(templates.render('message_edit_history', { + $('#message-history').html(render_message_edit_history({ edited_messages: content_edit_history, })); }, diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 224f2dc29c..aac40789c2 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -1,3 +1,8 @@ +var render_bookend = require('../templates/bookend.hbs'); +var render_message_group = require('../templates/message_group.hbs'); +var render_recipient_row = require('../templates/recipient_row.hbs'); +var render_single_message = require('../templates/single_message.hbs'); + function MessageListView(list, table_name, collapse_messages) { this.list = list; this.collapse_messages = collapse_messages; @@ -615,7 +620,7 @@ MessageListView.prototype = { var msg_to_render = _.extend(message_container, { table_name: this.table_name, }); - return templates.render('single_message', msg_to_render); + return render_single_message(msg_to_render); }, _render_group: function (opts) { @@ -623,7 +628,7 @@ MessageListView.prototype = { var use_match_properties = opts.use_match_properties; var table_name = opts.table_name; - return $(templates.render('message_group', { + return $(render_message_group({ message_groups: message_groups, use_match_properties: use_match_properties, table_name: table_name, @@ -1166,7 +1171,7 @@ MessageListView.prototype = { // rerendering rather than looking up the original version. populate_group_from_message_container(group, group.message_containers[0]); - var rendered_recipient_row = $(templates.render('recipient_row', group)); + var rendered_recipient_row = $(render_recipient_row(group)); header.replaceWith(rendered_recipient_row); }, @@ -1301,7 +1306,7 @@ MessageListView.prototype = { }, render_trailing_bookend: function (trailing_bookend_content, subscribed, show_button) { - var rendered_trailing_bookend = $(templates.render('bookend', { + var rendered_trailing_bookend = $(render_bookend({ bookend_content: trailing_bookend_content, trailing: show_button, subscribed: subscribed, diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js index 5edd237820..4f1a554373 100644 --- a/static/js/muting_ui.js +++ b/static/js/muting_ui.js @@ -1,3 +1,6 @@ +var render_muted_topic_ui_row = require('../templates/muted_topic_ui_row.hbs'); +var render_topic_muted = require('../templates/topic_muted.hbs'); + var muting_ui = (function () { var exports = {}; @@ -88,7 +91,7 @@ exports.set_up_muted_topics_ui = function (muted_topics) { topic: topic, }; - var row = templates.render('muted_topic_ui_row', template_data); + var row = render_muted_topic_ui_row(template_data); muted_topics_table.append(row); }); }; @@ -103,7 +106,7 @@ exports.mute = function (stream_id, topic) { exports.persist_mute(stream_id, topic); feedback_widget.show({ populate: function (container) { - var rendered_html = templates.render('topic_muted'); + var rendered_html = render_topic_muted(); container.html(rendered_html); container.find(".stream").text(stream_name); container.find(".topic").text(topic); diff --git a/static/js/notifications.js b/static/js/notifications.js index 5669a53dff..a814dca01a 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -1,3 +1,6 @@ +var render_compose_notification = require('../templates/compose_notification.hbs'); +var render_notification = require('../templates/notification.hbs'); + var notifications = (function () { var exports = {}; @@ -231,7 +234,7 @@ exports.window_has_focus = function () { }; function in_browser_notify(message, title, content, raw_operators, opts) { - var notification_html = $(templates.render('notification', { + var notification_html = $(render_notification({ gravatar_url: people.small_avatar_url(message), title: title, content: content, @@ -255,10 +258,12 @@ function in_browser_notify(message, title, content, raw_operators, opts) { } exports.notify_above_composebox = function (note, link_class, link_msg_id, link_text) { - var notification_html = $(templates.render('compose_notification', {note: note, - link_class: link_class, - link_msg_id: link_msg_id, - link_text: link_text})); + var notification_html = $(render_compose_notification({ + note: note, + link_class: link_class, + link_msg_id: link_msg_id, + link_text: link_text, + })); exports.clear_compose_notifications(); $('#out-of-view-notification').append(notification_html); $('#out-of-view-notification').show(); diff --git a/static/js/pm_list.js b/static/js/pm_list.js index b20f172eba..4607ce8d9f 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -1,3 +1,5 @@ +var render_sidebar_private_message_list = require('../templates/sidebar_private_message_list.hbs'); + var pm_list = (function () { var exports = {}; @@ -106,8 +108,9 @@ exports._build_private_messages_list = function (active_conversation) { display_messages.push(display_message); }); - var recipients_dom = templates.render('sidebar_private_message_list', - {messages: display_messages}); + var recipients_dom = render_sidebar_private_message_list({ + messages: display_messages, + }); return recipients_dom; }; diff --git a/static/js/poll_widget.js b/static/js/poll_widget.js index a628b0b4b9..daacdf721a 100644 --- a/static/js/poll_widget.js +++ b/static/js/poll_widget.js @@ -1,3 +1,6 @@ +var render_widgets_poll_widget = require('../templates/widgets/poll_widget.hbs'); +var render_widgets_poll_widget_results = require('../templates/widgets/poll_widget_results.hbs'); + var poll_widget = (function () { var exports = {}; @@ -285,7 +288,7 @@ exports.activate = function (opts) { } function build_widget() { - var html = templates.render('widgets/poll_widget'); + var html = render_widgets_poll_widget(); elem.html(html); elem.find('input.poll-question').on('keyup', function (e) { @@ -346,7 +349,7 @@ exports.activate = function (opts) { function render_results() { var widget_data = poll_data.get_widget_data(); - var html = templates.render('widgets/poll_widget_results', widget_data); + var html = render_widgets_poll_widget_results(widget_data); elem.find('ul.poll-widget').html(html); elem.find("button.poll-vote").off('click').on('click', function (e) { diff --git a/static/js/popovers.js b/static/js/popovers.js index 73b50af6f6..a01fff4dca 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -1,4 +1,14 @@ var confirmDatePlugin = require("flatpickr/dist/plugins/confirmDate/confirmDate.js"); +var render_actions_popover_content = require('../templates/actions_popover_content.hbs'); +var render_mobile_message_buttons_popover = require('../templates/mobile_message_buttons_popover.hbs'); +var render_mobile_message_buttons_popover_content = require('../templates/mobile_message_buttons_popover_content.hbs'); +var render_no_arrow_popover = require('../templates/no_arrow_popover.hbs'); +var render_remind_me_popover_content = require('../templates/remind_me_popover_content.hbs'); +var render_user_group_info_popover = require('../templates/user_group_info_popover.hbs'); +var render_user_group_info_popover_content = require('../templates/user_group_info_popover_content.hbs'); +var render_user_info_popover_content = require('../templates/user_info_popover_content.hbs'); +var render_user_info_popover_title = require('../templates/user_info_popover_title.hbs'); +var render_user_profile_modal = require("../templates/user_profile_modal.hbs"); var popovers = (function () { @@ -185,16 +195,17 @@ function render_user_info_popover(user, popover_element, is_sender_popover, priv } popover_element.popover({ - content: templates.render('user_info_popover_content', args), + content: render_user_info_popover_content(args), // TODO: Determine whether `fixed` should be applied // unconditionally. Right now, we only do it for the user // sidebar version of the popover. fixed: template_class === 'user_popover', placement: popover_placement, - template: templates.render('no_arrow_popover', {class: template_class}), - title: templates.render('user_info_popover_title', - {user_avatar: "avatar/" + user.email, - user_is_guest: user.is_guest}), + template: render_no_arrow_popover({class: template_class}), + title: render_user_info_popover_title({ + user_avatar: "avatar/" + user.email, + user_is_guest: user.is_guest, + }), trigger: "manual", top_offset: 100, fix_positions: true, @@ -251,8 +262,8 @@ function show_mobile_message_buttons_popover(element) { var $element = $(element); $element.popover({ placement: "left", - template: templates.render('mobile_message_buttons_popover'), - content: templates.render('mobile_message_buttons_popover_content', { + template: render_mobile_message_buttons_popover(), + content: render_mobile_message_buttons_popover_content({ is_in_private_narrow: narrow_state.narrowed_to_pms(), }), trigger: "manual", @@ -296,7 +307,7 @@ exports.show_user_profile = function (user) { user_is_guest: user.is_guest, }; - $("#user-profile-modal-holder").html(templates.render("user_profile_modal", args)); + $("#user-profile-modal-holder").html(render_user_profile_modal(args)); $("#user-profile-modal").modal("show"); settings_account.initialize_custom_user_type_fields("#user-profile-modal #content", user.user_id, false, false); @@ -370,8 +381,8 @@ function show_user_group_info_popover(element, group, message) { }; elt.popover({ placement: calculate_info_popover_placement(popover_size, elt), - template: templates.render('user_group_info_popover', {class: "message-info-popover"}), - content: templates.render('user_group_info_popover_content', args), + template: render_user_group_info_popover({class: "message-info-popover"}), + content: render_user_group_info_popover_content(args), trigger: "manual", }); elt.popover("show"); @@ -469,7 +480,7 @@ exports.toggle_actions_popover = function (element, id) { // Popover height with 7 items in it is ~190 px placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom', title: "", - content: templates.render('actions_popover_content', args), + content: render_actions_popover_content(args), trigger: "manual", }); elt.popover("show"); @@ -492,7 +503,7 @@ exports.render_actions_remind_popover = function (element, id) { // Popover height with 7 items in it is ~190 px placement: message_viewport.height() - ypos < 220 ? 'top' : 'bottom', title: "", - content: templates.render('remind_me_popover_content', args), + content: render_remind_me_popover_content(args), trigger: "manual", }); elt.popover("show"); diff --git a/static/js/reactions.js b/static/js/reactions.js index 0c361670f9..f5171a5554 100644 --- a/static/js/reactions.js +++ b/static/js/reactions.js @@ -1,3 +1,4 @@ +var render_message_reaction = require('../templates/message_reaction.hbs'); var Dict = require('./dict').Dict; var reactions = (function () { @@ -292,7 +293,7 @@ exports.view.insert_new_reaction = function (opts) { context.class = "message_reaction"; } - var new_reaction = $(templates.render('message_reaction', context)); + var new_reaction = $(render_message_reaction(context)); // Now insert it before the add button. var reaction_button_element = exports.get_add_reaction_button(message_id); diff --git a/static/js/settings.js b/static/js/settings.js index ee60241131..ace67ff35d 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -1,3 +1,5 @@ +var render_settings_tab = require('../templates/settings_tab.hbs'); + var settings = (function () { var exports = {}; @@ -121,7 +123,7 @@ function setup_settings_label() { exports.build_page = function () { setup_settings_label(); - var rendered_settings_tab = templates.render('settings_tab', { + var rendered_settings_tab = render_settings_tab({ full_name: people.my_full_name(), page_params: page_params, enable_sound_select: page_params.enable_sounds || diff --git a/static/js/settings_account.js b/static/js/settings_account.js index 93b4c95712..86d65ee693 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -1,3 +1,6 @@ +var render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs"); +var render_settings_dev_env_email_access = require('../templates/settings/dev_env_email_access.hbs'); + var settings_account = (function () { var exports = {}; @@ -110,7 +113,7 @@ exports.append_custom_profile_fields = function (element_id, user_id) { } } - var html = templates.render("settings/custom_user_profile_field", { + var html = render_settings_custom_user_profile_field({ field: field, field_type: all_field_template_types[field.type], field_value: field_value, @@ -395,7 +398,7 @@ exports.set_up = function () { var opts = { success_continuation: function () { if (page_params.development_environment) { - var email_msg = templates.render('settings/dev_env_email_access'); + var email_msg = render_settings_dev_env_email_access(); ui_report.success(email_msg, $("#dev-account-settings-status").expectOne(), 4000); } overlays.close_modal('change_email_modal'); diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js index f13ba21eee..19539c25ac 100644 --- a/static/js/settings_bots.js +++ b/static/js/settings_bots.js @@ -1,3 +1,8 @@ +var render_bot_avatar_row = require('../templates/bot_avatar_row.hbs'); +var render_edit_bot = require('../templates/edit_bot.hbs'); +var render_settings_edit_embedded_bot_service = require("../templates/settings/edit_embedded_bot_service.hbs"); +var render_settings_edit_outgoing_webhook_service = require("../templates/settings/edit_outgoing_webhook_service.hbs"); + var settings_bots = (function () { var exports = {}; @@ -49,7 +54,7 @@ exports.bot_error = function (bot_id, xhr) { }; function add_bot_row(info) { - var row = $(templates.render('bot_avatar_row', info)); + var row = $(render_bot_avatar_row(info)); if (info.is_active) { $('#active_bots_list').append(row); } else { @@ -391,8 +396,10 @@ exports.set_up = function () { var bot = bot_data.get(bot_id); var users_list = people.get_active_human_persons(); $("#edit_bot").empty(); - $("#edit_bot").append(templates.render('edit_bot', {bot: bot, - users_list: users_list})); + $("#edit_bot").append(render_edit_bot({ + bot: bot, + users_list: users_list, + })); var avatar_widget = avatar.build_bot_edit_widget($("#settings_page")); var form = $('#settings_page .edit_bot_form'); var image = li.find(".image"); @@ -401,13 +408,15 @@ exports.set_up = function () { $("#settings_page .edit_bot .edit-bot-owner select").val(bot.owner); var service = bot_data.get_services(bot_id)[0]; if (bot.bot_type.toString() === OUTGOING_WEBHOOK_BOT_TYPE) { - $("#service_data").append(templates.render("settings/edit_outgoing_webhook_service", - {service: service})); + $("#service_data").append(render_settings_edit_outgoing_webhook_service({ + service: service, + })); $("#edit_service_interface").val(service.interface); } if (bot.bot_type.toString() === EMBEDDED_BOT_TYPE) { - $("#service_data").append(templates.render("settings/edit_embedded_bot_service", - {service: service})); + $("#service_data").append(render_settings_edit_embedded_bot_service({ + service: service, + })); } avatar_widget.clear(); diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index 9a57610bd5..8c310c98fe 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -1,3 +1,6 @@ +var render_admin_emoji_list = require('../templates/admin_emoji_list.hbs'); +var render_settings_emoji_settings_tip = require("../templates/settings/emoji_settings_tip.hbs"); + var settings_emoji = (function () { var exports = {}; @@ -34,7 +37,7 @@ function can_admin_emoji(emoji) { } exports.update_custom_emoji_ui = function () { - var rendered_tip = templates.render("settings/emoji_settings_tip", { + var rendered_tip = render_settings_emoji_settings_tip({ realm_add_emoji_by_admins_only: page_params.realm_add_emoji_by_admins_only, }); $('#emoji-settings').find('.emoji-settings-tip-container').html(rendered_tip); @@ -62,7 +65,7 @@ exports.populate_emoji = function (emoji_data) { emoji_table.find('tr.emoji_row').remove(); _.each(emoji_data, function (data) { if (data.deactivated !== true) { - emoji_table.append(templates.render('admin_emoji_list', { + emoji_table.append(render_admin_emoji_list({ emoji: { name: data.name, display_name: data.name.replace(/_/g, ' '), diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js index 855707fa9b..05b492a98a 100644 --- a/static/js/settings_invites.js +++ b/static/js/settings_invites.js @@ -1,3 +1,6 @@ +var render_admin_invites_list = require("../templates/admin_invites_list.hbs"); +var render_settings_revoke_invite_modal = require("../templates/settings/revoke_invite_modal.hbs"); + var settings_invites = (function () { var exports = {}; @@ -60,7 +63,7 @@ function populate_invites(invites_data) { name: "admin_invites_list", modifier: function (item) { item.invited_absolute_time = timerender.absolute_time(item.invited * 1000); - return templates.render("admin_invites_list", { invite: item }); + return render_admin_invites_list({ invite: item }); }, filter: { element: invites_table.closest(".settings-section").find(".search"), @@ -146,7 +149,7 @@ exports.on_load_success = function (invites_data, initialize_event_handlers) { meta.invite_id = $(e.currentTarget).attr("data-invite-id"); meta.is_multiuse = $(e.currentTarget).attr("data-is-multiuse"); var ctx = {is_multiuse: meta.is_multiuse === "true", email: email, referred_by: referred_by}; - var rendered_revoke_modal = templates.render("settings/revoke_invite_modal", ctx); + var rendered_revoke_modal = render_settings_revoke_invite_modal(ctx); $("#revoke_invite_modal_holder").html(rendered_revoke_modal); $("#revoke_invite_modal #do_revoke_invite_button").attr("data-invite-id", meta.invite_id); $("#revoke_invite_modal #do_revoke_invite_button").attr("data-is-multiuse", meta.is_multiuse); diff --git a/static/js/settings_linkifiers.js b/static/js/settings_linkifiers.js index ea8ba80d1a..266926f323 100644 --- a/static/js/settings_linkifiers.js +++ b/static/js/settings_linkifiers.js @@ -1,3 +1,5 @@ +var render_admin_filter_list = require("../templates/admin_filter_list.hbs"); + var settings_linkifiers = (function () { var exports = {}; @@ -28,16 +30,14 @@ exports.populate_filters = function (filters_data) { filters_table.find("tr.filter_row").remove(); _.each(filters_data, function (filter) { filters_table.append( - templates.render( - "admin_filter_list", { - filter: { - pattern: filter[0], - url_format_string: filter[1], - id: filter[2], - }, - can_modify: page_params.is_admin, - } - ) + render_admin_filter_list({ + filter: { + pattern: filter[0], + url_format_string: filter[1], + id: filter[2], + }, + can_modify: page_params.is_admin, + }) ); }); loading.destroy_indicator($('#admin_page_filters_loading_indicator')); diff --git a/static/js/settings_org.js b/static/js/settings_org.js index d76020faf1..afa142101b 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -1,3 +1,8 @@ +var render_settings_admin_auth_methods_list = require('../templates/settings/admin_auth_methods_list.hbs'); +var render_settings_admin_realm_domains_list = require("../templates/settings/admin_realm_domains_list.hbs"); +var render_settings_admin_realm_dropdown_stream_list = require("../templates/settings/admin_realm_dropdown_stream_list.hbs"); +var render_settings_organization_settings_tip = require("../templates/settings/organization_settings_tip.hbs"); + var settings_org = (function () { var exports = {}; @@ -325,7 +330,11 @@ exports.populate_realm_domains = function (realm_domains) { var realm_domains_table_body = $("#realm_domains_table tbody").expectOne(); realm_domains_table_body.find("tr").remove(); _.each(realm_domains, function (realm_domain) { - realm_domains_table_body.append(templates.render("settings/admin_realm_domains_list", {realm_domain: realm_domain})); + realm_domains_table_body.append( + render_settings_admin_realm_domains_list({ + realm_domain: realm_domain, + }) + ); }); }; function sort_object_by_key(obj) { @@ -344,7 +353,7 @@ exports.populate_auth_methods = function (auth_methods) { auth_methods = sort_object_by_key(auth_methods); var rendered_auth_method_rows = ""; _.each(auth_methods, function (value, auth_method) { - rendered_auth_method_rows += templates.render('settings/admin_auth_methods_list', { + rendered_auth_method_rows += render_settings_admin_auth_methods_list({ method: auth_method, enabled: value, is_admin: page_params.is_admin, @@ -357,7 +366,7 @@ function insert_tip_box() { if (page_params.is_admin) { return; } - var tip_box = templates.render("settings/organization_settings_tip", {is_admin: page_params.is_admin}); + var tip_box = render_settings_organization_settings_tip({is_admin: page_params.is_admin}); $(".organization-box").find(".settings-section:not(.can-edit)") .not("#emoji-settings") .not("#user-groups-admin") @@ -388,7 +397,7 @@ exports.populate_notifications_stream_dropdown = function (stream_list) { list_render.create(dropdown_list_body, stream_list, { name: "admin-realm-notifications-stream-dropdown-list", modifier: function (item) { - return templates.render("settings/admin_realm_dropdown_stream_list", { stream: item }); + return render_settings_admin_realm_dropdown_stream_list({ stream: item }); }, filter: { element: search_input, @@ -417,7 +426,7 @@ exports.populate_signup_notifications_stream_dropdown = function (stream_list) { list_render.create(dropdown_list_body, stream_list, { name: "admin-realm-signup-notifications-stream-dropdown-list", modifier: function (item) { - return templates.render("settings/admin_realm_dropdown_stream_list", { stream: item }); + return render_settings_admin_realm_dropdown_stream_list({ stream: item }); }, filter: { element: search_input, diff --git a/static/js/settings_profile_fields.js b/static/js/settings_profile_fields.js index 2962bc8ee1..b518326ef3 100644 --- a/static/js/settings_profile_fields.js +++ b/static/js/settings_profile_fields.js @@ -1,3 +1,6 @@ +var render_admin_profile_field_list = require("../templates/admin_profile_field_list.hbs"); +var render_settings_profile_field_choice = require("../templates/settings/profile_field_choice.hbs"); + var settings_profile_fields = (function () { var exports = {}; @@ -101,7 +104,7 @@ function update_choice_delete_btn(container, display_flag) { function create_choice_row(container) { var context = {}; - var row = templates.render("settings/profile_field_choice", context); + var row = render_settings_profile_field_choice(context); $(container).append(row); } @@ -221,7 +224,7 @@ function set_up_choices_field_edit_form(profile_field, field_data) { _.each(choices_data, function (choice) { choice_list.append( - templates.render("settings/profile_field_choice", { + render_settings_profile_field_choice({ text: choice.text, }) ); @@ -333,22 +336,20 @@ exports.do_populate_profile_fields = function (profile_fields_data) { } profile_fields_table.append( - templates.render( - "admin_profile_field_list", { - profile_field: { - id: profile_field.id, - name: profile_field.name, - hint: profile_field.hint, - type: exports.field_type_id_to_string(profile_field.type), - choices: choices, - is_choice_field: profile_field.type === field_types.CHOICE.id, - is_external_account_field: profile_field.type === - field_types.EXTERNAL_ACCOUNT.id, - }, - can_modify: page_params.is_admin, - realm_default_external_accounts: page_params.realm_default_external_accounts, - } - ) + render_admin_profile_field_list({ + profile_field: { + id: profile_field.id, + name: profile_field.name, + hint: profile_field.hint, + type: exports.field_type_id_to_string(profile_field.type), + choices: choices, + is_choice_field: profile_field.type === field_types.CHOICE.id, + is_external_account_field: profile_field.type === + field_types.EXTERNAL_ACCOUNT.id, + }, + can_modify: page_params.is_admin, + realm_default_external_accounts: page_params.realm_default_external_accounts, + }) ); }); if (page_params.is_admin) { diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index 63c3cf9e9d..4e3e7f05ae 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -1,3 +1,4 @@ +var render_admin_default_streams_list = require("../templates/admin_default_streams_list.hbs"); var Dict = require('./dict').Dict; var settings_streams = (function () { @@ -31,7 +32,10 @@ exports.build_default_stream_table = function (streams_data) { list_render.create(table, streams_data, { name: "default_streams_list", modifier: function (item) { - var row = $(templates.render("admin_default_streams_list", { stream: item, can_modify: page_params.is_admin })); + var row = $(render_admin_default_streams_list({ + stream: item, + can_modify: page_params.is_admin, + })); self.row_dict.set(item.stream_id, row); return row; }, diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js index 7582d5446a..cd52185917 100644 --- a/static/js/settings_user_groups.js +++ b/static/js/settings_user_groups.js @@ -1,3 +1,6 @@ +var render_admin_user_group_list = require('../templates/admin_user_group_list.hbs'); +var render_confirm_delete_user = require('../templates/confirm_delete_user.hbs'); + var settings_user_groups = (function () { var exports = {}; @@ -37,7 +40,7 @@ exports.populate_user_groups = function () { var user_groups_section = $('#user-groups').expectOne(); var user_groups_array = user_groups.get_realm_user_groups(); _.each(user_groups_array, function (data) { - user_groups_section.append(templates.render('admin_user_group_list', { + user_groups_section.append(render_admin_user_group_list({ user_group: { name: data.name, id: data.id, @@ -319,7 +322,7 @@ exports.set_up = function () { // This is mostly important for styling concerns. var modal_parent = $('#settings_content'); - var html_body = templates.render('confirm_delete_user', { + var html_body = render_confirm_delete_user({ group_name: user_group.name, }); diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 2049d89ebd..78a867469e 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -1,3 +1,7 @@ +var render_admin_user_list = require("../templates/admin_user_list.hbs"); +var render_bot_owner_select = require("../templates/bot_owner_select.hbs"); +var render_user_info_form_modal = require('../templates/user_info_form_modal.hbs'); + var settings_users = (function () { var exports = {}; @@ -132,7 +136,7 @@ function populate_users(realm_people_data) { list_render.create($bots_table, bots, { name: "admin_bot_list", modifier: function (item) { - return templates.render("admin_user_list", { user: item, can_modify: page_params.is_admin }); + return render_admin_user_list({ user: item, can_modify: page_params.is_admin }); }, filter: { element: $bots_table.closest(".settings-section").find(".search"), @@ -168,7 +172,7 @@ function populate_users(realm_people_data) { activity_rendered = $("").text(i18n.t("Unknown")); } - var $row = $(templates.render("admin_user_list", { + var $row = $(render_admin_user_list({ user: item, can_modify: page_params.is_admin, is_current_user: people.is_my_user_id(item.user_id), @@ -198,7 +202,7 @@ function populate_users(realm_people_data) { list_render.create($deactivated_users_table, deactivated_users, { name: "deactivated_users_table_list", modifier: function (item) { - return templates.render("admin_user_list", { user: item, can_modify: page_params.is_admin }); + return render_admin_user_list({ user: item, can_modify: page_params.is_admin }); }, filter: { element: $deactivated_users_table.closest(".settings-section").find(".search"), @@ -244,7 +248,7 @@ exports.set_up = function () { }; function open_user_info_form_modal(person) { - var html = templates.render('user_info_form_modal', { + var html = render_user_info_form_modal({ user_id: person.user_id, email: person.email, full_name: people.get_full_name(person.user_id), @@ -262,7 +266,7 @@ function open_user_info_form_modal(person) { // Dynamically add the owner select control in order to // avoid performance issues in case of large number of users. var users_list = people.get_active_human_persons(); - var owner_select = $(templates.render("bot_owner_select", {users_list: users_list})); + var owner_select = $(render_bot_owner_select({users_list: users_list})); owner_select.val(bot_data.get(person.user_id).owner || ""); modal_container.find(".edit_bot_owner_container").append(owner_select); } diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 6af53453ee..35873430dc 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -1,3 +1,7 @@ +var render_announce_stream_docs = require('../templates/announce_stream_docs.hbs'); +var render_new_stream_users = require('../templates/new_stream_users.hbs'); +var render_subscription_invites_warning_modal = require('../templates/subscription_invites_warning_modal.hbs'); + var stream_create = (function () { var exports = {}; @@ -257,7 +261,7 @@ exports.show_new_stream_modal = function () { var all_users = people.get_rest_of_realm(); // Add current user on top of list all_users.unshift(people.get_person_from_user_id(page_params.user_id)); - var html = templates.render('new_stream_users', { + var html = render_new_stream_users({ users: all_users, streams: stream_data.get_streams_for_settings_page(), is_admin: page_params.is_admin, @@ -403,9 +407,10 @@ exports.set_up_handlers = function () { } if (principals.length >= 50) { - var invites_warning_modal = templates.render('subscription_invites_warning_modal', - {stream_name: stream_name, - count: principals.length}); + var invites_warning_modal = render_subscription_invites_warning_modal({ + stream_name: stream_name, + count: principals.length, + }); $('#stream-creation').append(invites_warning_modal); } else { create_stream(); @@ -432,7 +437,7 @@ exports.set_up_handlers = function () { var announce_stream_docs = $("#announce-stream-docs"); announce_stream_docs.popover({ placement: "right", - content: templates.render('announce_stream_docs', { + content: render_announce_stream_docs({ notifications_stream: page_params.notifications_stream}), trigger: "manual"}); announce_stream_docs.popover('show'); diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 459c864e23..5c4d1657d1 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -1,3 +1,8 @@ +var render_settings_deactivation_stream_modal = require("../templates/settings/deactivation_stream_modal.hbs"); +var render_stream_member_list_entry = require('../templates/stream_member_list_entry.hbs'); +var render_subscription_settings = require('../templates/subscription_settings.hbs'); +var render_subscription_stream_privacy_modal = require("../templates/subscription_stream_privacy_modal.hbs"); + var stream_edit = (function () { var exports = {}; @@ -90,9 +95,10 @@ exports.open_edit_panel_empty = function () { function format_member_list_elem(email) { var person = people.get_by_email(email); - return templates.render('stream_member_list_entry', - {name: person.full_name, email: email, - displaying_for_admin: page_params.is_admin}); + return render_stream_member_list_entry({ + name: person.full_name, email: email, + displaying_for_admin: page_params.is_admin, + }); } function get_subscriber_list(sub_row) { @@ -268,7 +274,7 @@ exports.show_settings_for = function (node) { var sub = stream_data.get_sub_by_id(stream_id); stream_data.update_calculated_fields(sub); - var html = templates.render('subscription_settings', { + var html = render_subscription_settings({ sub: sub, settings: exports.stream_settings(sub), realm_settings: check_realm_setting, @@ -493,7 +499,7 @@ exports.initialize = function () { stream.history_public_to_subscribers, is_admin: page_params.is_admin, }; - var change_privacy_modal = templates.render("subscription_stream_privacy_modal", template_data); + var change_privacy_modal = render_subscription_stream_privacy_modal(template_data); $("#stream_privacy_modal").remove(); $("#subscriptions_table").append(change_privacy_modal); overlays.open_modal('stream_privacy_modal'); @@ -617,7 +623,7 @@ exports.initialize = function () { return; } var stream_name = stream_data.maybe_get_stream_name(stream_id); - var deactivate_stream_modal = templates.render("settings/deactivation_stream_modal", { + var deactivate_stream_modal = render_settings_deactivation_stream_modal({ stream_name: stream_name, stream_id: stream_id, }); diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 4a59b00357..9a8f50dabd 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -1,3 +1,5 @@ +var render_stream_privacy = require('../templates/stream_privacy.hbs'); +var render_stream_sidebar_row = require('../templates/stream_sidebar_row.hbs'); var Dict = require('./dict').Dict; var stream_list = (function () { @@ -222,7 +224,7 @@ function build_stream_sidebar_li(sub) { pin_to_top: sub.pin_to_top, }; args.dark_background = stream_color.get_color_class(args.color); - var list_item = $(templates.render('stream_sidebar_row', args)); + var list_item = $(render_stream_sidebar_row(args)); return list_item; } @@ -283,7 +285,7 @@ exports.redraw_stream_privacy = function (sub) { dark_background: dark_background, }; - var html = templates.render('stream_privacy', args); + var html = render_stream_privacy(args); div.html(html); }; diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js index 74e782838c..5742d35e29 100644 --- a/static/js/stream_popover.js +++ b/static/js/stream_popover.js @@ -1,3 +1,10 @@ +var render_all_messages_sidebar_actions = require('../templates/all_messages_sidebar_actions.hbs'); +var render_delete_topic_modal = require('../templates/delete_topic_modal.hbs'); +var render_starred_messages_sidebar_actions = require('../templates/starred_messages_sidebar_actions.hbs'); +var render_stream_sidebar_actions = require('../templates/stream_sidebar_actions.hbs'); +var render_topic_sidebar_actions = require('../templates/topic_sidebar_actions.hbs'); +var render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs"); + var stream_popover = (function () { var exports = {}; @@ -120,10 +127,9 @@ function build_stream_popover(opts) { popovers.hide_all(); exports.show_streamlist_sidebar(); - var content = templates.render( - 'stream_sidebar_actions', - {stream: stream_data.get_sub_by_id(stream_id)} - ); + var content = render_stream_sidebar_actions({ + stream: stream_data.get_sub_by_id(stream_id), + }); $(elt).popover({ content: content, @@ -167,7 +173,7 @@ function build_topic_popover(opts) { var can_mute_topic = !is_muted; var can_unmute_topic = is_muted; - var content = templates.render('topic_sidebar_actions', { + var content = render_topic_sidebar_actions({ stream_name: sub.name, stream_id: sub.stream_id, topic_name: topic_name, @@ -199,9 +205,7 @@ function build_all_messages_popover(e) { popovers.hide_all(); - var content = templates.render( - 'all_messages_sidebar_actions' - ); + var content = render_all_messages_sidebar_actions(); $(elt).popover({ content: content, @@ -227,10 +231,9 @@ function build_starred_messages_popover(e) { popovers.hide_all(); - var content = templates.render( - 'starred_messages_sidebar_actions', - {starred_message_counts: page_params.starred_message_counts} - ); + var content = render_starred_messages_sidebar_actions({ + starred_message_counts: page_params.starred_message_counts, + }); $(elt).popover({ content: content, @@ -318,7 +321,7 @@ exports.register_stream_handlers = function () { e.preventDefault(); e.stopPropagation(); $(".left-sidebar-modal-holder").empty(); - $(".left-sidebar-modal-holder").html(templates.render("unstar_messages_modal")); + $(".left-sidebar-modal-holder").html(render_unstar_messages_modal()); $("#unstar-messages-modal").modal("show"); }); @@ -478,7 +481,7 @@ exports.register_topic_handlers = function () { exports.hide_topic_popover(); - $('#delete-topic-modal-holder').html(templates.render('delete_topic_modal', args)); + $('#delete-topic-modal-holder').html(render_delete_topic_modal(args)); $('#do_delete_topic_button').on('click', function () { message_edit.delete_topic(stream_id, topic); diff --git a/static/js/stream_ui_updates.js b/static/js/stream_ui_updates.js index 41f93d7957..73b08e5b50 100644 --- a/static/js/stream_ui_updates.js +++ b/static/js/stream_ui_updates.js @@ -1,3 +1,7 @@ +var render_subscription_count = require("../templates/subscription_count.hbs"); +var render_subscription_setting_icon = require('../templates/subscription_setting_icon.hbs'); +var render_subscription_type = require('../templates/subscription_type.hbs'); + var stream_ui_updates = (function () { var exports = {}; @@ -115,7 +119,7 @@ exports.update_stream_row_in_settings_tab = function (sub) { exports.update_stream_privacy_type_icon = function (sub) { var stream_settings = stream_edit.settings_for_sub(sub); var sub_row = subs.row_for_stream_id(sub.stream_id); - var html = templates.render('subscription_setting_icon', sub); + var html = render_subscription_setting_icon(sub); if (overlays.streams_open()) { sub_row.find('.icon').expectOne().replaceWith($(html)); @@ -133,7 +137,7 @@ exports.update_stream_privacy_type_icon = function (sub) { exports.update_stream_privacy_type_text = function (sub) { var stream_settings = stream_edit.settings_for_sub(sub); - var html = templates.render('subscription_type', sub); + var html = render_subscription_type(sub); if (stream_edit.is_sub_settings_active(sub)) { stream_settings.find('.subscription-type-text').expectOne().html(html); } @@ -146,7 +150,7 @@ exports.update_subscribers_count = function (sub, just_subscribed) { } var stream_row = subs.row_for_stream_id(sub.stream_id); if (!sub.can_access_subscribers || just_subscribed && sub.invite_only || page_params.is_guest) { - var rendered_sub_count = templates.render("subscription_count", sub); + var rendered_sub_count = render_subscription_count(sub); stream_row.find('.subscriber-count').expectOne().html(rendered_sub_count); } else { stream_row.find(".subscriber-count-text").expectOne().text(sub.subscriber_count); diff --git a/static/js/subs.js b/static/js/subs.js index d5812fe8f1..e4ede418cc 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -1,3 +1,9 @@ +var render_email_address_hint = require('../templates/email_address_hint.hbs'); +var render_subscription = require('../templates/subscription.hbs'); +var render_subscription_settings = require('../templates/subscription_settings.hbs'); +var render_subscription_table_body = require('../templates/subscription_table_body.hbs'); +var render_subscriptions = require('../templates/subscriptions.hbs'); + var subs = (function () { var exports = {}; @@ -199,7 +205,7 @@ function add_email_hint_handler() { // Add a popover explaining stream e-mail addresses on hover. $("body").on("mouseover", '.stream-email-hint', function (e) { - var email_address_hint_content = templates.render('email_address_hint', { page_params: page_params }); + var email_address_hint_content = render_email_address_hint({ page_params: page_params }); $(e.target).popover({ placement: "right", title: "Email integration", @@ -227,8 +233,8 @@ exports.add_sub_to_table = function (sub) { return; } - var html = templates.render('subscription', sub); - var settings_html = templates.render('subscription_settings', sub); + var html = render_subscription(sub); + var settings_html = render_subscription_settings(sub); if (stream_create.get_name() === sub.name) { ui.get_content_element($(".streams-list")).prepend(html); ui.reset_scrollbar($(".streams-list")); @@ -393,7 +399,7 @@ exports.populate_stream_settings_left_panel = function () { var template_data = { subscriptions: sub_rows, }; - var html = templates.render('subscriptions', template_data); + var html = render_subscriptions(template_data); ui.get_content_element($('#subscriptions_table .streams-list')).html(html); }; @@ -550,7 +556,7 @@ exports.setup_page = function (callback) { is_admin: page_params.is_admin, }; - var rendered = templates.render('subscription_table_body', template_data); + var rendered = render_subscription_table_body(template_data); $('#subscriptions_table').append(rendered); exports.populate_stream_settings_left_panel(); diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index 8b9b7b9361..688d0fde5f 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -1,3 +1,5 @@ +var render_tab_bar = require('../templates/tab_bar.hbs'); + var tab_bar = (function () { var exports = {}; @@ -158,7 +160,7 @@ function build_tab_bar() { tab_bar.empty(); tabs[tabs.length - 1].active = "active"; - var rendered = templates.render('tab_bar', {tabs: tabs}); + var rendered = render_tab_bar({tabs: tabs}); tab_bar.append(rendered); exports.colorize_tab_bar(); diff --git a/static/js/templates.js b/static/js/templates.js index 0dfcf08211..58a2c62233 100644 --- a/static/js/templates.js +++ b/static/js/templates.js @@ -2,18 +2,6 @@ var templates = (function () { var exports = {}; -exports.render = function (name, arg) { - var template; - try { - template = require('../templates/' + name + '.hbs'); - } catch (_e) { - throw new Error('Cannot find template static/templates/' + name - + '.hbs.'); - } - - return template(arg); -}; - // Below, we register Zulip-specific extensions to the handlebars API. // // IMPORTANT: When adding a new handlebars helper, update the @@ -40,7 +28,7 @@ Handlebars.registerHelper('partial', function (template_name) { } var data = _.extend({}, this, extra_data); - return new Handlebars.SafeString(exports.render(template_name, data)); + return new Handlebars.SafeString(require('../templates/' + template_name + '.hbs')(data)); }); Handlebars.registerHelper('plural', function (condition, one, other) { diff --git a/static/js/tictactoe_widget.js b/static/js/tictactoe_widget.js index 333a956a7c..da32e429cf 100644 --- a/static/js/tictactoe_widget.js +++ b/static/js/tictactoe_widget.js @@ -1,3 +1,5 @@ +var render_widgets_tictactoe_widget = require('../templates/widgets/tictactoe_widget.hbs'); + var tictactoe_widget = (function () { var exports = {}; @@ -127,7 +129,7 @@ exports.activate = function (opts) { function render() { var widget_data = tictactoe_data.get_widget_data(); - var html = templates.render('widgets/tictactoe_widget', widget_data); + var html = render_widgets_tictactoe_widget(widget_data); elem.html(html); elem.find("button.tictactoe-square").on('click', function (e) { diff --git a/static/js/todo_widget.js b/static/js/todo_widget.js index e129eaae29..ec8134954f 100644 --- a/static/js/todo_widget.js +++ b/static/js/todo_widget.js @@ -1,3 +1,6 @@ +var render_widgets_todo_widget = require('../templates/widgets/todo_widget.hbs'); +var render_widgets_todo_widget_tasks = require('../templates/widgets/todo_widget_tasks.hbs'); + var todo_widget = (function () { var exports = {}; @@ -122,7 +125,7 @@ exports.activate = function (opts) { var task_data = exports.task_data_holder(); function render() { - var html = templates.render('widgets/todo_widget'); + var html = render_widgets_todo_widget(); elem.html(html); elem.find("button.add-task").on('click', function (e) { @@ -149,7 +152,7 @@ exports.activate = function (opts) { function render_results() { var widget_data = task_data.get_widget_data(); - var html = templates.render('widgets/todo_widget_tasks', widget_data); + var html = render_widgets_todo_widget_tasks(widget_data); elem.find('ul.todo-widget').html(html); elem.find(".widget-error").text(''); diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 5135e1a70d..2b0da9616c 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -1,3 +1,5 @@ +var render_more_topics = require('../templates/more_topics.hbs'); +var render_topic_list_item = require('../templates/topic_list_item.hbs'); var Dict = require('./dict').Dict; var topic_list = (function () { @@ -113,7 +115,7 @@ exports.widget = function (parent_elem, my_stream_id) { is_muted: muting.is_topic_muted(my_stream_id, topic_name), url: hash_util.by_stream_topic_uri(my_stream_id, topic_name), }; - var li = $(templates.render('topic_list_item', topic_info)); + var li = $(render_topic_list_item(topic_info)); self.topic_items.set(topic_name, li); ul.append(li); }); @@ -132,7 +134,7 @@ exports.widget = function (parent_elem, my_stream_id) { }; self.build_more_topics_section = function () { - var show_more_html = templates.render('more_topics'); + var show_more_html = render_more_topics(); return $(show_more_html); }; diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 39a5e4e070..1a72480c87 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -1,3 +1,4 @@ +var render_typeahead_list_item = require('../templates/typeahead_list_item.hbs'); var Dict = require('./dict').Dict; var typeahead_helper = (function () { @@ -74,7 +75,7 @@ exports.highlight_query_in_phrase = function (query, phrase) { exports.render_typeahead_item = function (args) { args.has_image = args.img_src !== undefined; args.has_secondary = args.secondary !== undefined; - return templates.render('typeahead_list_item', args); + return render_typeahead_list_item(args); }; var rendered = { persons: new Dict(), streams: new Dict(), user_groups: new Dict() }; diff --git a/static/js/typing_events.js b/static/js/typing_events.js index d417601619..fcef921b2b 100644 --- a/static/js/typing_events.js +++ b/static/js/typing_events.js @@ -1,3 +1,5 @@ +var render_typing_notifications = require('../templates/typing_notifications.hbs'); + var typing_events = (function () { var exports = {}; @@ -47,7 +49,7 @@ exports.render_notifications_for_narrow = function () { if (users_typing.length === 0) { $('#typing_notifications').hide(); } else { - $('#typing_notifications').html(templates.render('typing_notifications', {users: users_typing})); + $('#typing_notifications').html(render_typing_notifications({users: users_typing})); $('#typing_notifications').show(); } }; diff --git a/static/js/unread_ui.js b/static/js/unread_ui.js index 1ac4e076d8..d0023f0232 100644 --- a/static/js/unread_ui.js +++ b/static/js/unread_ui.js @@ -1,3 +1,5 @@ +var render_bankruptcy_modal = require('../templates/bankruptcy_modal.hbs'); + var unread_ui = (function () { var exports = {}; @@ -81,7 +83,7 @@ function consider_bankruptcy() { var now = new XDate(true).getTime() / 1000; if (page_params.unread_msgs.count > 500 && now - page_params.furthest_read_time > 60 * 60 * 24 * 2) { // 2 days. - var rendered_modal = templates.render('bankruptcy_modal', { + var rendered_modal = render_bankruptcy_modal({ unread_count: page_params.unread_msgs.count}); $('#bankruptcy-unread-count').html(rendered_modal); $('#bankruptcy').modal('show'); diff --git a/static/js/zform.js b/static/js/zform.js index 40fdee586f..7fe4542b81 100644 --- a/static/js/zform.js +++ b/static/js/zform.js @@ -1,3 +1,5 @@ +var render_widgets_zform_choices = require('../templates/widgets/zform_choices.hbs'); + var zform = (function () { var exports = {}; @@ -64,7 +66,7 @@ exports.activate = function (opts) { choice.idx = idx; }); - var html = templates.render('widgets/zform_choices', data); + var html = render_widgets_zform_choices(data); var elem = $(html); elem.find('button').on('click', function (e) { diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 13f234d451..befe35621d 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -134,7 +134,7 @@ js_rules = RuleList( 'exclude': ['frontend_tests/'], 'description': '.includes() is incompatible with Internet Explorer. Use .indexOf() !== -1 instead.'}, {'pattern': '[.]html[(]', - 'exclude_pattern': '[.]html[(]("|\'|templates|html|message.content|sub.rendered_description|i18n.t|rendered_|$|[)]|error_text|widget_elem|[$]error|[$][(]"

"[)])', + 'exclude_pattern': r'''[.]html[(]("|'|render_|html|message.content|sub.rendered_description|i18n.t|rendered_|$|[)]|error_text|widget_elem|[$]error|[$][(]"

"[)])''', 'exclude': ['static/js/portico', 'static/js/lightbox.js', 'static/js/ui_report.js', 'static/js/confirm_dialog.js', 'frontend_tests/'],