Module: PluggableJs::Helpers::View

Defined in:
lib/pluggable_js/helpers.rb

Instance Method Summary collapse

Instance Method Details

#javascript_pluggable_tagObject

call function and pass data, include file if it exists



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

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

  ''.tap do |content|
    content << (javascript_tag "
      (function() {
        pjs_data = {}; #{@data_string}
        jQuery(function() {
          if (typeof(window['#{controller}##{action}']) == 'function') {
            return window['#{controller}##{action}'](pjs_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