Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jimmycuadra/jquery-tmpl-rails
jQuery Templates for the Rails asset pipeline.
https://github.com/jimmycuadra/jquery-tmpl-rails
jquery jquery-templates rails ruby sprockets unmaintained
Last synced: about 2 months ago
JSON representation
jQuery Templates for the Rails asset pipeline.
- Host: GitHub
- URL: https://github.com/jimmycuadra/jquery-tmpl-rails
- Owner: jimmycuadra
- License: mit
- Created: 2011-08-10T07:24:01.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-01-20T06:46:34.000Z (almost 9 years ago)
- Last Synced: 2024-09-19T15:36:21.080Z (3 months ago)
- Topics: jquery, jquery-templates, rails, ruby, sprockets, unmaintained
- Language: Ruby
- Homepage: http://rubygems.org/gems/jquery-tmpl-rails
- Size: 164 KB
- Stars: 46
- Watchers: 3
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Code Climate](https://codeclimate.com/github/jimmycuadra/jquery-tmpl-rails.png)](https://codeclimate.com/github/jimmycuadra/jquery-tmpl-rails) [![endorse](http://api.coderwall.com/jimmycuadra/endorsecount.png)](http://coderwall.com/jimmycuadra)
# jquery-tmpl-rails
This gem adds the jQuery Templates plugin and a corresponding Sprockets engine to the asset pipeline in Rails >= 3.1 applications.
## Installation
Add it to your Gemfile and run `bundle`.
## Usage
jQuery templates will be recognized by Sprockets with the `.tmpl` extension. Place them anywhere in the Sprockets load path.
```html
```In your application's JavaScript manifest file, require the jQuery Templates plugin followed by your templates. The templates are compiled and named with their Sprockets logical path:
```javascript
//= require jquery-tmpl
//= require_tree ./templates$.tmpl("templates/author", { name: "Jimmy" }).appendTo("#author");
```## Configuration
If the path to all of your templates have a common prefix that you prefer is not included in the template's name, you can set this option in `config/application.rb`:
```ruby
config.jquery_templates.prefix = "templates"
```That would change the previous example to this:
```javascript
$.tmpl("author", { name: "Jimmy" }).appendTo("#author");
```The prefix can also be a regular expression. For example, to use only the name of the file for the template name, regardless of directory structure:
```ruby
config.jquery_templates.prefix = %r{([^/]*/)*}
```Happy templating!
## Acknowledgements
The Sprockets engine was originally derived from the [sprockets-jquery-tmpl](https://github.com/rdy/sprockets-jquery-tmpl) gem. If you want a similar mechanism for use outside of Rails, take a look at this project.