Module: Fe::ApplicationHelper

Includes:
AnswerPagesHelper
Defined in:
app/helpers/fe/application_helper.rb

Instance Method Summary collapse

Methods included from AnswerPagesHelper

#li_page_active_if, #load_page_js

Instance Method Details

#calendar_date_select_tag(name, value = nil, options = {}) ⇒ Object



34
35
36
37
# File 'app/helpers/fe/application_helper.rb', line 34

def calendar_date_select_tag(name, value = nil, options = {})
  options.merge!({'data-calendar' => true})
  text_field_tag(name, value, options )
end

#flat_hash_key(names) ⇒ Object



25
26
27
28
29
30
31
32
# File 'app/helpers/fe/application_helper.rb', line 25

def flat_hash_key(names)
  names = Array.new(names)
  name = names.shift.to_s.dup
  names.each do |n|
    name << "[#{n}]"
  end
  name
end

#flatten_hash(hash = params, ancestor_names = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/fe/application_helper.rb', line 8

def flatten_hash(hash = params, ancestor_names = [])
  flat_hash = {}
  hash.each do |k, v|
    names = Array.new(ancestor_names)
    names << k
    if v.is_a?(Hash)
      flat_hash.merge!(flatten_hash(v, names))
    else
      key = flat_hash_key(names)
      key += "[]" if v.is_a?(Array)
      flat_hash[key] = v
    end
  end

  flat_hash
end


48
49
50
51
52
53
54
55
56
# File 'app/helpers/fe/application_helper.rb', line 48

def link_to_function(name, *args, &block)
   html_options = args.extract_options!.symbolize_keys

   function = block_given? ? update_page(&block) : args[0] || ''
   onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
   href = html_options[:href] || '#'

   (:a, name, html_options.merge(:href => href, :onclick => onclick))
end

#pretty_tag(txt) ⇒ Object



4
5
6
# File 'app/helpers/fe/application_helper.rb', line 4

def pretty_tag(txt)
  txt.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase
end

#spinner(extra = nil) ⇒ Object



43
44
45
46
# File 'app/helpers/fe/application_helper.rb', line 43

def spinner(extra = nil)
  e = extra ? "spinner_#{extra}" : 'spinner'
  image_tag('spinner.gif', :id => e, :style => 'display:none', :class => 'spinner')
end

#tip(t) ⇒ Object



39
40
41
# File 'app/helpers/fe/application_helper.rb', line 39

def tip(t)
  image_tag('fe/icons/question-balloon.png', :title => t, :class => 'tip')
end