Skip to content

Commit

Permalink
Use Blaze in order to render templates -
Browse files Browse the repository at this point in the history
no manual HTML concatenation anymore
  • Loading branch information
mrsimpson committed Mar 15, 2018
1 parent 734d72a commit 85b23e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template name="fieldTypeThreadReference">
<div>
<div class="thread-reference">{{value}}</div>
<a href="threadUrl">
<button class="rc-button rc-button--primary thread-url">
{{> icon icon="jump"}}
{{_ "View_thread"}}
</button>
</a>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {registerFieldTemplate} from './renderField';

registerFieldTemplate('threadReference', 'fieldTypeThreadReference');

Template.fieldTypeThreadReference.helpers({
});

24 changes: 11 additions & 13 deletions packages/rocketchat-message-attachments/client/renderField.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
const renderers = {};

export function registerFieldTemplate(fieldType, templateName) {
renderers[fieldType] = templateName;
}

Template.renderField.helpers({
specializedRendering(field) {
let html = '';

switch (field.type) {
case 'threadReference':
html = `<div><div class='thread-reference'>${ field.value }</div><a href='${ field.threadUrl }'>`;
html += '<button class="rc-button rc-button--primary thread-url">';
html += '<svg class="rc-icon tab-button-icon tab-button-icon--jump" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-jump"></use></svg>';
html += `${ TAPi18n.__('Thread_view') }</button>`;
html += '</a></div>';
break;
default:
// consider the value already formatted as html
html = field.value;
if (field.type && renderers[field.type]) {
html = Blaze.toHTMLWithData(Template[renderers[field.type]], field);
} else {
// consider the value already formatted as html
html = field.value;
}

return html;
}
});
2 changes: 2 additions & 0 deletions packages/rocketchat-message-attachments/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Package.onUse(function(api) {
api.addFiles('client/messageAttachment.js', 'client');
api.addFiles('client/renderField.html', 'client');
api.addFiles('client/renderField.js', 'client');
api.addFiles('client/fieldTypeThreadReference.html', 'client');
api.addFiles('client/fieldTypeThreadReference.js', 'client');

// stylesheets
api.addFiles('client/stylesheets/messageAttachments.css', 'client');
Expand Down

0 comments on commit 85b23e1

Please sign in to comment.