https://github.com/seekingalpha/jst
Simple Javascript templates for Rails projects without Sprockets
https://github.com/seekingalpha/jst
Last synced: about 1 year ago
JSON representation
Simple Javascript templates for Rails projects without Sprockets
- Host: GitHub
- URL: https://github.com/seekingalpha/jst
- Owner: seekingalpha
- License: mit
- Created: 2014-04-23T14:25:23.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-06-18T11:34:26.000Z (almost 12 years ago)
- Last Synced: 2024-04-19T11:07:43.632Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 220 KB
- Stars: 3
- Watchers: 8
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://codeclimate.com/repos/5358f2f0e30ba06766001f0b/feed)
[](https://travis-ci.org/seekingalpha/jst)
# JST
JST is a simple javascript templating system inspired by Sprockets' homonimous templating system, but built for rails projects without Sprockets.
JST works on top of [PrototypeJS's template system](http://prototypejs.org/doc/latest/language/Template/) and [HandleBars](http://handlebarsjs.com/).
## Install
Add this line to your application's Gemfile:
gem 'jst', github: 'seekingalpha/jst'
And then execute:
$ bundle
## Usage
Create a folder in your project and add PrototypeJS templates with the ".jst.pt" extension or Handlebars with the ".jst.hb". Let's suppose you have a "hi.jst.pt" file in "app/assets/javascripts/templates":
```html
Hi, #{name}
```
In order to compile your templates, run:
```ruby
JST::Aggregator.new('app/assets/javascripts/templates').save('public/javascripts/templates.js')
```
If you don't wanna pass the paths every time, you can configure it first (rule of thumb: add it to config/initializers/jst.rb):
```ruby
JST.configure do |config|
config.templates_path = 'app/assets/javascripts/templates'
config.output = 'public/javascripts/templates.js'
end
```
Then you can just run:
```ruby
JST.process!
```
Now, load templates.js in your view and then you can use the templates like this in your JS files:
```js
Templates.hi({name: 'Emmanuel'})
```
This will output ```
Hi, Emmanuel
```, as expected. Notice the method "hi" is created automatically based on the name of the template file.
Enjoy!
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Roadmap
- Use guard to watch template folder and compile automatically when changed.
- ~~Allow handlebars templates.~~