|
1 | 1 | module.exports = function () {
|
2 |
| - return { |
| 2 | + return { |
3 | 3 | /**
|
4 | 4 | * Handlebars Comparison Helpers
|
5 | 5 | * Copyright (c) 2013 Jon Schlinkert, Brian Woodward, contributors
|
@@ -28,95 +28,106 @@ module.exports = function () {
|
28 | 28 | * The value is lower than 10
|
29 | 29 | * {{/compare}}
|
30 | 30 | */
|
31 |
| - compare: function (left, operator, right, options) { // eslint-disable-line object-shorthand |
32 |
| - if (arguments.length < 3) { |
33 |
| - throw new Error('Handlebars Helper "compare" needs 2 parameters'); |
34 |
| - } |
| 31 | + compare: function (left, operator, right, options) { // eslint-disable-line object-shorthand |
| 32 | + if (arguments.length < 3) { |
| 33 | + throw new Error('Handlebars Helper "compare" needs 2 parameters'); |
| 34 | + } |
35 | 35 |
|
36 |
| - if (!options) { |
37 |
| - /*eslint-disable no-param-reassign*/ |
38 |
| - options = right; |
39 |
| - right = operator; |
40 |
| - operator = '==='; |
41 |
| - /*eslint-enable no-param-reassign*/ |
42 |
| - } |
| 36 | + /* eslint-disable no-param-reassign */ |
| 37 | + if (!options) { |
| 38 | + options = right; |
| 39 | + right = operator; |
| 40 | + operator = '==='; |
| 41 | + } |
| 42 | + /* eslint-enable no-param-reassign */ |
43 | 43 |
|
44 |
| - const operators = { |
45 |
| - '!=': (l, r) => { |
46 |
| - return l !== r; |
47 |
| - }, |
48 |
| - '!==': (l, r) => { |
49 |
| - return l !== r; |
50 |
| - }, |
51 |
| - '<': (l, r) => { |
52 |
| - return l < r; |
53 |
| - }, |
54 |
| - '<=': (l, r) => { |
55 |
| - return l <= r; |
56 |
| - }, |
57 |
| - '==': (l, r) => { |
58 |
| - return l === r; |
59 |
| - }, |
60 |
| - '===': (l, r) => { |
61 |
| - return l === r; |
62 |
| - }, |
63 |
| - '>': (l, r) => { |
64 |
| - return l > r; |
65 |
| - }, |
66 |
| - '>=': (l, r) => { |
67 |
| - return l >= r; |
68 |
| - }, |
69 |
| - typeof: (l, r) => { |
70 |
| - return typeof l === r; |
71 |
| - }, |
72 |
| - '||': (l, r) => { |
73 |
| - return l || r; |
74 |
| - } |
75 |
| - }; |
| 44 | + const operators = { |
| 45 | + '!=': (l, r) => { |
| 46 | + return l !== r; |
| 47 | + }, |
| 48 | + '!==': (l, r) => { |
| 49 | + return l !== r; |
| 50 | + }, |
| 51 | + '<': (l, r) => { |
| 52 | + return l < r; |
| 53 | + }, |
| 54 | + '<=': (l, r) => { |
| 55 | + return l <= r; |
| 56 | + }, |
| 57 | + '==': (l, r) => { |
| 58 | + return l === r; |
| 59 | + }, |
| 60 | + '===': (l, r) => { |
| 61 | + return l === r; |
| 62 | + }, |
| 63 | + '>': (l, r) => { |
| 64 | + return l > r; |
| 65 | + }, |
| 66 | + '>=': (l, r) => { |
| 67 | + return l >= r; |
| 68 | + }, |
| 69 | + typeof: (l, r) => { |
| 70 | + return typeof l === r; |
| 71 | + }, |
| 72 | + '||': (l, r) => { |
| 73 | + return l || r; |
| 74 | + } |
| 75 | + }; |
76 | 76 |
|
77 |
| - if (!operators[operator]) { |
78 |
| - throw new Error(`Handlebars Helper "compare" doesn't know the operator ${operator}`); |
79 |
| - } |
| 77 | + if (!operators[operator]) { |
| 78 | + throw new Error(`Handlebars Helper "compare" doesn't know the operator ${operator}`); |
| 79 | + } |
80 | 80 |
|
81 |
| - const result = operators[operator](left, right); |
| 81 | + const result = operators[operator](left, right); |
82 | 82 |
|
83 |
| - if (result) { |
84 |
| - return options.fn(this); |
85 |
| - } |
| 83 | + if (result) { |
| 84 | + return options.fn(this); |
| 85 | + } |
86 | 86 |
|
87 |
| - return options.inverse(this); |
88 |
| - }, |
89 |
| - getAboutItems: (navs) => { |
90 |
| - // `navs` is the menu data saved in `menu.yml`. |
91 |
| - return navs[2].items; |
92 |
| - }, |
93 |
| - getDocumentItems: (navs) => { |
94 |
| - // `navs` is the menu data saved in `menu.yml`. |
95 |
| - return navs[1].items; |
96 |
| - }, |
97 |
| - getSubPages: function (allPages, category) { // eslint-disable-line object-shorthand |
98 |
| - return allPages.reduce((acc, page) => { |
99 |
| - if (page.category === category) { |
100 |
| - const tocTitle = page['toc-title']; |
| 87 | + return options.inverse(this); |
| 88 | + }, |
| 89 | + getAboutItems: (navs) => { |
| 90 | + // `navs` is the menu data saved in `menu.yml`. |
| 91 | + return navs[2].items; |
| 92 | + }, |
| 93 | + getDocumentItems: (navs) => { |
| 94 | + // `navs` is the menu data saved in `menu.yml`. |
| 95 | + return navs[1].items; |
| 96 | + }, |
| 97 | + getSubPages: function (allPages, category) { // eslint-disable-line object-shorthand |
| 98 | + return allPages.reduce((acc, page) => { |
| 99 | + if (page.category === category) { |
| 100 | + const tocTitle = page['toc-title']; |
101 | 101 |
|
102 |
| - if (!acc[tocTitle]) { |
103 |
| - acc[tocTitle] = [page]; |
104 |
| - } else { |
105 |
| - acc[tocTitle].push(page); |
106 |
| - } |
107 |
| - } |
| 102 | + if (!acc[tocTitle]) { |
| 103 | + acc[tocTitle] = [page]; |
| 104 | + } else { |
| 105 | + acc[tocTitle].push(page); |
| 106 | + } |
| 107 | + } |
108 | 108 |
|
109 |
| - return acc; |
110 |
| - }, {}); |
111 |
| - }, |
112 |
| - hasSubPage: function (id, options) { // eslint-disable-line object-shorthand |
113 |
| - const result = (id === 'docs' || id === 'about'); |
| 109 | + return acc; |
| 110 | + }, {}); |
| 111 | + }, |
| 112 | + hasSubPage: function (id, options) { // eslint-disable-line object-shorthand |
| 113 | + const result = (id === 'docs' || id === 'about'); |
114 | 114 |
|
115 |
| - if (result) { |
116 |
| - return options.fn(this); |
117 |
| - } |
| 115 | + if (result) { |
| 116 | + return options.fn(this); |
| 117 | + } |
118 | 118 |
|
119 |
| - return options.inverse(this); |
120 |
| - } |
121 |
| - }; |
| 119 | + return options.inverse(this); |
| 120 | + }, |
| 121 | + hasTocTitle: (tocTitle, options) => { |
| 122 | + // Some files are placed directly under `developer-guide` or `user-guide`. |
| 123 | + // These files don't contain `toc-title` entries in their front matter. |
| 124 | + const result = (tocTitle !== 'undefined'); |
| 125 | + |
| 126 | + if (result) { |
| 127 | + return options.fn(this); |
| 128 | + } |
| 129 | + |
| 130 | + return options.inverse(this); |
| 131 | + } |
| 132 | + }; |
122 | 133 | };
|
0 commit comments