https://github.com/railsware/smt_rails
Shared mustache templates for rails 3.
https://github.com/railsware/smt_rails
Last synced: 9 months ago
JSON representation
Shared mustache templates for rails 3.
- Host: GitHub
- URL: https://github.com/railsware/smt_rails
- Owner: railsware
- License: mit
- Created: 2012-04-10T17:32:53.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2017-11-14T14:43:50.000Z (about 8 years ago)
- Last Synced: 2025-03-30T16:13:46.764Z (10 months ago)
- Language: Ruby
- Homepage: http://blog.railsware.com/2012/04/12/shared-mustache-templates-for-rails-3/
- Size: 46.9 KB
- Stars: 109
- Watchers: 46
- Forks: 21
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmtRails
Shared mustache templates for Rails 3 and 4 and Sprockets 2 and 3.
## Installation
Add this line to your application's Gemfile:
gem 'smt_rails', :git => 'git://github.com/railsware/smt_rails.git'
And then execute:
$ bundle
Or install it yourself as:
$ gem install smt_rails
## Usage
$ rails g smt_rails:install
Generator add into "application.js" requirements for mustache and "templates" folder in "app". Next you can create mustache templates in this folder or subfolders.
For example:
File: "app/templates/tests/_test.mustache"
Hello {{msg}}!!!
In view you can render this template by this way:
<%= render "tests/test", :mustache => {msg: "Test"} %>
The same template you can render in JavaScript:
var content = SMT['tests/test']({msg: "Test"});
## Mustache Partials
File: "app/templates/people/_list.mustache"
{{#people}}{{>people/item}}{{/people}}
File: "app/templates/people/_item.mustache"
Name: {{name}}
In view you can render this template by this way:
<%= render "people/list", :mustache => {people: [{name: 'Alex'}, {name: 'John'}]} %>
The same template you can render in JavaScript:
var content = SMT['people/list']({people: [{name: 'Alex'}, {name: 'John'}]});
## Configuration
SmtRails.configure do |config|
config.template_extension = 'mustache' # change extension of mustache templates
config.action_view_key = 'mustache' # change name of key for rendering in ActionView mustache template
config.template_namespace = 'SMT' # change templates namespace in javascript
config.template_base_path = Rails.root.join("app", "templates") # templates dir
end
## Demo
Site: [http://st-rails-example.herokuapp.com/](http://st-rails-example.herokuapp.com/)
Source code: [https://github.com/le0pard/st_rails_example](https://github.com/le0pard/st_rails_example)
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request