Skip to content

Commit

Permalink
Merge pull request #208 from pcardune/05-18-Install_prettier
Browse files Browse the repository at this point in the history
Use prettier to format code
  • Loading branch information
pcardune authored May 20, 2022
2 parents 3ba94fc + 07be695 commit bf40145
Show file tree
Hide file tree
Showing 38 changed files with 7,017 additions and 720 deletions.
7 changes: 2 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
"env": {
"node": true
},
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "prettier"],
"rules": {
"no-console": "off",
"indent": ["error", 2, { "VariableDeclarator": { "var": 2, "let": 2, "const": 3 }}],
"no-trailing-spaces": "error",
"semi": ["error", "always"],
"no-unused-vars": ["error", { "args": "none" }],
"comma-dangle": "off",
"no-cond-assign": "off",
"no-cond-assign": "off"
}
}
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"node": true
}
}
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ignore a bunch of stuff
coverage
*.handlebars
examples/**/dist/*
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@
## [1.7.2] - 2022-05-18

### Fixed

- Upgraded async dependency to 3.2.2 (#207)

## [1.7.1] - 2018-12-18

### Fixed

- Fixed use stringifyRequest instead of absolute paths in loader output (#167)

## [1.7.0] - 2018-03-20

### Fixed

- Use `loaderContext.rootContext` instead of `loaderContext.options` when used with Webpack 4
- Fixed resolving of inline partials and partial blocks with failover content (#106, #135)

## [1.6.0] - 2017-09-01 ##
## [1.6.0] - 2017-09-01

### Added

- Added `ignoreHelpers` option to skip automatic lookup/bundling of helpers
- Added `precompileOptions` to pass options to handlebars precompile

## [1.5.0] - 2017-04-20

### Added

- Added `helperResolver` config option to override the default helper resolution

### Fixed

- Fixed webpack deprecation warnings

## [1.4.0] - 2016-09-02

### Added

- Fixed resolving relative helpers on first pass when helper directories are given
- Added `ignorePartials` option to skip automatic lookup/bundling of partials
- Added `compat` option to enable Mustache lookup compatibility.
Expand All @@ -42,23 +49,25 @@
resolution

### Fixed

- Previously, if a partial name began with an `@`, it was ignored and treated
as an internal to handlebars partial. Now that checks specifically for
partials named `@partial-block` so that `{{> @a/b/c.hbs }}` is a valid partial reference

## [1.3.0] - 2016-04-29

### Added

- New `partialDirs` query option allows specifying additional directories to be searched for partials. Thank you @lostthetrail.
- New `preventIndent` query option to avoid nested partials adding whitespace to
`textarea` and `pre` elements.

## [1.2.0] - 2016-03-15

### Added

- Helpers can now use ECMAScript 6 export syntax and have their default export used. Thank you @kt0.
- New `exclude` query option lets you prevent helpers from being resolved to
modules in specified directories (such as `node_modules`). Thank you @ericmatthys.


See [keepachangelog.com](http://keepachangelog.com/) for how to update this file.
61 changes: 26 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

A [handlebars](http://handlebarsjs.com) template loader for [webpack](https://github.com/webpack/webpack).

*Handlebars 4 now supported*
_Handlebars 4 now supported_

## Installation

Expand Down Expand Up @@ -53,40 +53,31 @@ A file "/folder/file.handlebars".

The following query (or config) options are supported:

- *helperDirs*: Defines additional directories to be searched for helpers. Allows helpers to be defined in a directory and used globally without relative paths. You must surround helpers in subdirectories with brackets (Handlerbar helper identifiers can't have forward slashes without this). See [example](https://github.com/altano/handlebars-loader/tree/master/examples/helperDirs)
- *runtime*: Specify the path to the handlebars runtime library. Defaults to look under the local handlebars npm module, i.e. `handlebars/runtime`.
- *extensions*: Searches for templates with alternate extensions. Defaults are .handlebars, .hbs, and '' (no extension).
- *inlineRequires*: Defines a regex that identifies strings within helper/partial parameters that should be replaced by inline require statements. **Note**: For this to work, you'll have to disable the `esModule` Option in the corresponding file-loader entry in your webpack config.
- *rootRelative*: When automatically resolving partials and helpers, use an implied root path if none is present. Default = `./`. Setting this to be empty effectively turns off automatically resolving relative handlebars resources for items like `{{helper}}`. `{{./helper}}` will still resolve as expected.
- *knownHelpers*: Array of helpers that are registered at runtime and should not explicitly be required by webpack. This helps with interoperability for libraries like Thorax [helpers](http://thoraxjs.org/api.html#template-helpers).
- *exclude*: Defines a regex that will exclude paths from resolving. This can be used to prevent helpers from being resolved to modules in the `node_modules` directory.
- *debug*: Shows trace information to help debug issues (e.g. resolution of helpers).
- *partialDirs*: Defines additional directories to be searched for partials. Allows partials to be defined in a directory and used globally without relative paths. See [example](https://github.com/altano/handlebars-loader/tree/master/examples/partialDirs)
- *ignorePartials*: Prevents partial references from being fetched and bundled. Useful for manually loading partials at runtime.
- *ignoreHelpers*: Prevents helper references from being fetched and bundled. Useful for manually loading helpers at runtime.
- *precompileOptions*: Options passed to handlebars precompile. See the Handlebars.js [documentation](http://handlebarsjs.com/reference.html#base-precompile) for more information.
- *config*: Tells the loader where to look in the webpack config for configurations for this loader. Defaults to `handlebarsLoader`.
- *config.partialResolver* You can specify a function to use for resolving partials. To do so, add to your webpack config:
```js
handlebarsLoader: {
partialResolver: function(partial, callback){
// should pass the partial's path on disk
// to the callback. Callback accepts (err, locationOnDisk)
}
}
```
- *config.helperResolver* You can specify a function to use for resolving helpers. To do so, add to your webpack config:
```js
handlebarsLoader: {
helperResolver: function(helper, callback){
// should pass the helper's path on disk
// to the callback if one was found for the given parameter.
// Callback accepts (err, locationOnDisk)
// Otherwise just call the callback without any arguments
}
}
```
See [`webpack`](https://github.com/webpack/webpack) documentation for more information regarding loaders.
- _helperDirs_: Defines additional directories to be searched for helpers. Allows helpers to be defined in a directory and used globally without relative paths. You must surround helpers in subdirectories with brackets (Handlerbar helper identifiers can't have forward slashes without this). See [example](https://github.com/altano/handlebars-loader/tree/master/examples/helperDirs)
- _runtime_: Specify the path to the handlebars runtime library. Defaults to look under the local handlebars npm module, i.e. `handlebars/runtime`.
- _extensions_: Searches for templates with alternate extensions. Defaults are .handlebars, .hbs, and '' (no extension).
- _inlineRequires_: Defines a regex that identifies strings within helper/partial parameters that should be replaced by inline require statements. **Note**: For this to work, you'll have to disable the `esModule` Option in the corresponding file-loader entry in your webpack config.
- _rootRelative_: When automatically resolving partials and helpers, use an implied root path if none is present. Default = `./`. Setting this to be empty effectively turns off automatically resolving relative handlebars resources for items like `{{helper}}`. `{{./helper}}` will still resolve as expected.
- _knownHelpers_: Array of helpers that are registered at runtime and should not explicitly be required by webpack. This helps with interoperability for libraries like Thorax [helpers](http://thoraxjs.org/api.html#template-helpers).
- _exclude_: Defines a regex that will exclude paths from resolving. This can be used to prevent helpers from being resolved to modules in the `node_modules` directory.
- _debug_: Shows trace information to help debug issues (e.g. resolution of helpers).
- _partialDirs_: Defines additional directories to be searched for partials. Allows partials to be defined in a directory and used globally without relative paths. See [example](https://github.com/altano/handlebars-loader/tree/master/examples/partialDirs)
- _ignorePartials_: Prevents partial references from being fetched and bundled. Useful for manually loading partials at runtime.
- _ignoreHelpers_: Prevents helper references from being fetched and bundled. Useful for manually loading helpers at runtime.
- _precompileOptions_: Options passed to handlebars precompile. See the Handlebars.js [documentation](http://handlebarsjs.com/reference.html#base-precompile) for more information.
- _config_: Tells the loader where to look in the webpack config for configurations for this loader. Defaults to `handlebarsLoader`.
- _config.partialResolver_ You can specify a function to use for resolving partials. To do so, add to your webpack config:
```js
handlebarsLoader: {
partialResolver: function(partial, callback){
// should pass the partial's path on disk
// to the callback. Callback accepts (err, locationOnDisk)
}
}
```
- _config.helperResolver_ You can specify a function to use for resolving helpers. To do so, add to your webpack config:
`js handlebarsLoader: { helperResolver: function(helper, callback){ // should pass the helper's path on disk // to the callback if one was found for the given parameter. // Callback accepts (err, locationOnDisk) // Otherwise just call the callback without any arguments } } `
See [`webpack`](https://github.com/webpack/webpack) documentation for more information regarding loaders.

## Full examples

Expand Down
24 changes: 12 additions & 12 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var bookListingTemplate = require("./book-listing.handlebars");

document.addEventListener("DOMContentLoaded", function() {
var div = document.createElement('div');
div.innerHTML = bookListingTemplate({
username: "test",
info: "Your books are due next Tuesday",
books: [
{ title: "A book", synopsis: "With a description" },
{ title: "Another book", synopsis: "From a very good author" },
{ title: "Book without synopsis" }
]
});
document.body.appendChild(div);
document.addEventListener("DOMContentLoaded", function () {
var div = document.createElement("div");
div.innerHTML = bookListingTemplate({
username: "test",
info: "Your books are due next Tuesday",
books: [
{ title: "A book", synopsis: "With a description" },
{ title: "Another book", synopsis: "From a very good author" },
{ title: "Book without synopsis" },
],
});
document.body.appendChild(div);
});
4 changes: 2 additions & 2 deletions examples/basic/helpers/json.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function(object) {
module.exports = function (object) {
return JSON.stringify(object);
};
};
6 changes: 3 additions & 3 deletions examples/basic/helpers/title.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function() {
return this.title.toUpperCase()
};
module.exports = function () {
return this.title.toUpperCase();
};
12 changes: 6 additions & 6 deletions examples/basic/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module.exports = {
entry: "./app.js",
output: {
path: "dist",
filename: "bundle.js"
filename: "bundle.js",
},
resolve: {
fallback: path.join(__dirname, "helpers")
fallback: path.join(__dirname, "helpers"),
},
module: {
loaders: [{ test: /\.handlebars$/, loader: __dirname + "/../../" }]
}
};
module: {
loaders: [{ test: /\.handlebars$/, loader: __dirname + "/../../" }],
},
};
22 changes: 10 additions & 12 deletions examples/custom-block-helper/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
var template = require("./template.handlebars");

document.addEventListener("DOMContentLoaded", function() {
var div = document.createElement('div');
div.innerHTML = template({
user: {
name: "jack",
info: [
{ status: "leaving" }
]
}
});
document.body.appendChild(div);
});
document.addEventListener("DOMContentLoaded", function () {
var div = document.createElement("div");
div.innerHTML = template({
user: {
name: "jack",
info: [{ status: "leaving" }],
},
});
document.body.appendChild(div);
});
4 changes: 2 additions & 2 deletions examples/custom-block-helper/helpers/checkStatus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function (data, options) {
return options.fn( data.info[0] );
};
return options.fn(data.info[0]);
};
15 changes: 10 additions & 5 deletions examples/custom-block-helper/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ module.exports = {
entry: "./app.js",
output: {
path: "dist",
filename: "bundle.js"
filename: "bundle.js",
},
module: {
loaders: [{ test: /\.handlebars$/, loader: __dirname + "/../../?helperDirs[]=" + __dirname + "/helpers" }]
}
};
module: {
loaders: [
{
test: /\.handlebars$/,
loader: __dirname + "/../../?helperDirs[]=" + __dirname + "/helpers",
},
],
},
};
8 changes: 5 additions & 3 deletions examples/external-runtime/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var bookTemplate = require("./book.handlebars");

console.log(bookTemplate({
username: "Alan"
}));
console.log(
bookTemplate({
username: "Alan",
})
);
47 changes: 27 additions & 20 deletions examples/external-runtime/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@ module.exports = {
output: {
path: "dist",
filename: "bundle.js",
libraryTarget: 'umd',
library: 'App'
libraryTarget: "umd",
library: "App",
},
resolve: {
fallback: path.join(__dirname, "helpers")
fallback: path.join(__dirname, "helpers"),
},
externals: [{
'handlebars/runtime': {
root: 'Handlebars',
amd: 'handlebars.runtime',
commonjs2: 'handlebars/runtime',
commonjs: 'handlebars/runtime'
externals: [
{
"handlebars/runtime": {
root: "Handlebars",
amd: "handlebars.runtime",
commonjs2: "handlebars/runtime",
commonjs: "handlebars/runtime",
},
'handlebars': {
root: 'Handlebars',
amd: 'Handlebars',
commonjs: 'handlebars',
commonjs2: 'handlebars'
}
}],
module: {
loaders: [{ test: /\.handlebars$/, loader: __dirname + "/../..?runtime=handlebars/runtime" }]
}
};
handlebars: {
root: "Handlebars",
amd: "Handlebars",
commonjs: "handlebars",
commonjs2: "handlebars",
},
},
],
module: {
loaders: [
{
test: /\.handlebars$/,
loader: __dirname + "/../..?runtime=handlebars/runtime",
},
],
},
};
24 changes: 12 additions & 12 deletions examples/helperDirs-multiple/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var bookListingTemplate = require("./book-listing.handlebars");

document.addEventListener("DOMContentLoaded", function() {
var div = document.createElement('div');
div.innerHTML = bookListingTemplate({
username: "test",
books: [
{ title: "A book", synopsis: "With a description" },
{ title: "Another book", synopsis: "From a very good author" },
{ title: "Book without synopsis" }
]
});
document.body.appendChild(div);
});
document.addEventListener("DOMContentLoaded", function () {
var div = document.createElement("div");
div.innerHTML = bookListingTemplate({
username: "test",
books: [
{ title: "A book", synopsis: "With a description" },
{ title: "Another book", synopsis: "From a very good author" },
{ title: "Book without synopsis" },
],
});
document.body.appendChild(div);
});
6 changes: 3 additions & 3 deletions examples/helperDirs-multiple/helpers1/title.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function() {
return this.title.toUpperCase();
};
module.exports = function () {
return this.title.toUpperCase();
};
Loading

0 comments on commit bf40145

Please sign in to comment.