Module: Foundationstone::ApplicationHelper

Defined in:
app/helpers/foundationstone/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#body_classObject



165
166
167
# File 'app/helpers/foundationstone/application_helper.rb', line 165

def body_class
  [controller_name,action_name].join(' ')
end

#body_idObject



161
162
163
# File 'app/helpers/foundationstone/application_helper.rb', line 161

def body_id
  controller_path.split('/').first
end

#bootstrap_flashObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/foundationstone/application_helper.rb', line 55

def bootstrap_flash
  flash_messages = []
  flash.each do |type, message|
    type = 'alert-success' if type == :notice
    type = 'alert-error alert-danger' if type == :alert
    text = (:div, link_to("x", "#", class: "close", data: {dismiss: 'alert'}) + message, class: "alert fade in #{type}")
    flash_messages << text if message
  end
  if flash_messages
     :div, id: 'alerts' do 
      flash_messages.join("\n").html_safe
    end
  end
end

#current_dateObject



51
52
53
# File 'app/helpers/foundationstone/application_helper.rb', line 51

def current_date
  Time.zone.now.to_datetime
end

#divisible_by(number) ⇒ Object



149
150
151
152
153
154
155
# File 'app/helpers/foundationstone/application_helper.rb', line 149

def divisible_by number
  divisible = []
  1.upto(number) do |i|
    divisible << "div-by-#{i}" if number.modulo(i).zero?
  end
  divisible
end

#divisible_class(number) ⇒ Object



157
158
159
# File 'app/helpers/foundationstone/application_helper.rb', line 157

def divisible_class number
  divisible_by(number+1).join(' ')
end

#extract(text, opt = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'app/helpers/foundationstone/application_helper.rb', line 39

def extract text, opt = {}
  if text
    result = strip_tags text
    result = result.truncate(opt[:truncate]) if opt[:truncate]
    result.html_safe
  end
end

#flags(resolution) ⇒ Object



70
71
72
73
74
75
76
# File 'app/helpers/foundationstone/application_helper.rb', line 70

def flags resolution
   :div, class: 'flags' do
    I18n.available_locales.each do |flag|
      concat link_to(image_tag("foundationstone/icons/flags/#{resolution}/#{flag}.png"), defined?(root_path) ? root_path(locale: flag.to_s) : main_app.root_path(locale: flag.to_s))
    end
  end
end

#font_awesome_text(icon_class, text) ⇒ Object Also known as: fat



32
33
34
35
36
# File 'app/helpers/foundationstone/application_helper.rb', line 32

def font_awesome_text icon_class, text
   :span, class: 'icon-text' do
    icon icon_class, text
  end
end

#glyphicon(css_class) ⇒ Object



9
10
11
# File 'app/helpers/foundationstone/application_helper.rb', line 9

def glyphicon css_class
  i "glyphicon glyphicon-#{css_class}"
end

#glyphicon_text(icon_class, text) ⇒ Object Also known as: gt



27
28
29
# File 'app/helpers/foundationstone/application_helper.rb', line 27

def glyphicon_text icon_class, text
  icon_text "glyphicon glyphicon-#{icon_class}", text
end

#google_analytics(id = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/foundationstone/application_helper.rb', line 122

def google_analytics id = nil
   :script, type: 'text/javascript' do
    "var _gaq = _gaq || [];
    _gaq.push(['_setAccount', '#{id}']);
    _gaq.push(['_trackPageview']);
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();".html_safe
  end unless id.blank?
end

#i(css_class) ⇒ Object



3
4
5
6
7
# File 'app/helpers/foundationstone/application_helper.rb', line 3

def i css_class
   :i, class: css_class do
    ''
  end
end

#icon_text(icon_class, text) ⇒ Object Also known as: it



20
21
22
23
24
# File 'app/helpers/foundationstone/application_helper.rb', line 20

def icon_text icon_class, text
   :span, class: 'icon-text' do
    i(icon_class) + text
  end
end

#localization_bar(object) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/foundationstone/application_helper.rb', line 86

def localization_bar object
   :ul, class: 'nav nav-tabs translations' do
    result = ''
    object.translations.each_with_index do |translation, i|
      result +=  :li, class: ('active' if i == 0) do
         :a, href: "#translation_#{i}", data: { toggle: 'tab' } do
          (!translation.to_s or translation.to_s.empty?) ? t('foundationstone.new_translation') : translation.to_s
        end
      end
    end
    result.html_safe
  end
end

#rails_admin_alert(object) ⇒ Object



113
114
115
116
117
118
119
120
# File 'app/helpers/foundationstone/application_helper.rb', line 113

def rails_admin_alert object
   :div, class: 'alert alert-info' do
    result = rails_admin_switch object
    result +=  :a, class: 'close', href: '#', data: { dismiss: 'alert' } do 
      'x'
    end
  end
end

#rails_admin_switch(object) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/foundationstone/application_helper.rb', line 100

def rails_admin_switch object
  model_name = object.class.model_name
  path = model_name.i18n_key.to_s.gsub('/', '~')

  action = 'new' if controller.action_name == 'new' or controller.action_name == 'create'
  action = 'edit' if controller.action_name == 'edit' or controller.action_name == 'update'
  if action == 'new'
    link_to t("foundationstone.rails_admin.#{action}", model: model_name.human), rails_admin.new_path(path)
  else
    link_to t("foundationstone.rails_admin.#{action}", model: model_name.human), rails_admin.edit_path(path, object.id)
  end
end

#span_icon(span_class, icon_class) ⇒ Object Also known as: si



13
14
15
16
17
# File 'app/helpers/foundationstone/application_helper.rb', line 13

def span_icon span_class, icon_class
   :span, class: span_class do
    i(icon_class)
  end
end

#translations(object, options = {}) ⇒ Object



78
79
80
81
82
83
84
# File 'app/helpers/foundationstone/application_helper.rb', line 78

def translations object, options = {}
   :div, class: 'translations' do
    object.translations.each do |translation|
      concat link_to(image_tag("foundationstone/icons/flags/#{options[:resolution]}/#{translation.locale}.png"), url_for(locale: translation.locale.to_s)) if translation.id?
    end
  end
end

#tree(engine_name, items, options = {}) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/helpers/foundationstone/application_helper.rb', line 135

def tree engine_name, items, options = {}
   :ul do
    items.map do |item|
      output = '<li>'
      klass = ( item.children.find{|i| current_page?(polymorphic_path([engine_name, i])) } ? 'active' : nil ) if item.has_children?
      klass = current_page?(polymorphic_path([engine_name, item])) ? 'current' : klass
      output << link_to(item.send(options.fetch(:title, 'title')), polymorphic_path([engine_name, item]), class: klass)
      output << tree(engine_name, item.children, options) if item.has_children?
      output << '</li>'
      output
    end.join.html_safe
  end
end

#true_false_icon(true_false) ⇒ Object



47
48
49
# File 'app/helpers/foundationstone/application_helper.rb', line 47

def true_false_icon true_false
  true_false ? i('glyphicon glyphicon-ok') : i('glyphicon glyphicon-minus')
end