Commit e4c7476f218998424e18fe321c706c7ecf2aa0d3
1 parent
6d95c3a1
Exists in
master
and in
12 other branches
creating a list_proposal helpr
Showing
2 changed files
with
27 additions
and
16 deletions
Show diff stats
index.html
... | ... | @@ -31,28 +31,18 @@ |
31 | 31 | <img src="{{../host}}{{image.thumb_url}}"/> |
32 | 32 | {{#link name id}}{{/link}} |
33 | 33 | <ul id='proposal-item-{{id}}' class='proposal-category-item hide'> |
34 | - {{#each ../article.children}} | |
35 | - <li class="proposal-item"> | |
36 | - <ul class='category'> | |
37 | - {{#each categories}} | |
38 | - <li>{{name}}</li> | |
39 | - {{/each}} | |
40 | - </ul> | |
41 | - {{#link title id}}{{/link}} | |
42 | - <p>{{body}}</p> | |
43 | - </li> | |
44 | - {{/each}} | |
34 | + {{#list_proposal ../article.children}} | |
35 | + {{#link title id}}{{/link}} | |
36 | + {{/list_proposal}} | |
45 | 37 | </ul> |
46 | 38 | </li> |
47 | 39 | {{/each}} |
48 | 40 | </ul> |
49 | 41 | |
50 | 42 | <ul id="proposal-group" class='hide'> |
51 | - {{#each article.children}} | |
52 | - <li class="proposal-item"> | |
53 | - {{#link title id}}{{/link}} | |
54 | - </li> | |
55 | - {{/each}} | |
43 | + {{#list_proposal article.children}} | |
44 | + {{#link title id}}{{/link}} | |
45 | + {{/list_proposal}} | |
56 | 46 | </ul> |
57 | 47 | {{#each article.children}} |
58 | 48 | <div class='proposal-detail hide' id="proposal-item-{{id}}"> | ... | ... |
js/handlebars-helpers.js
... | ... | @@ -6,3 +6,24 @@ Handlebars.registerHelper('link', function(text, url) { |
6 | 6 | |
7 | 7 | return new Handlebars.SafeString(result); |
8 | 8 | }); |
9 | + | |
10 | +Handlebars.registerHelper('list_proposal', function(proposals, options) { | |
11 | + | |
12 | + var ret = ""; | |
13 | + | |
14 | + for(var i=0, j=proposals.length; i<j; i++) { | |
15 | + ret = ret + "<li class='proposal-item'>"; | |
16 | + ret = ret + "<ul class='category'>"; | |
17 | + | |
18 | + for(var x=0, y=proposals[i].categories.length; x<y; x++) { | |
19 | + ret = ret + '<li>' + proposals[i].categories[x].name + '</li>'; | |
20 | + } | |
21 | + ret = ret + '</ul>'; | |
22 | + ret = ret + options.fn(proposals[i]); | |
23 | + ret = ret + '<p>' + proposals[i].body + '</p>'; | |
24 | + ret = ret + '</li>'; | |
25 | + } | |
26 | + | |
27 | + return ret; | |
28 | + | |
29 | +}); | ... | ... |