Module: ApplicationHelper

Defined in:
lib/html_helpers/form_object.rb,
lib/html_helpers/icons_helper.rb,
lib/html_helpers/inside_layout.rb

Constant Summary collapse

DefaultIconCategory =
"default"

Instance Method Summary collapse

Instance Method Details

#icon_path(category, icon, root = '') ⇒ Object



14
15
16
# File 'lib/html_helpers/icons_helper.rb', line 14

def icon_path(category, icon, root = '')
  File.join('', root, 'images', category.to_s, icon.to_s + '.png')
end

#icon_src(category, icon, root = '') ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/html_helpers/icons_helper.rb', line 18

def icon_src(category, icon, root = '')
  paths = []
  paths << icon_path(category, icon)
  paths << icon_path(category, icon, root)
  paths << icon_path(DefaultIconCategory, icon, root)
  paths << icon_path(DefaultIconCategory, icon)
  
  paths.each { |p| $stderr.puts ("Icon Path: " + File.join(RAILS_ROOT, 'public', p)) }
  return paths.find { |p| File.exist?(File.join(RAILS_ROOT, 'public', p)) }
end

#icon_tag(icon, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/html_helpers/icons_helper.rb', line 29

def icon_tag(icon, options = {})
  category = options.delete(:controller) || options.delete(:category) || controller.controller_name
  root = options.delete('root') || ''
  
  if defined? Engines.plugins
    plugin = options.delete(:plugin) || IconHelper::current_plugin(caller)
    root = File.join("plugin_assets", plugin.name) unless plugin.nil?
  end
  
  css_class = options.delete(:class) || 'icon'
  
  src = icon_src(category, icon, root)
  
  if src
    return tag('img', {'class' => css_class, 'src' => src})
  else
    return options[:unavailable]
  end
end

#inside_layout(layout, &block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/html_helpers/inside_layout.rb', line 3

def inside_layout(layout, &block)
  @template.instance_variable_set("@content_for_layout", capture(&block))
  
  layout = layout.include?("/") ? layout : "layouts/#{layout}" if layout
  buffer = eval("_erbout", block.binding)
  buffer.concat(@template.render_file(layout, true))
end

#submit_button(value = "Save changes", url_for_options = {}, options = {}, *parameters_for_url) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/html_helpers/form_object.rb', line 2

def submit_button(value = "Save changes", url_for_options = {}, options = {}, *parameters_for_url)
  options.stringify_keys!
  
  options["action"]  = url_for(url_for_options, *parameters_for_url) if url_for_options.size != 0
  
  if disable_with = options.delete("disable_with")
    options["onclick"] = "this.disabled=true;this.value='#{disable_with}';this.form.submit();#{options["onclick"]}"
  end
  
  if action = options.delete("action")
    options["onclick"] = "this.form.action='#{escape_javascript(action)}';#{options['onclick']}"
  end
  
  if method = options.delete("method")
    options["onclick"] = "this.form.method='#{escape_javascript(method)}';#{options['onclick']}"
  end
  
  if confirm = options.delete("confirm")
    options["onclick"] = "if (!#{confirm_javascript_function(confirm)}){return false};#{options['onclick']}"
  end
    
  tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
end