1 | Handlebars.registerHelper 'first', (array, count) ->
|
2 | if Utils.isUndefined(count) then array[0] else array.slice 0, count
|
3 |
|
4 | Handlebars.registerHelper 'withFirst', (array, count, options) ->
|
5 | if Utils.isUndefined count
|
6 | options = count
|
7 | options.fn array[0]
|
8 | else
|
9 | array = array.slice 0, count
|
10 | result = ''
|
11 | for item of array then result += options.fn array[item]
|
12 | result
|
13 |
|
14 | Handlebars.registerHelper 'last', (array, count) ->
|
15 | if Utils.isUndefined(count) then array[array.length - 1] else array.slice -count
|
16 |
|
17 | Handlebars.registerHelper 'withLast', (array, count, options) ->
|
18 | if Utils.isUndefined count
|
19 | options = count
|
20 | options.fn array[array.length - 1]
|
21 | else
|
22 | array = array.slice -count
|
23 | result = ''
|
24 | for item of array then result += options.fn array[item]
|
25 | result
|
26 |
|
27 | Handlebars.registerHelper 'after', (array, count) ->
|
28 | array.slice count
|
29 |
|
30 | Handlebars.registerHelper 'withAfter', (array, count, options) ->
|
31 | array = array.slice count
|
32 | result = ''
|
33 | for item of array then result += options.fn array[item]
|
34 | result
|
35 |
|
36 | Handlebars.registerHelper 'before', (array, count) ->
|
37 | array.slice 0, -count
|
38 |
|
39 | Handlebars.registerHelper 'withBefore', (array, count, options) ->
|
40 | array = array.slice 0, -count
|
41 | result = ''
|
42 | for item of array then result += options.fn array[item]
|
43 | result
|
44 |
|
45 | Handlebars.registerHelper 'join', (array, separator) ->
|
46 | array.join if Utils.isUndefined(separator) then ' ' else separator
|
47 |
|
48 | Handlebars.registerHelper 'sort', (array, field) ->
|
49 | if Utils.isUndefined field
|
50 | array.sort()
|
51 | else
|
52 | array.sort (a, b) -> a[field] > b[field]
|
53 |
|
54 | Handlebars.registerHelper 'withSort', (array, field, options) ->
|
55 | result = ''
|
56 |
|
57 | if Utils.isUndefined field
|
58 | options = field
|
59 | array = array.sort()
|
60 | result += options.fn(item) for item in array
|
61 | else
|
62 | array = array.sort (a, b) -> a[field] > b[field]
|
63 | result += options.fn(array[item]) for item of array
|
64 |
|
65 | result
|
66 |
|
67 | Handlebars.registerHelper 'length', (array) ->
|
68 | array.length
|
69 |
|
70 | Handlebars.registerHelper 'lengthEqual', (array, length, options) ->
|
71 | if array.length is length then options.fn(@) else options.inverse(@)
|
72 |
|
73 | Handlebars.registerHelper 'empty', (array, options) ->
|
74 | if array.length <= 0 then options.fn(@) else options.inverse(@)
|
75 |
|
76 | Handlebars.registerHelper 'any', (array, options) ->
|
77 | if array.length > 0 then options.fn(@) else options.inverse(@)
|
78 |
|
79 | Handlebars.registerHelper 'inArray', (array, value, options) ->
|
80 | if array.indexOf(value) isnt -1 then options.fn(@) else options.inverse(@)
|
81 |
|
82 | Handlebars.registerHelper 'eachIndex', (array, options) ->
|
83 | result = ''
|
84 |
|
85 | for value, index in array
|
86 | result += options.fn item: value, index: index
|
87 |
|
88 | result
|
89 |
|
90 | Handlebars.registerHelper 'eachProperty', (obj, options) ->
|
91 | result = ''
|
92 |
|
93 | for key, value of obj
|
94 | result += options.fn key: key, value: value
|
95 |
|
96 | result
|