Giter Site home page Giter Site logo

yhandlebars's Introduction

yhandlebars

yhandlebars is a YUI handlebars based command-line application for precompiling templates as YUI modules. Checkout the official Handlebars docs site at www.handlebarsjs.com and the official YUI Handlebars docs at yuilibrary.com/yui/docs/handlebars/.

Precompiling Templates

Handlebars allows templates to be precompiled and included as javascript code rather than the handlebars template allowing for faster startup time.

Installation

The precompiler script may be installed via npm using the npm install -g yhandlebars command.

Usage

Precompile handlebar templates.
Usage: yhandlebars <template> ...

Options:
  -f, --output     Output File                                                                [string]
  -k, --known      Known helpers                                                              [string]
  -o, --knownOnly  Known helpers only                                                         [boolean]
  -m, --min        Minimize output                                                            [boolean]
  -s, --simple     Output template function only.                                             [boolean]
  -r, --root       Template root. Base value that will be stripped from template names.       [string]
  -n, --namespace  Namespace in which the templates object will reside under the Y instance.  [string]  [default: "Handlebars"]
  -p, --plain      Plain module output without YUI.add(...) wrapper function.                 [boolean]

Simple mode

If using the simple mode the precompiler will generate a single javascript method.

Module mode

If using the precompiler's normal mode, the resulting templates will be stored to the Y.Handlebars.templates object using the relative template name sans the extension. These templates may be executed in the same manner as templates.

Namespacing

To change the location where the templates object should be stored on the Y instance just pass a namespace argument like this -n NS and the templates will be stored to Y.NS.templates.

Mustache compatible

The compiler will also precompile *.mustache and *.hbs files.

Using templates in YUI

The templates will be wrapped in a YUI.add(...) call to be used as a YUI module. The name of the module will be the relative -f output file name sans the extension. If the -f argument is not given the module name will default to handlebars-templates.

Since the module is configured to require handlebars-base you can simply use the module in YUI like this:

<!DOCTYPE html>
<meta charset="utf-8">
<title>My Favorite Food</title>

<body>
<div id="content"></div>

<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script>
YUI().use("handlebars-templates", "node", function (Y) {
    
    // Render the template and insert its output into the page.
    var output = Y.Handlebars.templates["my-template"]({food: "pie"});
    Y.one("#content").append(output);
});
</script>
</body>

Handlebars.js

yhandlebars is a port of the handlebarsjs command-line application to YUI handlebars.

yhandlebars's People

Contributors

cquinders avatar okuryu avatar

Stargazers

Tobias Eckardt avatar James Bunt avatar Michael Wu avatar Forrest Galloway avatar Dav Glass avatar

Watchers

 avatar

yhandlebars's Issues

yhandlebars duplicates mustache-wax functionality.

Hi Christian,

I happened to notice @davglass star this project, and I was immediately intrigued. I am the author of mustache-wax, which is largely doing exactly the same thing as you're doing here (indeed, we even started from the same "inspiration" of the handlebars CLI code).

I've extended the handlebarsjs CLI pattern a bit, enabling it to be required by other modules in a programmatic way. I've also added nodeunit tests, and avoided pulling in the entirety of the yui3 package just for the handlebars compiler (which YUI3 is just wrapping). I think we could make it better by combining our efforts instead of splitting them.

I'm not cool enough to make a "call me maybe" reference, but perhaps we could merge projects?

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.