Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brentgreeff/js_namespace_framework
A Framework for namespacing your JavaScript
https://github.com/brentgreeff/js_namespace_framework
javascript rails
Last synced: about 1 month ago
JSON representation
A Framework for namespacing your JavaScript
- Host: GitHub
- URL: https://github.com/brentgreeff/js_namespace_framework
- Owner: brentgreeff
- License: mit
- Created: 2009-09-03T22:20:30.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2018-01-08T05:44:12.000Z (almost 7 years ago)
- Last Synced: 2024-10-01T15:53:04.373Z (about 2 months ago)
- Topics: javascript, rails
- Language: Ruby
- Homepage: http://www.brentgreeff.com/rails-plugins/js-namespace-framework
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= Js::Namespace::Framework
== Kinda deprecated - not sure anyone would use this anymore with the amazing collection of JS frameworks available.
The humble goal of this project was to namespace JS automatically on Rails projects based on the controller and action name.
If you are on Users#new
Instead of hunting for the JS that might be running on this page. You already know where to look:
SiteName.users.new_page();
It a convention over "hunting for selectors" pattern.
== Use the power of Rails to namespace your JavaScript.
== INSTALL
gem install js_namespace_framework
(or use bundler)* Define
SITE_NAMEsomewhere
probably:
config/initializers== Usage
* Add
<%= init_javascript if requires_javascript? %>
to the bottom of your layout.
When you need some JS Love on a page
Lets saycontroller: '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.messages.show_page();
* Then just define your namespace and method
SiteName = {}
SiteName.messages = {
show_page: function() {
SiteName.awesomeness.activate();
}
}* If you need some more progressive enhancement on messages.index
* In the messages_helper.rbdef requires_javascript?
return true if action_is? 'show', 'index'
end* In a Js file
SiteName = {}
SiteName.messages = {
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.Copyright (c) 2009 [Brent Greeff], released under the MIT license