https://github.com/atomicobject/jquery_expand_assets
A Sprockets processor and Rails engine for jquery.expand assets.
https://github.com/atomicobject/jquery_expand_assets
Last synced: 10 months ago
JSON representation
A Sprockets processor and Rails engine for jquery.expand assets.
- Host: GitHub
- URL: https://github.com/atomicobject/jquery_expand_assets
- Owner: atomicobject
- License: mit
- Created: 2012-08-24T16:14:03.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2013-04-17T19:45:46.000Z (about 13 years ago)
- Last Synced: 2025-06-08T22:08:04.584Z (11 months ago)
- Language: Ruby
- Homepage:
- Size: 125 KB
- Stars: 0
- Watchers: 25
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery.expand assets [](http://travis-ci.org/atomicobject/jquery_expand_assets) [](https://codeclimate.com/github/atomicobject/jquery_expand_assets)
A Sprockets processor that wraps html in a jquery.expand function. It is specifically meant to work within the Rails asset pipeline.
The processor outputs CoffeeScript, so you'll need to have the result be processed by the CoffeeScript processor.
## Requirements
This gem is syntax compatible with Ruby 1.9. It does not run on older Rubies.
## Creating and using templates
Create your templates in a directory named `app/assets/javascripts/templates`. Organize your templates within subdirectories. I personally organize them based on what resource they're associated with.
Write your template and wrap it in a root element.
Example: `app/assets/javascripts/templates/articles/_entry.js.coffee.expand`
Your template is now available to Javascript as a function on the `JST` object. Pass an expand directive to the function and you'll be given the result minus the wrapper element.
Example: see `articles/_entry.js.coffee.expand` above
directive = { name: 'Joe', content: 'I love Smurfs.' }
html = JST['articles/entry'](directive)
$('body').append(html)
In this example, the result html will be:
Joe
I love Smurfs.
## Naming conventions
Templates are named on the `JST` object based on their filename. Directories under `app/assets/javascripts/templates` are preserved. If the template's filename starts with an underscore, then the underscore is removed from the name.
Examples:
`articles/_entry.js.coffee.expand` becomes `articles/entry`
`articles/comments/_comment.js.coffee.expand` becomes `articles/comments/comment`
`articles/response.js.coffee.expand` becomes `articles/response`
## Resources
* [jquery.expand](https://github.com/atomicobject/jquery.expand)
* [jquery.expand examples](http://spin.atomicobject.com/2011/07/10/jquery-expand-examples/)
## Development
This project depends on bundler for installing and using development gems. You'll need to `bundle install` and `bundle exec rake` to run the tests.
## Thanks so much!
I'd like to give a huge 'thank you' to the [Sprockets](https://github.com/sstephenson/sprockets), [haml_assets](https://github.com/infbio/haml_assets), and [haml_coffee_assets](https://github.com/netzpirat/haml_coffee_assets) projects. Without their examples, I'm not sure I would have figured out the code required to create the Rails engine and Tilt template.
Authors
=======
* Matt Fletcher (fletcher@atomicobject.com)
* © 2013 [Atomic Object](http://www.atomicobject.com/)
* More Atomic Object [open source](http://www.atomicobject.com/pages/Software+Commons) projects