Git Product home page Git Product logo

jadeify's Introduction

A Browserify Transform for Jade

Jadeify lets you use Jade templates with browserify in the simplest way possible:

var template = require("./template.jade");

document.getElementById("my-thing").innerHTML = template({
    localVar: "value",
    anotherOne: "another value"
});

Setup

When creating your browserify bundle, just add this line:

bundle.transform(require("jadeify"));

or if you are a command line cowboy, something along the lines of

browserify -t jadeify entry.js -o bundle.js

Note that this project peer-depends on Jade and each template will do require("jade/runtime"), so everything will just work: there's no need to add any Jade-related stuff to your bundle manually. (See below if your need to customize this.)

So yeah, now requireing any .jade files will give you back a template function. Have fun!

Configuration

As with most browserify transforms, you can configure jadeify via the second argument to bundle.transform:

bundle.transform(require("jadeify"), { compileDebug: true, pretty: true });

or inside your package.json configuration:

{
    "name": "my-spiffy-package",
    "browserify": {
        "transform": [
            ["jadeify", { "compileDebug": true, "pretty": true }]
        ]
    }
}

Most options given to jadeify will be passed through to Jade's API.

runtimePath option

There is one additional option, runtimePath, which can be used to customize the require statement inserted at the top of every resulting template. If supplied, instead of require("jade/runtime"), the given module ID will be required.

This can be useful if you are using jadeify as a dependency in a standalone library. For example, if your package demo-package depends on both jade and jadeify, you can do

bundle.transform(require("jadeify"), { runtimePath: require.resolve("jade/runtime") });

inside your package. If your package is then located at node_modules/demo-package, and thus its jade dependency is located at node_modules/demo-package/node_modules/jade, this will ensure that the template files output by your library contain the equivalent of require("demo-package/node_modules/jade/runtime"), instead of the default require("jade/runtime"). This way your library completely encapsulates the presence of Jade, and doesn't require its installation at top level.

jadeify's People

Contributors

domenic avatar icflorescu avatar w0rm avatar wbinnssmith avatar gdzx avatar jazzzz avatar joeybaker avatar piotrd avatar streetstrider avatar industrial avatar kanaabe avatar nmccready 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.