Coder Social home page Coder Social logo

ahmader / grunt-handlebars-compiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mattacular/grunt-handlebars-compiler

0.0 2.0 0.0 129 KB

Grunt.js task to precompile *.handlebars templates (default target = Handlebars.templates.*)

License: MIT License

JavaScript 100.00%

grunt-handlebars-compiler's Introduction

grunt-handlebars-compiler

A Grunt plugin for pre-compiling Handlebars templates to a single concatenated file (or individually, whichever floats your boat).

Getting Started

*IMPORTANT: This plugin requires Grunt 0.4 or higher - it is recommended that you always run the latest version

Install the task:

npm install grunt-handlebars-compiler

Then add this line to your project's Gruntfile.js:

grunt.loadNpmTasks('grunt-handlebars-compiler');

This allows you to use the 'handlebars' task to specify targets!

	handlebars: {
		all: {
			/*
				The output will be formatted as a Common JS module, using a require()
				statement where the argument is the Handlebars path provided in the option.
			*/
			files: {
				'pkg/template-compile-test.js': 'template/*.handlebars'
			},
			options: {
				exportCommonJS: 'handlebars'
			}
		},
		some: {
			/*
				The output will be set to register two templates under 'myApp.templates' namespace after 
				stripping the templateRoot:
					* myApp.templates.template1
					* myApp.templates.template2
			*/
			files: {
				'pkg/template-compile-test2.js': [
					'template/webApp-template1.handlebars', 
					'template/webApp-template2.handlebars'
				] 
			},
			options: {
				namespace: 'myApp.templates',
				templateRoot: 'webApp-',
				knownHelpers: ['if', 'each']
			}
		}
	}

The handlebars task has the following options, none of which are required. The defaults are shown here:

	{
		separator: '\n',					// specify a character to delimit individual compiled files in the output
		namespace: 'Handlebars.templates',	// specify a namespace for templates to be set to register to
		exportAMD: false,					// export compiled templates as AMD (RequireJS) module
		exportCommonJS: false,				// export as Common JS, provide string path to Handlebars instead of false
		pathToHandlebars: '',				// only relevant if 'exportAMD === true' - provide path to Handlebars
		knownHelpers: [],					// provide an array of known helpers
		knownOnly: false,					// compile with known helpers only (requires 'knownHelpers')
		templateRoot: false,				// a value to strip from the beginning of template names
		partial: false						// EXPERIMENTAL: specify that target templates are partials
	}

Note: You may choose only one 'exportX' option. (Eg. you can't use exportAMD and exportCommonJS on the same task. That would just be straight silly.)

Documentation

The handlebars task is a multi task, meaning that it will implicitly iterate over all of its targets if no target is specified.

Contributing

Feel free to fork if you see possible improvements or contact me directly if you want to contribute to this project (or just submit a pull request): [email protected]

Author

License

This project is licensed under the MIT license.

grunt-handlebars-compiler's People

Contributors

ahmader avatar mattacular 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.