Giter Club home page Giter Club logo

injectify-1's Introduction

Injectify Build Status npm downloads

Inspired by hbsfy and based on it source code.

Transform handlebars AST and add support of require helper for browserify/webpack automatic injection;

Install

npm install --save-dev injectify

Use with browserify

Use it as Browserify transform module with -t:

browserify -t injectify main.js > bundle.js

If you prefer gulp:

var gulp = require("gulp"),
    browserify = require("browserify"),
    source = require("vinyl-source-stream"),
    
gulp.task('js', function () {
    var bundleStream = browserify('./src/main.js')
        .transform(require("injectify"))
        .bundle();

    return bundleStream
        .pipe(source('main.js'))
        .pipe(gulp.dest('dist'));
});

Use with webpack

Configure webpack

{
    "module": {
        "loaders": [
            {"test": /\.hbs/, "loader": "injectify"}
        ]
    }
}

Load helper

In file ./src/main.js require injectify require helper:

require("injectify/require");

Now you can use require helper in your templates:

Simple require some module with string export: 

{{require "../string-module"}}

Pass require result as param to another helper: 

{{formatUser (require "../user-module")}}

Pass require result as hash param to another helper: 

{{formatUser user=(require "../user-module")}}

require helper works like original browserify. You can require modules relative to template file or node_modules directory

Relative require {{require "../utils/strange-module"}} 

or globally defined {{require "my-utils"}}

Examples of usage

  • Include helper - allow include templates like partials, but with browserify
  • View helper - allow render marionette view direct to template

Changelog

v2.2.0

  • Handlebars 4.0 support

injectify-1's People

Contributors

ftdebugger avatar

Watchers

James Cloos 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.