= Js::Namespace::Framework

== 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

    <%= initialize_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 (c) 2009 [Brent Greeff], released under the MIT license