From 9ea32bf7d832e324ea9bbdacb45d69e1d8c3e88a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 29 Apr 2016 17:29:41 -0400 Subject: [PATCH] Deprecation: Change `{{#each x in y}}` to `{{#each y as |x|}}` --- .../javascripts/admin/templates/api.hbs | 2 +- .../admin/templates/backups_index.hbs | 2 +- .../javascripts/admin/templates/badges.hbs | 2 +- .../admin/templates/customize_colors.hbs | 4 +-- .../javascripts/admin/templates/dashboard.hbs | 20 +++++------ .../admin/templates/email-bounced.hbs | 2 +- .../admin/templates/email-received.hbs | 6 ++-- .../admin/templates/email-rejected.hbs | 6 ++-- .../admin/templates/email-sent.hbs | 2 +- .../admin/templates/email-skipped.hbs | 2 +- .../admin/templates/email_index.hbs | 2 +- .../javascripts/admin/templates/emojis.hbs | 2 +- .../admin/templates/flags-list.hbs | 6 ++-- .../admin/templates/groups_type.hbs | 2 +- .../templates/modal/admin_badge_preview.hbs | 2 +- .../modal/admin_edit_badge_groupings.hbs | 2 +- .../admin/templates/plugins-index.hbs | 2 +- .../javascripts/admin/templates/plugins.hbs | 2 +- .../javascripts/admin/templates/reports.hbs | 2 +- .../admin/templates/site-settings.hbs | 2 +- .../admin/templates/user-index.hbs | 2 +- .../admin/templates/users-list-show.hbs | 2 +- .../discourse/lib/ember_compat_handlebars.js | 35 +++++++++++++------ .../discourse/templates/badges/index.hbs | 2 +- .../category-group-autocomplete.raw.hbs | 2 +- .../category-tag-autocomplete.raw.hbs | 2 +- .../discourse/templates/choose_topic.hbs | 2 +- .../templates/components/category-drop.hbs | 2 +- .../templates/components/ip-lookup.hbs | 2 +- .../templates/components/login-buttons.hbs | 2 +- .../templates/components/period-chooser.hbs | 2 +- .../templates/components/tag-drop.hbs | 4 +-- .../components/top-period-buttons.hbs | 2 +- .../templates/components/topic-category.hbs | 2 +- .../templates/discovery/categories.hbs | 4 +-- .../emoji-selector-autocomplete.raw.hbs | 2 +- .../discourse/templates/emoji-toolbar.raw.hbs | 6 ++-- .../group-selector-autocomplete.raw.hbs | 2 +- .../templates/list/posters-column.raw.hbs | 2 +- .../templates/list/topic-list-item.raw.hbs | 2 +- .../mobile/components/basic-topic-list.hbs | 4 +-- .../templates/mobile/discovery/categories.hbs | 4 +-- .../mobile/list/topic_list_item.raw.hbs | 2 +- .../discourse/templates/mobile/users.hbs | 2 +- .../modal/bulk_notification_level.hbs | 2 +- .../templates/modal/create-account.hbs | 2 +- .../discourse/templates/modal/modal.hbs | 2 +- .../javascripts/discourse/templates/share.hbs | 2 +- .../discourse/templates/tags/index.hbs | 2 +- .../discourse/templates/topic-status.raw.hbs | 2 +- .../discourse/templates/user-card.hbs | 4 +-- .../discourse/templates/user-invited-show.hbs | 2 +- .../user-selector-autocomplete.raw.hbs | 4 +-- .../discourse/templates/user/posts.hbs | 2 +- .../discourse/templates/user/preferences.hbs | 2 +- .../discourse/templates/user/summary.hbs | 10 +++--- .../discourse/templates/user/user.hbs | 4 +-- .../components/poll-results-standard.hbs | 2 +- .../javascripts/discourse/templates/poll.hbs | 2 +- vendor/assets/javascripts/handlebars.js | 2 +- 60 files changed, 112 insertions(+), 99 deletions(-) diff --git a/app/assets/javascripts/admin/templates/api.hbs b/app/assets/javascripts/admin/templates/api.hbs index c37c468db..0f2e65b89 100644 --- a/app/assets/javascripts/admin/templates/api.hbs +++ b/app/assets/javascripts/admin/templates/api.hbs @@ -5,7 +5,7 @@ {{i18n 'admin.api.user'}}   - {{#each k in model}} + {{#each model as |k|}} {{k.key}} diff --git a/app/assets/javascripts/admin/templates/backups_index.hbs b/app/assets/javascripts/admin/templates/backups_index.hbs index 09bf83bc6..d326aede6 100644 --- a/app/assets/javascripts/admin/templates/backups_index.hbs +++ b/app/assets/javascripts/admin/templates/backups_index.hbs @@ -13,7 +13,7 @@ - {{#each backup in model}} + {{#each model as |backup|}} {{backup.filename}} {{human-size backup.size}} diff --git a/app/assets/javascripts/admin/templates/badges.hbs b/app/assets/javascripts/admin/templates/badges.hbs index c128c6fb9..3ca7f9129 100644 --- a/app/assets/javascripts/admin/templates/badges.hbs +++ b/app/assets/javascripts/admin/templates/badges.hbs @@ -3,7 +3,7 @@

{{i18n 'admin.badges.title'}}

- {{#each to in email.to_addresses}} + {{#each email.to_addresses as |to|}}

{{unbound to}}

{{/each}} - {{#each cc in email.cc_addresses}} + {{#each email.cc_addresses as |cc|}}

{{unbound cc}}

{{/each}} diff --git a/app/assets/javascripts/admin/templates/email-sent.hbs b/app/assets/javascripts/admin/templates/email-sent.hbs index 56765cfad..4854a4e94 100644 --- a/app/assets/javascripts/admin/templates/email-sent.hbs +++ b/app/assets/javascripts/admin/templates/email-sent.hbs @@ -18,7 +18,7 @@ {{text-field value=filter.reply_key placeholderKey="admin.email.logs.filters.reply_key_placeholder"}} - {{#each l in model}} + {{#each model as |l|}} {{format-date l.created_at}} diff --git a/app/assets/javascripts/admin/templates/email-skipped.hbs b/app/assets/javascripts/admin/templates/email-skipped.hbs index 9c21c428c..b03e6179b 100644 --- a/app/assets/javascripts/admin/templates/email-skipped.hbs +++ b/app/assets/javascripts/admin/templates/email-skipped.hbs @@ -18,7 +18,7 @@ {{text-field value=filter.skipped_reason placeholderKey="admin.email.logs.filters.skipped_reason_placeholder"}} - {{#each l in model}} + {{#each model as |l|}} {{format-date l.created_at}} diff --git a/app/assets/javascripts/admin/templates/email_index.hbs b/app/assets/javascripts/admin/templates/email_index.hbs index 8837ac619..cd3696739 100644 --- a/app/assets/javascripts/admin/templates/email_index.hbs +++ b/app/assets/javascripts/admin/templates/email_index.hbs @@ -4,7 +4,7 @@ {{delivery_method}} - {{#each s in model.settings}} + {{#each model.settings as |s|}} {{s.name}} {{s.value}} diff --git a/app/assets/javascripts/admin/templates/emojis.hbs b/app/assets/javascripts/admin/templates/emojis.hbs index e89ec2af1..146baba74 100644 --- a/app/assets/javascripts/admin/templates/emojis.hbs +++ b/app/assets/javascripts/admin/templates/emojis.hbs @@ -16,7 +16,7 @@ - {{#each e in controller}} + {{#each controller as |e|}} :{{e.name}}: diff --git a/app/assets/javascripts/admin/templates/flags-list.hbs b/app/assets/javascripts/admin/templates/flags-list.hbs index 9b404b992..dbbec2a23 100644 --- a/app/assets/javascripts/admin/templates/flags-list.hbs +++ b/app/assets/javascripts/admin/templates/flags-list.hbs @@ -42,7 +42,7 @@ - {{#each flagger in flaggedPost.flaggers}} + {{#each flaggedPost.flaggers as |flagger|}}
{{#link-to 'adminUser' flagger.user}} @@ -67,7 +67,7 @@ {{#if adminOldFlagsView}} - {{#each flagger in flaggedPost.flaggers}} + {{#each flaggedPost.flaggers as |flagger|}} {{/if}} - {{#each c in flaggedPost.conversations}} + {{#each flaggedPost.conversations as |c|}} - {{#each plugin in controller}} + {{#each controller as |plugin|}} - {{#each row in model.dataReversed}} + {{#each model.dataReversed as |row|}} - {{#each user in model}} + {{#each model as |user|}} {{#if controller.showApproval}} - {{#each a in other_accounts}} + {{#each other_accounts as |a|}} diff --git a/app/assets/javascripts/discourse/templates/components/login-buttons.hbs b/app/assets/javascripts/discourse/templates/components/login-buttons.hbs index d6efea186..baf18eec3 100644 --- a/app/assets/javascripts/discourse/templates/components/login-buttons.hbs +++ b/app/assets/javascripts/discourse/templates/components/login-buttons.hbs @@ -1,3 +1,3 @@ -{{#each b in buttons}} +{{#each buttons as |b|}} {{/each}} diff --git a/app/assets/javascripts/discourse/templates/components/period-chooser.hbs b/app/assets/javascripts/discourse/templates/components/period-chooser.hbs index 75e9dd648..6559d03d5 100644 --- a/app/assets/javascripts/discourse/templates/components/period-chooser.hbs +++ b/app/assets/javascripts/discourse/templates/components/period-chooser.hbs @@ -3,7 +3,7 @@
diff --git a/app/assets/javascripts/discourse/templates/components/tag-drop.hbs b/app/assets/javascripts/discourse/templates/components/tag-drop.hbs index 46e4f6604..f1ca7f3e6 100644 --- a/app/assets/javascripts/discourse/templates/components/tag-drop.hbs +++ b/app/assets/javascripts/discourse/templates/components/tag-drop.hbs @@ -10,7 +10,7 @@
{{#if renderTags}} - {{#each t in tags}} + {{#each tags as |t|}}
{{tag-drop-link tagId=t category=currentCategory}}
@@ -18,4 +18,4 @@ {{/if}}
{{/if}} -{{/if}} \ No newline at end of file +{{/if}} diff --git a/app/assets/javascripts/discourse/templates/components/top-period-buttons.hbs b/app/assets/javascripts/discourse/templates/components/top-period-buttons.hbs index 169d69432..92c73d388 100644 --- a/app/assets/javascripts/discourse/templates/components/top-period-buttons.hbs +++ b/app/assets/javascripts/discourse/templates/components/top-period-buttons.hbs @@ -1,4 +1,4 @@ -{{#each p in periods}} +{{#each periods as |p|}} {{#d-button action="changePeriod" actionParam=p}} {{period-title p}} {{/d-button}} diff --git a/app/assets/javascripts/discourse/templates/components/topic-category.hbs b/app/assets/javascripts/discourse/templates/components/topic-category.hbs index cf70e3e8a..c31142256 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-category.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-category.hbs @@ -4,7 +4,7 @@ {{bound-category-link topic.category hideParent=true}} {{#if siteSettings.tagging_enabled}}
- {{#each t in topic.tags}} + {{#each topic.tags as |t|}} {{discourse-tag t}} {{/each}}
diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/discovery/categories.hbs index 7d26d35ba..bbb75015d 100644 --- a/app/assets/javascripts/discourse/templates/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/categories.hbs @@ -9,7 +9,7 @@
- {{#each c in model.categories}} + {{#each model.categories as |c|}}
{{#link-to 'adminUser' flagger.disposedBy}} @@ -101,7 +101,7 @@
diff --git a/app/assets/javascripts/admin/templates/groups_type.hbs b/app/assets/javascripts/admin/templates/groups_type.hbs index 780814b82..4486b8780 100644 --- a/app/assets/javascripts/admin/templates/groups_type.hbs +++ b/app/assets/javascripts/admin/templates/groups_type.hbs @@ -2,7 +2,7 @@

{{i18n 'admin.groups.edit'}}

    - {{#each group in controller}} + {{#each controller as |group|}}
  • {{#link-to "adminGroup" group.type group.name}}{{group.name}} {{#if group.userCountDisplay}} diff --git a/app/assets/javascripts/admin/templates/modal/admin_badge_preview.hbs b/app/assets/javascripts/admin/templates/modal/admin_badge_preview.hbs index e244d5b0e..14a475f5c 100644 --- a/app/assets/javascripts/admin/templates/modal/admin_badge_preview.hbs +++ b/app/assets/javascripts/admin/templates/modal/admin_badge_preview.hbs @@ -34,7 +34,7 @@ {{i18n 'admin.badges.preview.sample'}}

      - {{#each html in processed_sample}} + {{#each processed_sample as |html|}}
    • {{{html}}}
    • {{/each}}
    diff --git a/app/assets/javascripts/admin/templates/modal/admin_edit_badge_groupings.hbs b/app/assets/javascripts/admin/templates/modal/admin_edit_badge_groupings.hbs index f2a6581bb..5ca9f9cc3 100644 --- a/app/assets/javascripts/admin/templates/modal/admin_edit_badge_groupings.hbs +++ b/app/assets/javascripts/admin/templates/modal/admin_edit_badge_groupings.hbs @@ -1,7 +1,7 @@
{{#if plugin.url}} diff --git a/app/assets/javascripts/admin/templates/plugins.hbs b/app/assets/javascripts/admin/templates/plugins.hbs index 96ed1fc7d..ac1ca1a83 100644 --- a/app/assets/javascripts/admin/templates/plugins.hbs +++ b/app/assets/javascripts/admin/templates/plugins.hbs @@ -2,7 +2,7 @@ diff --git a/app/assets/javascripts/admin/templates/reports.hbs b/app/assets/javascripts/admin/templates/reports.hbs index 12303f27e..048ff284b 100644 --- a/app/assets/javascripts/admin/templates/reports.hbs +++ b/app/assets/javascripts/admin/templates/reports.hbs @@ -37,7 +37,7 @@ {{model.yaxis}}
{{row.x}} diff --git a/app/assets/javascripts/admin/templates/site-settings.hbs b/app/assets/javascripts/admin/templates/site-settings.hbs index d7e157a92..b9a96c90c 100644 --- a/app/assets/javascripts/admin/templates/site-settings.hbs +++ b/app/assets/javascripts/admin/templates/site-settings.hbs @@ -14,7 +14,7 @@
 
diff --git a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js b/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js index e69c5421a..01aee3fc0 100644 --- a/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js +++ b/app/assets/javascripts/discourse/lib/ember_compat_handlebars.js @@ -40,7 +40,7 @@ }; }; - // #each .. in support + // #each .. in support (as format is transformed to this) RawHandlebars.registerHelper('each', function(localName,inKeyword,contextName,options){ var list = Em.get(this, contextName); var output = []; @@ -68,6 +68,13 @@ RawHandlebars.JavaScriptCompiler.prototype.compiler = RawHandlebars.JavaScriptCompiler; RawHandlebars.JavaScriptCompiler.prototype.namespace = "Discourse.EmberCompatHandlebars"; + function buildPath(blk, args) { + return $.extend({ type: "PathExpression", + data: false, + depth: blk.path.depth, + loc: blk.path.loc }, args); + } + function replaceGet(ast) { var visitor = new Handlebars.Visitor(); visitor.mutating = true; @@ -75,19 +82,25 @@ visitor.MustacheStatement = function(mustache) { if (!(mustache.params.length || mustache.hash)) { mustache.params[0] = mustache.path; - mustache.path = { - type: "PathExpression", - data: false, - depth: mustache.path.depth, - parts: ["get"], - original: "get", - loc: mustache.path.loc, - strict: true, - falsy: true - }; + mustache.path = buildPath(mustache, { parts: ['get'], original: 'get', strict: true, falsy: true }); } return Handlebars.Visitor.prototype.MustacheStatement.call(this, mustache); }; + + // rewrite `each x as |y|` as each y in x` + // This allows us to use the same syntax in all templates + visitor.BlockStatement = function(block) { + if (block.path.original === 'each' && block.params.length === 1) { + const paramName = block.program.blockParams[0]; + block.params = [ buildPath(block, { original: paramName }), + { type: "CommentStatement", value: "in" }, + block.params[0] ]; + delete block.program.blockParams; + } + + return Handlebars.Visitor.prototype.BlockStatement.call(this, block); + }; + visitor.accept(ast); } diff --git a/app/assets/javascripts/discourse/templates/badges/index.hbs b/app/assets/javascripts/discourse/templates/badges/index.hbs index 71964b0e6..a5aac17b2 100644 --- a/app/assets/javascripts/discourse/templates/badges/index.hbs +++ b/app/assets/javascripts/discourse/templates/badges/index.hbs @@ -2,7 +2,7 @@

{{i18n 'badges.title'}}

- {{#each bg in badgeGroups}} + {{#each badgeGroups as |bg|}}

{{bg.badgeGrouping.displayName}}

diff --git a/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs index 1164fa80c..bc2181f53 100644 --- a/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs +++ b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs @@ -1,6 +1,6 @@
diff --git a/app/assets/javascripts/discourse/templates/category-tag-autocomplete.raw.hbs b/app/assets/javascripts/discourse/templates/category-tag-autocomplete.raw.hbs index 886c7bba7..efbf18a33 100644 --- a/app/assets/javascripts/discourse/templates/category-tag-autocomplete.raw.hbs +++ b/app/assets/javascripts/discourse/templates/category-tag-autocomplete.raw.hbs @@ -1,6 +1,6 @@
    - {{#each option in options}} + {{#each options as |option|}}
  • {{#if option.model}} {{category-link option.model allowUncategorized="true" link="false"}} diff --git a/app/assets/javascripts/discourse/templates/choose_topic.hbs b/app/assets/javascripts/discourse/templates/choose_topic.hbs index 3300b22b6..03af7f616 100644 --- a/app/assets/javascripts/discourse/templates/choose_topic.hbs +++ b/app/assets/javascripts/discourse/templates/choose_topic.hbs @@ -8,7 +8,7 @@ {{#if view.noResults}}

    {{i18n 'choose_topic.none_found'}}

    {{else}} - {{#each t in view.topics}} + {{#each view.topics as |t|}}
{{#link-to "adminUser" a}}{{avatar a usernamePath="user.username" imageSize="small"}} {{a.username}}{{/link-to}} {{a.trustLevel.id}}