You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/PULL_REQUEST_TEMPLATE.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,4 +9,4 @@ Generally we like to see pull requests that
9
9
-[ ] Have tests
10
10
-[ ] Have the [typings](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) (lib/handlebars.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description.
11
11
-[ ] Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
12
-
-[ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR.
12
+
-[ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR.
Copy file name to clipboardExpand all lines: FAQ.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,53 +2,53 @@
2
2
3
3
## How can I file a bug report:
4
4
5
-
See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).
5
+
See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).
6
6
7
7
## Why isn't my Mustache template working?
8
8
9
-
Handlebars deviates from Mustache slightly on a few behaviors. These variations are documented in our [readme](https://github.com/handlebars-lang/handlebars.js#differences-between-handlebarsjs-and-mustache).
9
+
Handlebars deviates from Mustache slightly on a few behaviors. These variations are documented in our [readme](https://github.com/handlebars-lang/handlebars.js#differences-between-handlebarsjs-and-mustache).
10
10
11
11
## Why is it slower when compiling?
12
12
13
-
The Handlebars compiler must parse the template and construct a JavaScript program which can then be run. Under some environments such as older mobile devices this can have a performance impact which can be avoided by precompiling. Generally it's recommended that precompilation and the runtime library be used on all clients.
13
+
The Handlebars compiler must parse the template and construct a JavaScript program which can then be run. Under some environments such as older mobile devices this can have a performance impact which can be avoided by precompiling. Generally it's recommended that precompilation and the runtime library be used on all clients.
14
14
15
15
## Why doesn't this work with Content Security Policy restrictions?
16
16
17
-
When not using the precompiler, Handlebars generates a dynamic function for each template which can cause issues with pages that have enabled Content Policy. It's recommended that templates are precompiled or the `unsafe-eval` policy is enabled for sites that must generate dynamic templates at runtime.
17
+
When not using the precompiler, Handlebars generates a dynamic function for each template which can cause issues with pages that have enabled Content Policy. It's recommended that templates are precompiled or the `unsafe-eval` policy is enabled for sites that must generate dynamic templates at runtime.
18
18
19
19
## How can I include script tags in my template?
20
20
21
-
If loading the template via an inlined `<script type="text/x-handlebars">` tag then you may need to break up the script tag with an empty comment to avoid browser parser errors:
21
+
If loading the template via an inlined `<script type="text/x-handlebars">` tag then you may need to break up the script tag with an empty comment to avoid browser parser errors:
22
22
23
-
```html
24
-
<scripttype="text/x-handlebars">
25
-
foo
26
-
<scr{{!}}iptsrc="bar"></scr{{!}}ipt>
27
-
</script>
28
-
```
23
+
```html
24
+
<scripttype="text/x-handlebars">
25
+
foo
26
+
<scr{{!}}iptsrc="bar"></scr{{!}}ipt>
27
+
</script>
28
+
```
29
29
30
-
It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue.
30
+
It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue.
31
31
32
32
## Why are my precompiled scripts throwing exceptions?
33
33
34
-
When using the precompiler, it's important that a supporting version of the Handlebars runtime be loaded on the target page. In version 1.x there were rudimentary checks to compare the version but these did not always work. This is fixed under 2.x but the version checking does not work between these two versions. If you see unexpected errors such as `undefined is not a function` or similar, please verify that the same version is being used for both the precompiler and the client. This can be checked via:
34
+
When using the precompiler, it's important that a supporting version of the Handlebars runtime be loaded on the target page. In version 1.x there were rudimentary checks to compare the version but these did not always work. This is fixed under 2.x but the version checking does not work between these two versions. If you see unexpected errors such as `undefined is not a function` or similar, please verify that the same version is being used for both the precompiler and the client. This can be checked via:
35
35
36
-
```sh
37
-
handlebars --version
38
-
```
36
+
```sh
37
+
handlebars --version
38
+
```
39
39
40
-
If using the integrated precompiler and
40
+
If using the integrated precompiler and
41
41
42
-
```javascript
43
-
console.log(Handlebars.VERSION);
44
-
```
42
+
```javascript
43
+
console.log(Handlebars.VERSION);
44
+
```
45
45
46
-
On the client side.
46
+
On the client side.
47
47
48
-
We include the built client libraries in the npm package for those who want to be certain that they are using the same client libraries as the compiler.
48
+
We include the built client libraries in the npm package for those who want to be certain that they are using the same client libraries as the compiler.
49
49
50
-
Should these match, please file an issue with us, per our [issue filing guidelines](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).
50
+
Should these match, please file an issue with us, per our [issue filing guidelines](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).
51
51
52
52
## How do I load the runtime library when using AMD?
53
53
54
-
The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility.
54
+
The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility.
"description": "Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.",
4
-
"homepage": "http://handlebarsjs.com",
5
-
"license": "MIT",
6
-
"type": "component",
7
-
"keywords": [
8
-
"handlebars",
9
-
"mustache",
10
-
"html"
11
-
],
12
-
"authors": [
13
-
{
14
-
"name": "Chris Wanstrath",
15
-
"homepage": "http://chriswanstrath.com"
16
-
}
17
-
],
18
-
"require": {
19
-
"robloach/component-installer": "*"
20
-
},
21
-
"extra": {
22
-
"component": {
23
-
"name": "handlebars",
24
-
"scripts": [
25
-
"handlebars.js"
26
-
],
27
-
"files": [
28
-
"handlebars.runtime.js"
29
-
],
30
-
"shim": {
31
-
"exports": "Handlebars"
32
-
}
33
-
}
2
+
"name": "components/handlebars.js",
3
+
"description": "Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.",
Copy file name to clipboardExpand all lines: docs/compiler-api.md
+32-31Lines changed: 32 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,8 +34,8 @@ let ast = Handlebars.parseWithoutProcessing(myTemplate);
34
34
35
35
`Handlebars.parse` will parse the template with `parseWithoutProcessing` (see above) then it will update the AST to strip extraneous whitespace. The whitespace stripping functionality handles two distinct situations:
36
36
37
-
* Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone")
38
-
* Applies "whitespace control" characters (i.e. `~`) by truncating the `ContentStatement``value` property appropriately (e.g. `\n\n{{~foo}}` would have a `ContentStatement` with a `value` of `''`)
37
+
- Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone")
38
+
- Applies "whitespace control" characters (i.e. `~`) by truncating the `ContentStatement``value` property appropriately (e.g. `\n\n{{~foo}}` would have a `ContentStatement` with a `value` of `''`)
39
39
40
40
`Handlebars.parse` is used internally by `Handlebars.precompile` and `Handlebars.compile`.
`name` will be a `SubExpression` when tied to a dynamic partial, i.e. `{{> (foo) }}`, otherwise this is a path or literal whose `original` value is used to lookup the desired partial.
-`parts` is an array of the names in the path. `foo.bar` would be `['foo', 'bar']`. Scope references, `.`, `..`, and `this` should be omitted from this array.
210
208
-`original` is the path as entered by the user. Separator and scope references are left untouched.
@@ -309,58 +305,63 @@ The `Handlebars.JavaScriptCompiler` object has a number of methods that may be c
309
305
Note that this does not impact dynamic partials, which implementors need to be aware of. Overriding `VM.resolvePartial` may be required to support dynamic cases.
310
306
311
307
-`depthedLookup(name)`
312
-
Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode.
308
+
Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode.
313
309
314
310
-`compilerInfo()`
315
311
Allows for custom compiler flags used in the runtime version checking logic.
316
312
317
313
-`appendToBuffer(source, location, explicit)`
318
-
Allows for code buffer emitting code. Defaults behavior is string concatenation.
314
+
Allows for code buffer emitting code. Defaults behavior is string concatenation.
319
315
320
-
-`source` is the source code whose result is to be appending
321
-
-`location` is the location of the source in the source map.
322
-
-`explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise.
316
+
-`source` is the source code whose result is to be appending
317
+
-`location` is the location of the source in the source map.
318
+
-`explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise.
323
319
324
320
-`initializeBuffer()`
325
-
Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation.
321
+
Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation.
326
322
327
323
### Example for the compiler api.
328
324
329
325
This example changes all lookups of properties are performed by a helper (`lookupLowerCase`) which looks for `test` if `{{Test}}` occurs in the template. This is just to illustrate how compiler behavior can be change.
330
326
331
327
There is also [a jsfiddle with this code](https://jsfiddle.net/9D88g/162/) if you want to play around with it.
0 commit comments