Giter Club home page Giter Club logo

handlebars-rust's Introduction

handlebars-rust

Rust templating with Handlebars.

Warning: This project, like rust, is in its early stage. Breaking changes are constantly introduced.

Why Handlebars?

For information about handlebars, you will go to handlebars.js.

It's my favorite templating tool by far. I used it in Delicious.com as javascript-side template in 2013. Also I maintained a Clojure wrapper for Handlebars.java, hbs. And you may notice the close relationship between Ember.js and Rust community, handlebars is the default templating language of Ember.js framework, which powers crates.io.

Reasons I prefer Handlebars:

  • Never ruin your Rust with HTML
  • Never ruin your HTML with Rust
  • Templating without a reuse mechanism is shit
  • Templating without customization is nothing but shit

Handlebars provides:

  • Separation of Rust and HTML
  • A few control structures makes templating easier
  • Few control structures stops you to put logic into templates
  • Template reuse with include(>), partial and block
  • Customize template behavior with helpers

Limitations:

  • As a static typed language, it's a little verbose to use handlebars
  • You will have to make your data ToJson-able, so we can render it.

Usage

Check examples in the source. The example shows you how to:

  • Create a Handlebars and register the template from files
  • Create a custom Helper by impl HelperDef, and register it
  • Render something
  • Make your custom struct ToJson-able.

Run cargo run --example render to see results. (or RUST_LOG=INFO cargo run --example render) for logging output.

Handlebars-js features supported in Handlebars-rust

  • Expression / Block Helpers
  • Built-in helpers
  • Customizing helper
  • Parameter and hashes for helper
  • Partials, include
  • Omitting whitespace with ~

Feel free to report an issue if you find something broken. We aren't going to implement all features of handlebars-js, but we should have a workaround for cases we don't support.

Handlebars for Iron

I have started another project handlebars-iron for the Iron web framework.

License

MIT, of course.

Contact

Ning Sun ([email protected])

handlebars-rust's People

Contributors

sunng87 avatar blaenk avatar burntsushi avatar eric-guo avatar

Watchers

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