UNPKG

6.5 kBMarkdownView Raw
1<a name="TemplateHelpers"></a>
2
3## TemplateHelpers
4Condensation specific helpers for common tasks
5
6**Kind**: global namespace
7
8* [TemplateHelpers](#TemplateHelpers) : <code>object</code>
9 * [.arrayify(...str)](#TemplateHelpers.arrayify) ⇒ <code>String</code>
10 * [.assetPath(path)](#TemplateHelpers.assetPath) ⇒ <code>String</code>
11 * [.cValue(str, options)](#TemplateHelpers.cValue) ⇒ <code>string</code> \| <code>Number</code>
12 * [.layout([options])](#TemplateHelpers.layout) ⇒ <code>string</code>
13 * [.objectify([...options])](#TemplateHelpers.objectify) ⇒ <code>String</code>
14 * [.requireAssets(globPath)](#TemplateHelpers.requireAssets) ⇒ <code>string</code>
15 * [.scopeId()](#TemplateHelpers.scopeId) ⇒ <code>string</code>
16 * [.templateUrl(path)](#TemplateHelpers.templateUrl) ⇒ <code>string</code>
17
18
19* * *
20
21<a name="TemplateHelpers.arrayify"></a>
22
23### arrayify(...str)
24Turn a string into a JSON parseable array.
25Each value is processed with `cValue`
26
27**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
28**Returns**: <code>String</code> - - When parsed will be an array
29
30| Param | Type | Description |
31| --- | --- | --- |
32| ...str | <code>string</code> | String to use if block is not present |
33
34**Example**
35```js
36{{arrayify "string" (ref "Parameter1") }}
37```
38**Example**
39```js
40{{arrayify (ref "Parameter1")}}
41```
42
43* * *
44
45<a name="TemplateHelpers.assetPath"></a>
46
47### assetPath(path)
48Build the S3 path to an asset particle within the project
49
50**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
51**Returns**: <code>String</code> - - S3 path to the asset
52
53| Param | Type | Description |
54| --- | --- | --- |
55| path | <code>string</code> | the path to the particle relative to the `assets` directory |
56
57**Example**
58```js
59{{assetPath "myasset.zip"}}
60```
61**Example**
62```js
63{{assetPath "path/to/myasset.sh"}}
64```
65
66* * *
67
68<a name="TemplateHelpers.cValue"></a>
69
70### cValue(str, options)
71Coerce Value
72
73Will check to see if a string is a parsable object. If it is,
74then it will be left alone and simply returned back.
75
76If the string is not a parseable object it will be made JSON compliant and returned.
77
78If the string is empty, null, undefined or otherwise `falsey` then an empty string will be returned.
79
80**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
81**Summary**: Coerce value
82
83| Param | Type | Description |
84| --- | --- | --- |
85| str | <code>string</code> | The string to evaluate |
86| options | <code>Object</code> | options object from Handlebars |
87| options.forceNumber | <code>boolean</code> | return a number at all costs |
88
89**Example**
90```js
91---
92foo: bar
93baz: {"Ref": "LogicalId"}
94faz: "5"
95---
96{{cValue foo}}
97{{cValue baz}}
98{{cValue faz forceNumber=true}}
99```
100
101* * *
102
103<a name="TemplateHelpers.layout"></a>
104
105### layout([options])
106Start a layout
107
108**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
109**Returns**: <code>string</code> - - CloudFormation Template
110
111| Param | Type | Default | Description |
112| --- | --- | --- | --- |
113| [options] | <code>Object</code> | | options object from Handlebars |
114| [options.AWSTemplateFormatVersion] | <code>string</code> | <code>&quot;2010-09-09&quot;</code> | AWS Format Version |
115| [options.TemplateDescription] | <code>string</code> | | Description for the template |
116| [options.Transform] | <code>string</code> | | AWS Transform type for the template |
117
118**Example**
119```js
120---
121things:
122-
123 name: subnet1
124 cidr: "10.0.0.0/24"
125-
126 name subnet2
127 cidr: "10.0.1.0/24"
128---
129
130{{#layout templateDescription="condensation rocks!"}}
131 {{parameter 'my_parameter' logicalId="MyParameter"}}
132 {{condition 'my_condition' logicalId="MyCondition"}}
133
134 {{! helpers can occur in any order, allowing you to group related section parts together }}
135
136 {{#each things}}
137 {{parameter 'repeate_me' logicalId="RepeateMe" logicalIdSuffix=@index}}
138 {{condition 'repeate_me' logicalId="RepeateMeCond" logicalIdSuffix=@index}}
139 {{resource 'repeate_me' logicalId="RepeateMeResource" logicalIdSuffix=@index}}
140 {{output 'repeate_me' logicalId="RepeateMeOutput" logicalIdSuffix=@index}}
141 {{/each}}
142{{/layout}}
143```
144
145* * *
146
147<a name="TemplateHelpers.objectify"></a>
148
149### objectify([...options])
150Return options as a stringified object
151
152**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
153**Returns**: <code>String</code> - - When parsed will be an object
154
155| Param | Type | Description |
156| --- | --- | --- |
157| [...options] | <code>kv</code> | Key/Value pairs to pass to the particle helper |
158
159**Example**
160```js
161{{objectify Param1="Value1" Param2=(ref "AWS::Region")}}
162```
163
164* * *
165
166<a name="TemplateHelpers.requireAssets"></a>
167
168### requireAssets(globPath)
169Include a glob of assets
170
171Only needed for assets that are not directly referenced by another particle
172
173**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
174
175| Param | Type | Description |
176| --- | --- | --- |
177| globPath | <code>string</code> | Glob patter of assets to package with the project |
178
179**Example**
180```js
181{{requireAssets "all_of_these/**"}}
182```
183**Example**
184```js
185{{requireAssets "module:<MODULE>" 'all_from_module/**'}}
186```
187**Example**
188```js
189{{!-- to load modules with format `particles-NAME` --}}
190{{requireAssets "m:<NAME>" "all_from_module/**"}}
191```
192
193* * *
194
195<a name="TemplateHelpers.scopeId"></a>
196
197### scopeId()
198Used within sets to add the correct logicalIdPrefix and/or logicalIdSuffix to a logicalId
199
200**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
201**Returns**: <code>string</code> - - The logical with the correct prefix and suffix for the current scope
202
203| Type | Description |
204| --- | --- |
205| <code>string</code> | The logicalId |
206
207**Example**
208```js
209{{scopeId "LogicalId"}}
210```
211**Example**
212```js
213{{ref (scopeId "LogicalId")}}
214```
215
216* * *
217
218<a name="TemplateHelpers.templateUrl"></a>
219
220### templateUrl(path)
221Generate an S3 URL for another template in the project
222
223**Kind**: static method of [<code>TemplateHelpers</code>](#TemplateHelpers)
224
225| Param | Type | Description |
226| --- | --- | --- |
227| path | <code>string</code> | Path to the template (file extensions optional) |
228
229**Example**
230```js
231{{templateUrl "another.template.json"}}
232```
233**Example**
234```js
235{{templateUrl "module:<MODULE>" 'another.template.json'}}
236```
237**Example**
238```js
239{{!-- to load modules with format `particles-NAME` --}}
240{{set "m:<NAME>" "another.template.json"}}
241```
242
243* * *
244