GithubHelp home page GithubHelp logo

tudo / static-handlebars-brunch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bloudermilk/static-handlebars-brunch

0.0 2.0 0.0 96 KB

Compile Handlebars templates to HTML with brunch

Home Page: https://npmjs.org/package/static-handlebars-brunch

License: MIT License

CoffeeScript 100.00%

static-handlebars-brunch's Introduction

static-handlebars-brunch

static-handlebars-brunch is a Brunch plugin that facilitates the use of Handlebars as a build-time templating engine. This is useful if you have many "static" pages that need the ability to include partials or other dynamic content at build time.

Installation

npm install --save static-handlebars-brunch

This will add it to your package.json file and install the package automatically.

How it works

Any .hbs file found in app/templates will be compiled to .html and copied into app/assets. Brunch will then copy app/assets to public.

Partials

A partial is any .hbs file in app/templates that begins with an underscore, for example: app/templates/_header.hbs.

You can use the standard Handlebars partial helper to include partials in a template:

{{> header}}

<p>This is a page!</p>

{{> footer}}

A custom partial helper is available which allows you to pass variables to your partials.

{{partial "header" title="My great page"}}

<p>This is a page!</p>

{{> "footer"}}

Configuration

Output directory

You can customize the output directory (default: app/assets)

exports.config =
  plugins:
    staticHandlebars:
      outputDirectory: 'app/another_directory'

Additional project-specific configuration

You can set the context and configure Handlebars in your project by providing an include file.

exports.config =
  plugins:
    staticHandlebars:
      includeFile: 'app/another_directory/include.js'

The file may look like this:

###
Parameters:
- handlebars -> reference to the handlebars object

Returns:
- context -> object which represents the context in which the templates will
  be executed
###

module.exports = (handlebars) ->
  context =
    color: 'blue'
  
  # make calls on the `handlebars` variable to define additional helpers etc.
  
  context

TODO

This library has a long way to go in terms of configurability and compatability with other workflows. The following are known features which we would like to support. Feel free to send a pull request if you end up implementing any.

  • Support a custom source path (ie. app/templates).
  • Play nicely with handlebars-brunch (ie. figure out how to support both plugins in one app).
  • Support custom extensions (only .hbs is supported now).
  • Cache partials (right now partials are recompiled up every time a file is changed).
  • Write tests

Contribution

  • Fork this repository
  • Create a feature branch on your fork
  • Recompile the coffeescript: coffee -c -o lib/ src/index.coffee
  • Make a Pull Request

License

static-handlebars-brunch is an open source project released under the MIT License. See MIT-LICENSE in the project root for more details.

static-handlebars-brunch's People

Contributors

faldrian avatar nerdoc avatar tudo avatar

Watchers

 avatar  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.