Module: CoffeeGrounds::CoffeeGroundsHelper

Defined in:
lib/coffee-grounds/helpers/coffee-grounds_helper.rb

Instance Method Summary collapse

Instance Method Details

#coffee_grounds_script_tag(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/coffee-grounds/helpers/coffee-grounds_helper.rb', line 3

def coffee_grounds_script_tag( options = {} )
  js_namespace = ( options[:namespace] ) ? options[:namespace] : "App"
  <<-JS
  <script type="text/javascript">//<![CDATA[
    (function() {
      $(document).ready(function() {
        var _ref, _ref1, _ref2;
        if ((_ref = #{js_namespace}['#{params[:controller].parameterize}']) != null) {
          if (typeof _ref.init === "function") {
            _ref.init();
          }
        }
        if ((_ref1 = #{js_namespace}['#{params[:controller].parameterize}']) != null) {
          if ((_ref2 = _ref1['#{params[:action].parameterize}']) != null) {
            if (typeof _ref2.init === "function") {
              _ref2.init();
            }
          }
        }
        return true;
      });

    }).call(this);
  //]]></script>
  JS
end