1 | 1 | var sanatizeType = require('../util/sanatize-patterntype'); |
|
2 | 1 | var processPatternParameters = require('../util/process-parameters'); |
|
3 | 1 | var extend = require('extend'); |
|
4 | 1 | var fm = require('front-matter'); |
|
5 | |||
6 | /** |
||
7 | * render a pattern with 'handlebars' |
||
8 | * |
||
9 | * @param string body |
||
10 | * @param object data |
||
11 | * @return Buffer |
||
12 | */ |
||
13 | function renderPattern ( patterncontent, data ) { |
||
14 | |||
15 | // Get the HTML for the current page and layout |
||
16 | 1 | var pattern = fm(patterncontent); |
|
17 | 1 | var patternData = {}; |
|
18 | |||
19 | 1 | var patternLayout = this.handlebars.compile('{{> body}}' /*+ '\n'*/, {noEscape: true}); |
|
20 | |||
21 | 1 | try { |
|
22 | 1 | var specs = pattern.attributes; |
|
23 | 4 | if (specs.pattern && !specs.pattern.type) { |
|
24 | // 'type' is not set, try to get it from 'name' |
||
25 | var parts = String(specs.pattern.name).split('/'); |
||
26 | 2 | if (parts.length > 1) { |
|
27 | specs.pattern.type = sanatizeType(parts[0]); |
||
28 | } |
||
29 | } |
||
30 | // Add this page's front matter |
||
31 | 1 | patternData = extend(patternData, specs); |
|
32 | 1 | patternData = extend(patternData, data); |
|
33 | |||
34 | // Finish by adding constants |
||
35 | 1 | patternData = extend(patternData, { |
|
36 | // ... layout: layout |
||
37 | }); |
||
38 | |||
39 | // parameters and defaults |
||
40 | 2 | if (specs.params) { |
|
41 | patternData = processPatternParameters(specs, patternData); |
||
42 | } |
||
43 | |||
44 | //patternData.Patternlibrary = this; |
||
45 | // Now create Handlebars templates out of them |
||
46 | 1 | var patternTemplate = this.handlebars.compile(pattern.body /*+ '\n'*/, {noEscape: true}); |
|
47 | |||
48 | } catch (err) { |
||
49 | throw ('renderPattern Error: ', err); |
||
0 ignored issues
–
show
|
|||
50 | } |
||
51 | // Finally, add the page as a partial called "body", and render the layout template |
||
52 | 1 | this.handlebars.registerPartial('body', patternTemplate); |
|
53 | |||
54 | |||
55 | 1 | return ( patternLayout(patternData) ); |
|
56 | |||
57 | } // renderPattern () {} |
||
58 | |||
59 | module.exports = renderPattern; |
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.
This operator is most often used in
for
statements.Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.
This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.
could just as well be written as:
To learn more about the sequence operator, please refer to the MDN.