0.0.4-a • Published 2 years ago

brunch-preval v0.0.4-a

Weekly downloads
11
License
Apache-2.0
Repository
-
Last release
2 years ago

avatar

brunch-preval v0.0.3

Simple JS based preprocessing for Brunch static HTML files.

seanmorris-brunch-preval Size badge

Install

$ npm i brunch-preval

Use

Simply open a static HTML file and put some javascript inside {{ double curly braces }}. The javascript will be evaluated, and the results will be interpolated in its place.

<html><body>{{ Math.random() }}</body></html>

Escaping

Use the backslash (\) character to escape a replacement

<html><body>\{{ This won't be processed. }}</body></html>

Escaping Escapes

Backslashes may also be used to escape a backslash.

<html>
<body>
	{{ "This WILL be processed." }}
	\{{ "This won't be processed."" }}
	\\{{ "This WILL be processed and will be preceeded by a single backslash." }}
	\\\{{ "This won't be processed and will be preceeded by a single backslash." }}
	\\\\{{ "This WILL be processed and will be preceeded by a 2 backslashes." }}
</body>
</html>

Alt Notation

<<< triple angle brackets >>> or ((( triple parens ))) may also be used.

Configure

See also configuring Brunch

Include/exclude

You can more finely control which HTML files are processed by specifying a regex for the include & exclude keys.

If a file matches both include and exclude the include will take precedence.

exports.plugins = {
	preval:{
		exclude: /thing.html$/,
		, include: /something.html$/,
	}
};

Tokens

Tokens can be specified in your Brunch config.

Tokens may be static values or the results of a function. Dynamic tokens will be generated once per compile pass, and will have the same value for all files processed in each pass.

Tokens in templates can be accessed on the _ object.

<html><body>{{ _.BUILD_TIME }}</body></html>
exports.plugins = {
	preval:{
		tokens: {
			STATIC_VAL: 'Some value',
			BUILD_TIME: ()=>(new Date).getTime() / 1000,
		}
	}
};

Suppress Logging

Set log to false in your Brunch config to stop BrunchPreval from logging to the console during compilation.

exports.plugins = {
	preval:{
		log: false
	}
};
0.0.4-a

2 years ago

0.0.4

3 years ago

0.0.3

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago