Skip to content

Commit

Permalink
Format *.md files with prettier
Browse files Browse the repository at this point in the history
The `npm run format` command now matches
the husky `lint-staged`-commands.

Also upgraded to prettier v3.
  • Loading branch information
jaylinski committed Jul 30, 2023
1 parent f202c50 commit 9413ea9
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Upgrade to Prettier 2.7
3d228334530860a6e3f99dc10777c84bf22292c1
3d228334530860a6e3f99dc10777c84bf22292c1
# Format markdown files with Prettier
dfe2eaaf20f0b679d94e5a799757c4394d80f1cc
4 changes: 1 addition & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ Before filing issues, please check the following points first:
- [ ] Read the FAQ at https://github.com/handlebars-lang/handlebars.js/blob/master/FAQ.md
- [ ] Use the jsfiddle-template at https://jsfiddle.net/4nbwjaqz/4/ to reproduce problems or bugs

This will probably help you to get a solution faster.
This will probably help you to get a solution faster.
For bugs, it would be great to have a PR with a failing test-case.


2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Generally we like to see pull requests that
- [ ] Have tests
- [ ] 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.
- [ ] Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
- [ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR.
- [ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR.
48 changes: 24 additions & 24 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@

## How can I file a bug report:

See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).
See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues).

## Why isn't my Mustache template working?

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).
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).

## Why is it slower when compiling?

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.
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.

## Why doesn't this work with Content Security Policy restrictions?

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.
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.

## How can I include script tags in my template?

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:
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:

```html
<script type="text/x-handlebars">
foo
<scr{{!}}ipt src="bar"></scr{{!}}ipt>
</script>
```
```html
<script type="text/x-handlebars">
foo
<scr{{!}}ipt src="bar"></scr{{!}}ipt>
</script>
```

It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue.
It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue.

## Why are my precompiled scripts throwing exceptions?

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:
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:

```sh
handlebars --version
```
```sh
handlebars --version
```

If using the integrated precompiler and
If using the integrated precompiler and

```javascript
console.log(Handlebars.VERSION);
```
```javascript
console.log(Handlebars.VERSION);
```

On the client side.
On the client side.

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.
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.

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).
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).

## How do I load the runtime library when using AMD?

The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility.
The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We recommend always using the latest versions of Handlebars and its official com
## Supported Versions

| Version | Supported |
|---------| ------------------ |
| ------- | ------------------ |
| 5.0.x | :white_check_mark: |
| 4.7.x | :white_check_mark: |
| < 4.7 | :x: |
Expand Down
4 changes: 1 addition & 3 deletions components/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
"repo": "components/handlebars.js",
"version": "1.0.0",
"main": "handlebars.js",
"scripts": [
"handlebars.js"
]
"scripts": ["handlebars.js"]
}
64 changes: 32 additions & 32 deletions components/composer.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"name": "components/handlebars.js",
"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.",
"homepage": "http://handlebarsjs.com",
"license": "MIT",
"type": "component",
"keywords": [
"handlebars",
"mustache",
"html"
],
"authors": [
{
"name": "Chris Wanstrath",
"homepage": "http://chriswanstrath.com"
}
],
"require": {
"robloach/component-installer": "*"
},
"extra": {
"component": {
"name": "handlebars",
"scripts": [
"handlebars.js"
],
"files": [
"handlebars.runtime.js"
],
"shim": {
"exports": "Handlebars"
}
}
"name": "components/handlebars.js",
"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.",
"homepage": "http://handlebarsjs.com",
"license": "MIT",
"type": "component",
"keywords": [
"handlebars",
"mustache",
"html"
],
"authors": [
{
"name": "Chris Wanstrath",
"homepage": "http://chriswanstrath.com"
}
],
"require": {
"robloach/component-installer": "*"
},
"extra": {
"component": {
"name": "handlebars",
"scripts": [
"handlebars.js"
],
"files": [
"handlebars.runtime.js"
],
"shim": {
"exports": "Handlebars"
}
}
}
}
63 changes: 32 additions & 31 deletions docs/compiler-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ let ast = Handlebars.parseWithoutProcessing(myTemplate);

`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:

* Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone")
* 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 `''`)
- Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone")
- 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 `''`)

`Handlebars.parse` is used internally by `Handlebars.precompile` and `Handlebars.compile`.

Expand Down Expand Up @@ -71,7 +71,7 @@ interface Position {
interface Program <: Node {
type: "Program";
body: [ Statement ];

blockParams: [ string ];
}
```
Expand Down Expand Up @@ -132,7 +132,6 @@ interface PartialBlockStatement <: Statement {

`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.


```java
interface ContentStatement <: Statement {
type: "ContentStatement";
Expand All @@ -148,7 +147,6 @@ interface CommentStatement <: Statement {
}
```


```java
interface Decorator <: Statement {
type: "Decorator";
Expand Down Expand Up @@ -209,7 +207,6 @@ interface PathExpression <: Expression {
- `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.
- `original` is the path as entered by the user. Separator and scope references are left untouched.


##### Literals

```java
Expand Down Expand Up @@ -242,7 +239,6 @@ interface NullLiteral <: Literal {
}
```


### Miscellaneous

```java
Expand Down Expand Up @@ -279,8 +275,8 @@ function ImportScanner() {
}
ImportScanner.prototype = new Visitor();

ImportScanner.prototype.PartialStatement = function(partial) {
this.partials.push({request: partial.name.original});
ImportScanner.prototype.PartialStatement = function (partial) {
this.partials.push({ request: partial.name.original });

Visitor.prototype.PartialStatement.call(this, partial);
};
Expand Down Expand Up @@ -309,58 +305,63 @@ The `Handlebars.JavaScriptCompiler` object has a number of methods that may be c
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.

- `depthedLookup(name)`
Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode.
Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode.

- `compilerInfo()`
Allows for custom compiler flags used in the runtime version checking logic.

- `appendToBuffer(source, location, explicit)`
Allows for code buffer emitting code. Defaults behavior is string concatenation.
Allows for code buffer emitting code. Defaults behavior is string concatenation.

- `source` is the source code whose result is to be appending
- `location` is the location of the source in the source map.
- `explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise.
- `source` is the source code whose result is to be appending
- `location` is the location of the source in the source map.
- `explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise.

- `initializeBuffer()`
Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation.
Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation.

### Example for the compiler api.

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.

There is also [a jsfiddle with this code](https://jsfiddle.net/9D88g/162/) if you want to play around with it.


```javascript
function MyCompiler() {
Handlebars.JavaScriptCompiler.apply(this, arguments);
}
MyCompiler.prototype = new Handlebars.JavaScriptCompiler();

// Use this compile to compile BlockStatment-Blocks
MyCompiler.prototype.compiler = MyCompiler
MyCompiler.prototype.compiler = MyCompiler;

MyCompiler.prototype.nameLookup = function(parent, name, type) {
MyCompiler.prototype.nameLookup = function (parent, name, type) {
if (type === 'context') {
return this.source.functionCall('helpers.lookupLowerCase', '', [parent, JSON.stringify(name)])
return this.source.functionCall('helpers.lookupLowerCase', '', [
parent,
JSON.stringify(name),
]);
} else {
return Handlebars.JavaScriptCompiler.prototype.nameLookup.call(this, parent, name, type);
return Handlebars.JavaScriptCompiler.prototype.nameLookup.call(
this,
parent,
name,
type
);
}
}
};

var env = Handlebars.create();
env.registerHelper('lookupLowerCase', function(parent, name) {
return parent[name.toLowerCase()]
})
env.registerHelper('lookupLowerCase', function (parent, name) {
return parent[name.toLowerCase()];
});

env.JavaScriptCompiler = MyCompiler;

var template = env.compile('{{#each Test}} ({{Value}}) {{/each}}');
console.log(template({
test: [
{value: 'a'},
{value: 'b'},
{value: 'c'}
]
}));
console.log(
template({
test: [{ value: 'a' }, { value: 'b' }, { value: 'c' }],
})
);
```
Loading

0 comments on commit 9413ea9

Please sign in to comment.