injectify-condition
v1.0.4
Published
Condition plugin for injectify
Downloads
5
Readme
Injectify condition
Remove conditional code from template
Install
npm install --save-dev injectify-condition
Usage
Configure gulp
:
var gulp = require("gulp"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
require('injectify-condition/inject');
gulp.task('js', function () {
var options = {
injectify: {
condition: {
'is-mobile': true,
'is-desktop': false
}
}
};
var bundleStream = browserify('./src/index.js')
.transform(require("injectify"))
.bundle();
return bundleStream
.pipe(source('index.js'))
.pipe(gulp.dest('dist'));
});
And write some template
{{#is-mobile}}
This template will be rendered
{{else}}
This code will be removed
{{/is-mobile}}
You can pass helper to if
and unless
statements
{{#unless (is-mobile)}}
This code will be removed for is-mobile=true
{{/unless}}
You can pass variables as params and hashes to helpers
{{my-awesome-helper (is-desktop) touch=(is-mobile)}}
will be transform into
{{my-awesome-helper false touch=true}}
Webpack
module.exports = {
module: {
loaders: [
{
test: /\.hbs/,
loader: 'injectify',
query: JSON.stringify({
condition: {
'is-mobile': true,
'is-desktop': false
}
})
}
]
}
}