1.0.4 • Published 8 years ago

injectify-condition v1.0.4

Weekly downloads
7
License
ISC
Repository
github
Last release
8 years ago

Injectify condition Build Status npm downloads

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
                    }
                })
            }
        ]
    }
}
1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago