Module: JellyHelper

Defined in:
lib/jelly/jelly_helper.rb

Instance Method Summary collapse

Instance Method Details

#application_jelly_files(jelly_files_path_from_javascripts = '', rails_root = RAILS_ROOT) ⇒ Object



3
4
5
6
7
# File 'lib/jelly/jelly_helper.rb', line 3

def application_jelly_files(jelly_files_path_from_javascripts = '', rails_root = RAILS_ROOT)
  Dir["#{rails_root}/public/javascripts/#{jelly_files_path_from_javascripts}/pages/**/*.js"].map do |path|
    path.gsub("#{rails_root}/public/javascripts/", "").gsub(/\.js$/, "")
  end
end

#attach_javascript_component(component_name, *args) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/jelly/jelly_helper.rb', line 24

def attach_javascript_component(component_name, *args)
  @jelly_attached_components ||= []    
  key = "page.attach(#{component_name}, #{args.to_json});"
  unless @jelly_attached_components.include? key
    @jelly_attached_components << key
    content_for(:javascript, key)
  end
end

#attach_javascript_component_on_ready(component_name, *args) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/jelly/jelly_helper.rb', line 33

def attach_javascript_component_on_ready(component_name, *args)
  @jelly_attached_components_on_ready ||= []
  key = "page.attach(#{component_name}, #{args.to_json});"
  unless @jelly_attached_components_on_ready.include? key
    @jelly_attached_components_on_ready << key
    content_for(:javascript_on_ready, key)
  end
end

#clear_jelly_attachedObject



20
21
22
# File 'lib/jelly/jelly_helper.rb', line 20

def clear_jelly_attached()
  @jelly_attached_components = []
end

#spread_jellyObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/jelly/jelly_helper.rb', line 9

def spread_jelly
  javascript_tag <<-JS
    window._token = '#{form_authenticity_token}'
    Jelly.activatePage('#{controller.controller_path.camelcase}', '#{controller.action_name}');
    #{@content_for_javascript}
    $(document).ready(function() {
      #{@content_for_javascript_on_ready}
    });
  JS
end