Coder Social home page Coder Social logo

brunch-preval's Introduction

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
	}
};

brunch-preval's People

Contributors

seanmorris avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.