Git Product home page Git Product logo

poirot's Introduction

Poirot

Description

Allows you to use Mustache template partials in Rails, also ads a helper method to easily allow JavaScript to re-use the same templates.

Usage

Create a partial just like you would with erb, prefixing the name with an underscore.

app/views/posts/_post_list.html.mustache

The template will have access to all normal rails helper methods and any instance variables that were set in the controller. If you need more than this an optional view class can be included, it should have the same name as the partial, but without the underscore.

app/views/posts/post_list_view.rb

module Posts
  class PostListView < Poirot::View
    def foo
      "bar"
    end

    def post_link
      post_path(post)
    end
  end
end

The view class has access to all the normal Rails helpers and access to the controller instance variables, e.g @post becomes the method post.

Also included is a simple view helper for including mustache templates in a page ready for use by JavaScript.

<%= template_include_tag 'post_list' %>

The above will insert a script tag with the contents of the partial called post_list, the type will be set as text/mustache and the id will be post-list-template.

<script id="post-list-template" type="text/mustache">
  <!-- template will be here! -->
</script>

Dependencies

  • Rails >3.0.0
  • Mustache

More

An example app using Poirot

Credits

Mark Evans & Oliver Nightingale

poirot's People

Contributors

olivernn avatar

Stargazers

 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.