Code Monkey home page Code Monkey logo

mustache-rails's Introduction

Mustache Rails

Implements Mustache views and templates for Rails 3.x

Installation

gem 'mustache-rails', :require => 'mustache/railtie'

Or alternatively require 'mustache/railtie' in your config/application.rb.

Usage

In typical mustache fashion, .mustache templates go under app/templates and view .rb files go under app/views. Any view classes will be looked for under the ::Views modules.

Simple template scaffolding:

# app/views/layouts/application.rb
module Views
  module Layouts
    class Application < ActionView::Mustache
      def title
        "Hello"
      end
    end
  end
end
{{ ! app/templates/layouts/application.mustache }}
<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <title>{{title}}</title>
</head>
<body>
  {{yield}}
</body>
</html>
# app/views/users/show.rb
module Views
  module Users
    class Show < Layouts::Application
      attr_reader :user
    end
  end
end
{{ ! app/templates/users/show.mustache }}
{{#user}}
  <h1>{{name}}</h1>
{{/user}}

Optional Configuration

# config/application.rb
module Foo
  class Application < Rails::Application
    # Config defaults
    config.mustache.template_path = "app/templates"
    config.mustache.view_path = "app/views"
    config.mustache.view_namespace = "::Views"
  end
end

License

Copyright © 2012 Joshua Peek.

Released under the MIT license. See LICENSE for details.

mustache-rails's People

Contributors

dasch avatar joeybutler avatar josh 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.