grunt-add-view
v0.1.0
Published
Input html files and output a js file that exports all of the html as an object in the form {filename:html text}. It is intended to be used as a view object in single page web apps.
Downloads
2
Readme
grunt-add-view
Input html files and out put a js file that exports all the html as a object of the for {filename:html text}. It is intended to be used as a view object in single page web apps.
Getting Started
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-add-view --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-add-view');
The "add_view" task
Overview
In your project's Gruntfile, add a section named add_view
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
add_view: {
your_target: {
// Target-specific file lists go here.
},
},
})
Usage Examples
Default Options
In this example, the files src/login.htm and src/register.html are compiled into a view object that wrapped in a common js export and stored in dest/view.js. So if the login.html
file has the content <label>Hello World</label>
and the register.html
file had the content <label for="name">NAME</label><input id="name">
, the generated result contained in view.js
would be:
'use strict';
module.exports = {"login":"<label>Hello World</label>", "register":"<label for=\"name\">NAME</label><input id=\"name\">"};
grunt.initConfig({
add_view: {
files: {
'dest/view.js': ['src/login.html', 'src/register.html'],
},
},
})
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
(Nothing yet)
License
Copyright (c) 2015 Dale Corns. Licensed under the MIT license.