Socket
Socket
Sign inDemoInstall

injectify-condition

Package Overview
Dependencies
10
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    injectify-condition

Condition plugin for injectify


Version published
Maintainers
1
Install size
12.4 kB
Created

Readme

Source

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

FAQs

Last updated on 30 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc