Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

team: Migrate contributors template to Handlebars.

Anders Kaseorg0c8ae09a5eb3
diff --git a/templates/corporate/team.html b/templates/corporate/team.html
index 2f42f3743a3..7ad9e329f95 100644
--- a/templates/corporate/team.html
+++ b/templates/corporate/team.html
@@ -130,20 +130,6 @@ contributors, and 97+ people with 100+ commits." %}
</div>
<!-- Compiled using lodash -->
- <script type="text/template" id="contributors-template">
- <div class="person">
- <a href="<%= profile_url %>" target="_blank" rel="noopener noreferrer" class="no-underline">
- <div class="avatar">
- <img class="avatar_img" src="<%= avatar %>" alt="{{ _('Avatar') }}" />
- </div>
- <div class='info'>
- <b><%= name %></b><br />
- <%= commits %> <%= commits === 1 ? 'commit' : 'commits' %>
- </div>
- </a>
- </div>
- </script>
-
<script type="text/template" id="loading-template">
<p class="tab-loading">
Loading…
diff --git a/web/src/portico/team.ts b/web/src/portico/team.ts
index 1f77679a6a7..0d50070c8d0 100644
--- a/web/src/portico/team.ts
+++ b/web/src/portico/team.ts
@@ -2,6 +2,9 @@ import $ from "jquery";
import _ from "lodash";
import assert from "minimalistic-assert";
+import "../templates.ts";
+import render_contributors from "../../templates/team/contributors.hbs";
+
// The list of repository names is duplicated here in order to provide
// a clear type for Contributor objects.
//
@@ -134,7 +137,6 @@ function exclude_bot_contributors(contributor: Contributor): boolean {
// - Make tab header responsive.
// - Display full name instead of GitHub username.
export default function render_tabs(contributors: Contributor[]): void {
- const template = _.template($("#contributors-template").html());
const count_template = _.template($("#count-template").html());
const total_count_template = _.template($("#total-count-template").html());
const contributors_list = contributors
@@ -150,7 +152,7 @@ export default function render_tabs(contributors: Contributor[]): void {
mapped_contributors_list.sort((a, b) =>
a.commits < b.commits ? 1 : a.commits > b.commits ? -1 : 0,
);
- const total_tab_html = mapped_contributors_list.map((c) => template(c)).join("");
+ const total_tab_html = render_contributors({contributors: mapped_contributors_list});
const twenty_plus_total_contributors = mapped_contributors_list.filter((c) => c.commits >= 20);
const hundred_plus_total_contributors = mapped_contributors_list.filter(
@@ -197,17 +199,15 @@ export default function render_tabs(contributors: Contributor[]): void {
return a_commits < b_commits ? 1 : a_commits > b_commits ? -1 : 0;
});
- const html = filtered_by_tab
- .map((c) =>
- template({
- name: get_display_name(c),
- github_username: c.github_username,
- avatar: c.avatar,
- profile_url: get_profile_url(c, tab_name),
- commits: c.total_commits,
- }),
- )
- .join("");
+ const html = render_contributors({
+ contributors: filtered_by_tab.map((c) => ({
+ name: get_display_name(c),
+ github_username: c.github_username,
+ avatar: c.avatar,
+ profile_url: get_profile_url(c, tab_name),
+ commits: c.total_commits,
+ })),
+ });
$(`#tab-${CSS.escape(tab_name)} .contributors-grid`).html(html);
const contributor_count = filtered_by_tab.length;
diff --git a/web/templates/team/contributors.hbs b/web/templates/team/contributors.hbs
new file mode 100644
index 00000000000..3eb6a867a79
--- /dev/null
+++ b/web/templates/team/contributors.hbs
@@ -0,0 +1,13 @@
+{{#each contributors}}
+ <div class="person">
+ <a href="{{profile_url}}" target="_blank" rel="noopener noreferrer" class="no-underline">
+ <div class="avatar">
+ <img class="avatar_img" src="{{avatar}}" alt="{{t 'Avatar'}}" />
+ </div>
+ <div class='info'>
+ <b>{{name}}</b><br />
+ {{commits}} {{#if (eq commits 1)}}commit{{else}}commits{{/if}}
+ </div>
+ </a>
+ </div>
+{{/each}}