0.0
No commit activity in last 3 years
No release in over 3 years
Use the power of Rails to namespace your JavaScript.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 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_NAME
    

somewhere

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 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.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.rb

    def 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 © 2009 [Brent Greeff], released under the MIT license