Render hashtags using labels
Use labels to represent #hashtags in the HTML rendering. Allows commands like "#swift now discussing #cinder" to render with two labels.
This commit is contained in:
parent
173c3ba5c4
commit
b8ca0c43ff
@ -23,7 +23,7 @@
|
||||
{{#each now}}
|
||||
<tr>
|
||||
<td class="col-sm-1"><span class="label label-primary">{{@key}}</span></td>
|
||||
<td>{{this}}</td>
|
||||
<td>{{#hashtag}}{{this}}{{/hashtag}}</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td><small><i>Nothing yet</i></small><td></tr>
|
||||
@ -38,7 +38,7 @@
|
||||
<td class="col-sm-1"><span class="label label-primary">{{room}}</span></td>
|
||||
<td>
|
||||
{{#each sessions}}
|
||||
{{ this }}<br/>
|
||||
{{#hashtag}}{{this}}{{/hashtag}}<br/>
|
||||
{{/each}}
|
||||
</td>
|
||||
</tr>
|
||||
@ -52,7 +52,7 @@
|
||||
<table class="table">
|
||||
{{#each ethercalc}}
|
||||
<tr>
|
||||
<td>{{this}}</td>
|
||||
<td>{{#hashtag}}{{this}}{{/hashtag}}</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<tr><td><small><i>Nothing yet</i></small><td></tr>
|
||||
|
14
html/ptg.js
14
html/ptg.js
@ -4,6 +4,20 @@ var source = document.getElementById("PTGtemplate").innerHTML;
|
||||
// Handlebars compiles the above source into a template
|
||||
var template = Handlebars.compile(source);
|
||||
|
||||
Handlebars.registerHelper('hashtag', function(options) {
|
||||
var words = options.fn(this).split(" ");
|
||||
var sentence = "";
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
if (words[i].startsWith("#")) {
|
||||
sentence += '<span class="label label-info">'
|
||||
+ words[i].substring(1) + '</span> ';
|
||||
} else {
|
||||
sentence += words[i] + " ";
|
||||
}
|
||||
}
|
||||
return new Handlebars.SafeString(sentence);
|
||||
});
|
||||
|
||||
$.getJSON("ptg.json", function(json) {
|
||||
console.log(json);
|
||||
document.getElementById("PTGsessions").innerHTML = template(json);
|
||||
|
Loading…
x
Reference in New Issue
Block a user