Js::Namespace::Framework
Use the power of Rails to namespace your JavaScript.
-
Add
<%= init_javascript if requires_javascript? %>
to the bottom of your layout.
When you need some JS Love on a page Lets say
:controller => 'messages', :action => 'show'
-
simply define the following method in the messages_helper.rb
def requires_javascript? return true if action_is? 'show' end
-
This will generate the following namespaced call.
SiteName.controller.action_page();
-
In this case
SiteName..show_page();
-
Then just define your namespace and method
SiteName = {} SiteName. = { show_page: function() { SiteName.awesomeness.activate(); } }
-
If you need some more progressive enhancement on messages.index
-
In the messages_helper.rb
def requires_javascript? return true if action_is? 'show', 'index' end
-
In a Js file
SiteName = {} SiteName. = { show_page: function() { SiteName.awesomeness.activate(); }, index_page: function() { SiteName.progressively.enhance(); } }
I would recommend creating one Js file per controller to keep things nice and neat and using Asset Packager to pack everything together for production.
INSTALL
braid add (this) -p
get braid if you do not have it.
-
Define
SITE_NAME
somewhere
Copyright © 2009 [Brent Greeff], released under the MIT license