Browse Source

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.
changes/56/473756/1
Thierry Carrez 4 years ago
parent
commit
b8ca0c43ff
2 changed files with 17 additions and 3 deletions
  1. +3
    -3
      html/ptg.html
  2. +14
    -0
      html/ptg.js

+ 3
- 3
html/ptg.html View File

@ -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
- 0
html/ptg.js View File

@ -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…
Cancel
Save