Skip to content

maciejka/serenade.rb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serenade.js for Ruby

Serenade.js is a JavaScript client side MVC framework. This gem makes Serenade.js available for usage with Sprockets, or the asset pipeline in Ruby on Rails version 3.1 or later.

Installation

To use Serenade with Rails, add Serenade to the assets group in your Gemfile:

group :assets do
  gem "serenade", :require => "serenade/rails"
end

You can now require Serenade in your app/assets/javascripts/application.js file:

//= require serenade

Serenade should now be loaded and ready. See the Serenade README for examples.

Using Serenade with Sprockets

If you are not using Rails, you can still use Serenade with just Sprockets:

gem "serenade", :require => "serenade/sprockets"

You’ll also need to register the Serenade asset path with your Sprockets environment.

sprockets.append_path Serenade::ASSET_PATH

Serenade.js views and the asset pipeline

Serenade.js allows Sprockets or the Rails asset pipeline to compile your Serenade views for you, just use the extension .serenade on any asset file. Your views will be precompiled server-side before being served to the client.

For example, if you create the following view in app/assets/javascripts/test.serenade:

h1 "Hello " @name

Now you can render this view:

var model = new Serenade.Model({ name: "Vega" })
document.body.appendChild(Serenade.render('test', model));

And, like in all Serenade.js views, you can change your model and see the DOM update itself accordingly:

model.name = "Mercedes" // HTML now says <h1>Hello Mercedes</h1>

A note about the view path

If the path to your view starts with views, that initial part is stripped off, so you could have placed the above view in app/assets/javascripts/views/test.serenade without changing the code.

License

(The MIT License)

Copyright (c) 2012 Jonas Nicklas, Kim Burgestrand

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Serenade.js for Ruby, Rails, and Sprockets

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 93.4%
  • Ruby 6.6%