Module: Symbolink::SymbolinkHelpers

Defined in:
lib/symbolink/helper.rb

Instance Method Summary collapse

Instance Method Details

#symbol(sym) ⇒ Object



8
9
10
# File 'lib/symbolink/helper.rb', line 8

def symbol(sym)
  symbolicon(sym)
end

#symbolicon(sym) ⇒ Object



3
4
5
# File 'lib/symbolink/helper.rb', line 3

def symbolicon(sym)
  Symbolink.configuration.symbols[sym]
end


35
36
37
38
# File 'lib/symbolink/helper.rb', line 35

def symbolink_destroy(options = {}, html_options = {})
  html_options[:method] = :delete
  symbolink_to(:delete, options, html_options)
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/symbolink/helper.rb', line 12

def symbolink_to(sym, options = {}, html_options = {})
  action = Symbolink.configuration.actions[sym]
  if action
    icon = action[:icon]
    title = action[:title]
    confirm = action[:confirm]
  else
    icon = sym
    title = sym.to_s.humanize
    confirm = nil
  end
  html_options[:title] ||= title
  if confirm
    html_options[:data] ||= {}
    %w{confirm data-confirm}.map(&:to_sym).select{ |opt| html_options[opt] }.each do |opt|
      html_options[:data][:confirm] = html_options[opt]
      html_options.delete(opt)
    end
    html_options[:data][:confirm] ||= confirm
  end
  link_to(symbolicon(icon), options, html_options)
end