Giter VIP home page Giter VIP logo

dust_assets's Introduction

dust.js for the Rails asset pipeline

First of all! The credits goes to handlebars_assets we used this gem as a base for dust_assets. The dust_assets gem allows you to use dust.js templates within Rails applications.

dust.js

dust_assets right now comes with a packaged v0.3.0 of dust.js. Some work is being currently done in extracting dust.js source into a separate gem that could be used by other gems as well.

Installation

Load dust_assets in your Gemfile as part of the assets group

group :assets do
  gem 'dust_assets'
end

Then run 'bundle install'

Require dust.js in your Javascript manifest (i.e. application.js)

//= require dust

Precompiling

dust_assets also works when you are precompiling your assets. If you are deploying to Heroku, be sure to read the Rails guide and in your config/application.rb set:

config.assets.initialize_on_precompile = false

Your file extensions tell the asset pipeline how to process the file. Use .dust to compile the template with Dust. Combine it with .jst to add the compiled template to the JST global variable.

JST

sprockets ships with a simple JavaScript template wrapper called JST for use with the ejs and other gems.

dust_assets is compatible with JST. If you name your template files name.jst.dust, you will have access to your templates through the JST global just like your ejs templates.

A note about dust.js templates and the current implementation of dust_assets gem:

dust.js templates are asychronous so when using the compiled templates availables trough the JST object you must supply a callback along with the context in which the template will be evaluated, suppose you have a template in 'app/assets/javascripts/templates/hello.jst.dust' that looks like this:

  Hello {name}!

In your code do something like this (this example is taken from a real Spine.js application written in CoffeScript)

  JST['templates/hello.jst.dust'] name: "Aleksander", (out, err) ->
    @html out

In JavaScript should be something like this:

  JST['templates/hello.jst.dust']({ name: "Aleksander" }, function(out, err) {
    return this.html(out);
  });

Example Rails 3 application using ´dust_assets´:

You can go to dust_assests_example and
see some basic usage of dust_assets.

Thanks

Thank you Aleksander Williams (@akdubya) for dust.js.

Thank you Les Hill (@leshill) handlebars_assets

Thank you Charles Lowell (@cowboyd) for therubyracer and handlebars.rb.

Contributing

Once you've made your great commits

  1. Fork
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Create a Pull Request from your branch
  5. That's it!

Authors

  • Anderson Sequera (@andersonsp)
  • Jose Narvaez (@goyox86)
  • Manuel Mujica (@evilsaurer)

Contributors

  • Your name here!

dust_assets's People

Contributors

goyox86 avatar

Watchers

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