Module: PluggableJs::Helpers::View

Defined in:
lib/pluggable_js/helpers.rb

Instance Method Summary collapse

Instance Method Details

#javascript_pluggable_tagObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pluggable_js/helpers.rb', line 5

def javascript_pluggable_tag
  controller = params[:controller]
  action = define_pair_action

  ''.tap do |content|
    content << (javascript_tag "
      (function() {
        var function_name = '#{controller}##{action}';
        if (typeof(this[function_name]) == 'function') {
          $(function() {
            return window[function_name](#{@pluggable_js_data});
          });
        }
      }).call(this);"
    )

    if File.exist?(Rails.root + "app/assets/javascripts/pluggable/#{controller}/#{action}.js.coffee")
      content << (javascript_include_tag "pluggable/#{controller}/#{action}")
    end
  end.html_safe
end