Module ApplicationHelper
In: app/helpers/application_helper.rb

Methods added to this helper will be available to all templates in the application.

Methods

Included Modules

TagsHelper WhiteListHelper

Public Instance methods

Turns all urls into clickable links. If a block is given, each url is yielded and the result is used as the link text. This is actually auto_link_urls of Rails modified to include html_options in already linked URLs

[Source]

     # File app/helpers/application_helper.rb, line 224
224:   def auto_link_urls_with_options(text, html_options = {})
225:     extra_options = tag_options(html_options.stringify_keys) || ""
226:     text.gsub(ActionView::Helpers::TextHelper::AUTO_LINK_RE) do
227:       all, a, b, c, d = $&, $1, $2, $3, $4
228:       if a =~ /<a\s/i # don't replace URL's that are already linked
229:         all
230:       else
231:         text = b + c
232:         text = yield(text) if block_given?
233:         %(#{a}<a href="#{b=="www."?"http://www.":b}#{c}"#{extra_options}>#{text}</a>#{d})
234:       end
235:     end
236:   end

[Source]

    # File app/helpers/application_helper.rb, line 27
27:   def body_class
28:     txt = @body_class || ""
29: 
30:     unless txt.eql?('home')
31:       if @content_for_left_menu.present?
32:         txt += " left_menu"
33:       end
34:       if @content_for_right_menu.present?
35:         txt += " right_menu"
36:       end
37:     end
38:     txt
39:   end

[Source]

    # File app/helpers/application_helper.rb, line 49
49:   def carousel_widget(dom_id, options={}, &block)
50:     visible_slides = options[:visible_slides] || 4
51:     wrapper_content = content_tag(:div, content_tag(:div, capture(&block), 
52:                                                        :class => "carousel-content #{options[:content_class]}"), 
53:                                      :class => "carousel-wrapper #{options[:wrapper_class]}", 
54:                                      :id => "#{dom_id}_wrapper") 
55:     if options[:second_wrapper] 
56:       wrapper_html = content_tag(:div, wrapper_content, :class => "carousel-wrapper-block")
57:     else
58:       wrapper_html = content_tag(:div, wrapper_content, :class => "wrapper-block-maxwidth")
59:     end
60:     concat(content_tag(:div, content_tag(:div, link_to("<span>&laquo;</span>", "javascript:", 
61:                                                 :class => "carousel-control prev", 
62:                                                 :rel => "prev"), 
63:                                   :class => 'carousel_prev')+
64:                               content_tag(:div, link_to("<span>&raquo;</span>", "javascript:", 
65:                                                    :class => "carousel-control next", 
66:                                                    :rel => "next"), 
67:                                               :class => 'carousel_next')+
68:                               wrapper_html,
69:                              :class => "carousel", :id => dom_id)+
70:                              javascript_tag("new Carousel('#{dom_id}_wrapper', $$('##{dom_id} .carousel-content .slide'), $$('##{dom_id} a.carousel-control'), {duration: 0.5,
71:                                       transition: 'fade',
72:                                       visibleSlides: #{visible_slides},
73:                                       circular: false
74:                                       });"))
75:   end

[Source]

     # File app/helpers/application_helper.rb, line 249
249:   def connected_from_lan?
250:     request.remote_ip.match(/10\.(\d+\.){2}\d+/)
251:   end

[Source]

     # File app/helpers/application_helper.rb, line 215
215:   def convert_relative_urls_to_absolute(text)
216:     e = "#{request.protocol}#{request.host_with_port}"
217:     text.sub(/href=([\"\'])\//, "href=\\1#{e}/")
218:   end

[Source]

     # File app/helpers/application_helper.rb, line 253
253:   def double_quote_quote(text)
254:     text.gsub("'", "\"")
255:   end

[Source]

     # File app/helpers/application_helper.rb, line 207
207:   def enet_contact_form_lang_code(lang)
208:     Document::LANGUAGES.index(lang) + 1
209:   end

[Source]

     # File app/helpers/application_helper.rb, line 211
211:   def file_name_for_path(path)
212:     Pathname.new(path).basename
213:   end

Example: <% for_every_locale do |code, lang| %>

  <%= content_tag(:li, link_to("Nuevo documento en #{lang}", self.send("new_admin_document_path", {:lang => code}))) %>

<% end %>

[Source]

    # File app/helpers/application_helper.rb, line 21
21:   def for_every_locale(*args, &block)
22:     locales.each_pair do |code, lang|
23:       yield(*args + [code, lang])
24:     end    
25:   end

[Source]

     # File app/helpers/application_helper.rb, line 161
161:   def ga_custom_vars
162:     cvars = []
163:     if subsite.eql?('agencia')
164:       cvars.push "_gaq.push(['_setCustomVar',1,'Acceso','Periodistas',3]);"
165:     else
166:       cvars.push "_gaq.push(['_setCustomVar',1,'Acceso','Ciudadanos',3]);"
167:     end
168:     
169:     current_section = ga_get_current_section()
170:     cvars.push "_gaq.push(['_setCustomVar',2,'Seccion','#{current_section.tildes.gsub(/\s+/, '_')}', 3]);" if current_section        
171:     
172:     cvars.join("\n")
173:   end

Google Analytics‘s specific functions

[Source]

     # File app/helpers/application_helper.rb, line 124
124:   def ga_get_current_section
125:     sname = nil
126:     
127:     if subsite.eql?('agencia')
128:       case controller.controller_name
129:       when 'news'
130:         if @news && @news.is_a?(News) && @news.title.eql?('Titulares de Comunicación del Gobierno Vasco')
131:           sname = 'Jefes de prensa'
132:         else
133:           sname = 'Hemeroteca' unless params[:action].eql?('home')
134:         end
135:       end
136:     else
137:       case controller.controller_name
138:       when 'events'
139:         sname ='Agenda'
140:       when 'videos', 'news', 'gallery', 'albums'
141:         sname = 'Multimedia'
142:       when 'site'
143:         sname = 'Redes y blogs' if params[:action].eql?('snetworking')
144:       when 'proposals'
145:         sname = 'Propuestas ciudadanas'
146:       when 'articles'
147:         sname = 'Escucha activa'
148:       when 'categories'
149:         if @category && (@category.name_es.match('Multimedia') || @category.name_es.match('Hemeroteca'))
150:           sname = 'Multimedia'
151:         end
152:       when 'pages'
153:         if @flash_page
154:           sname = "Qué es irekia"
155:         end
156:       end
157:     end
158:     sname
159:   end

moved to partial /shared/_tags.html.erb def tags_widget(item, html_options={})

  txt = ""
  if item.tags.public.count > 0
    txt = content_tag(:div, content_tag(:span, "#{t('documents.tags')}: ", :class => "tags_label")+
                            content_tag(:span, item.tags.public.collect { |tag| link_to(tag.name, tag_path(tag))}.join(', ')),
                            html_options.merge(:class => "tags"))
  end
  txt

end

[Source]

     # File app/helpers/application_helper.rb, line 110
110:   def go2comment_link
111:     link_to(content_tag(:span, t('documents.Comentar').downcase), "#comments", :class => 'go2comment')
112:   end

[Source]

     # File app/helpers/application_helper.rb, line 198
198:   def header_links
199:     {"es" => {:accesibilidad => "http://www.euskadi.net/r33-2288/es/contenidos/informacion/cabecera_accesibilidad/es_6144/politica_accesibilidad.html",
200:               :gestiones => "https://www6.euskadi.net/s06-9512x/eu/r02nConsultationSistemWar/consultation/r02nExpedientList.do"},
201:      "eu" => {:accesibilidad => "http://www.euskadi.net/r33-2288/eu/contenidos/informacion/cabecera_accesibilidad/eu_6144/erabilerraztasuna.html",
202:               :gestiones => "https://www6.euskadi.net/s06-9512x/es/r02nConsultationSistemWar/consultation/r02nExpedientList.do"},
203:      "en" => {:accesibilidad => "http://www.basques.euskadi.net/t32-2286/en/contenidos/informacion/cabecera_accesibilidad/", 
204:              :gestiones => "http://www.basques.euskadi.net/t32-2286/en/contenidos/informacion/cabecera_identificarse/"}}    
205:   end

[Source]

    # File app/helpers/application_helper.rb, line 77
77:   def image_tip(options={})
78:     content_tag(:div, content_tag(:div, '&nbsp;', :class => 'balloon-top') +
79:                       content_tag(:div, (options[:date] ? content_tag(:span, I18n.localize(options[:date], :format => :long), :class => 'date') : "") +
80:                                         content_tag(:span, h(options[:title])), 
81:                                         :class => 'balloon-bottom'), 
82:                       :class => "image_tip")
83:   end

[Source]

    # File app/helpers/application_helper.rb, line 85
85:   def init_tooltip
86:     content_for :head do
87:       stylesheet_link_tag('new/tooltip')+
88:       javascript_include_tag('tooltip')+
89:       javascript_tag("Event.observe(window, 'load', function(evt){var ttip = new ToolTip('a.link_with_tip')});")
90:     end
91:   end

[Source]

     # File app/helpers/application_helper.rb, line 238
238:   def ipad_user_agent?
239:     # Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) 
240:     # Version/4.0.4 Mobile/7B314 Safari/531.21.10
241:     request.env["HTTP_USER_AGENT"] && !request.env["HTTP_USER_AGENT"].match(/(iPad)/i).nil?
242:   end

Request from an iPhone or iPod touch? (Mobile Safari user agent)

[Source]

     # File app/helpers/application_helper.rb, line 185
185:   def iphone_user_agent?
186:     request.env["HTTP_USER_AGENT"] && !request.env["HTTP_USER_AGENT"].match(/iPhone/).nil?
187:   end

[Source]

    # File app/helpers/application_helper.rb, line 41
41:   def irekia_subsite
42:     @irekia_subsite ||= ['polls', 'articles', 'proposals'].include?(controller.controller_name) ? "participation" : "transparency"
43:   end

[Source]

     # File app/helpers/application_helper.rb, line 114
114:   def link_to_comments(object)
115:     link_to(content_tag(:span, t('documents.Comentar').downcase), self.send("#{object.class.to_s.downcase}_path", object, :anchor => "comments"), :class => 'comment')
116:   end

Example: <%= link_to_in_every_locale "Nuevo documento", "new_admin_document_path", :content_tag => :li %>

[Source]

    # File app/helpers/application_helper.rb, line 8
 8:   def link_to_in_every_locale(text, link, options = {})
 9:     options.reverse_merge(:content_tag => :li)
10:     output = ""
11:     locales.each_pair do |code, lang|
12:       output << content_tag(options[:content_tag], link_to("#{text} en #{lang}", self.send(link, {:lang => code})))
13:     end
14:     return output
15:   end

[Source]

    # File app/helpers/application_helper.rb, line 45
45:   def menu_link_class(tab)
46:     @current_tab.eql?(tab) ? "active" : "passive"
47:   end

[Source]

     # File app/helpers/application_helper.rb, line 244
244:   def mobile_user_agent?
245:     ipad_user_agent? || iphone_user_agent? || floki_user_agent?
246:   end

[Source]

    # File app/helpers/application_helper.rb, line 93
93:   def more_info_widget(link)
94:     content_tag(:div, content_tag(:span, t('site.mas_informacion'), :class => "tags_label")+
95:                       content_tag(:span, link, :class => "tag_links"), 
96:                       :class => "more_info")
97:   end

[Source]

     # File app/helpers/application_helper.rb, line 194
194:   def multimedia_content_dir_format
195:     'Sólo letras sin tildes, números y "_". "/" para indicar directorios.'
196:   end

[Source]

     # File app/helpers/application_helper.rb, line 118
118:   def see_all_link(title, url)
119:     "<div class='see_all_link'><a href=\"#{url}\"><span class=\"icon todos\"></span>#{title}</a></div>"
120:   end

Returns true if a fetured video o streaming is defined.

[Source]

     # File app/helpers/application_helper.rb, line 190
190:   def video_or_streaming?
191:     @featured_video.present? || @streaming.present? || @announced_streaming.present?
192:   end

[Validate]