module ApplicationHelper

OpenIrekia v4.0.0

Copyright 2009-2013 eFaber, S.L. Copyright 2009-2013 Ejie, S.A. Copyrigth 2009-2013 Dirección de Gobierno Abierto y Comunicación en Internet;

Gobernu Irekirako eta Interneteko Komunikaziorako Zuzendaritza; Lehendakaritza.
Gobierno Vasco – Eusko Jaurlaritza

Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto sean aprobadas por la Comisión Europea– versiones posteriores de la EUPL (la Licencia); Solo podrá usarse esta obra si se respeta la Licencia. Puede obtenerse una copia de la Licencia en: ec.europa.eu/idabc/eupl Salvo cuando lo exija la legislación aplicable o se acuerde por escrito, el programa distribuido con arreglo a la Licencia se distribuye TAL CUAL, SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas. Véase la Licencia en el idioma concreto que rige los permisos y limitaciones que establece la Licencia

http://open.irekia.net, openirekia@efaber.net

Public Instance Methods

avatar(item, opts = {}) click to toggle source
# File app/helpers/application_helper.rb, line 224
def avatar(item, opts = {})
  size = opts[:size] || :thumb_70

  # if item.respond_to?(:avatar) && item.avatar.present? && !item.avatar.url.eql?("/images/icons/faceless_avatar.png")
  #   avatar_image = image_tag(item.avatar.url(size)) + content_tag(:div, " ", :class => :ieframe)      
  # else
  #   avatar_image = image_tag "icons/faceless#{ "_#{size}" unless size.blank? }_avatar.png", :class => "avatar #{size}", :title => t('unknown_user')      
  # end
  
  if item.respond_to?(:photo)
    avatar_image = image_tag(item.photo.url(size)) + content_tag(:div, " ", :class => :ieframe)
  else
    avatar_image = image_tag("default/faceless_avatar_#{ size unless size.blank? }.png", :class => "avatar #{size}", :title => t('unknown_user'))
  end
  
  avatar_html = case 
                when item.is_a?(Politician)
                  politician_avatar = if item.approved_or_ex?
                    avatar_image
                  else
                    image_tag("default/faceless_avatar_#{ size unless size.blank? }.png", :class => "avatar #{size}", :title => t('unknown_user'))
                  end
                  link_to(politician_avatar, politician_url(item), :class => "avatar #{size}")
                when item.class.superclass.to_s.eql?('User') && !item.new_record?
                  avatar_url = (item == current_user) ? account_path : user_url(item)
                  link_to(avatar_image, avatar_url, :class => "avatar #{size}")
                else
                  link_to(avatar_image, '#', :class => "avatar #{size}")
                end
  
  avatar_html
end
block_to_partial(partial_name, options={}, &block) click to toggle source
# File app/helpers/application_helper.rb, line 66
def block_to_partial(partial_name, options={}, &block)
  options.merge!(:block => block.present? ? capture(&block) : '') 
  concat(render(:partial => partial_name, :locals => options))
end
body_class() click to toggle source

Not used

# File app/helpers/application_helper.rb, line 58
def body_class
  @body_class || ""
end
class_for_modal_login() click to toggle source
# File app/helpers/application_helper.rb, line 257
def class_for_modal_login
  logged_in? ? '' : 'login-required'
end
connected_from_lan?() click to toggle source
# File app/helpers/application_helper.rb, line 169
def connected_from_lan?
  request.remote_ip.match(/10\.(\d+\.){2}\d+/)
end
context_partial(context, prefix) click to toggle source
# File app/helpers/application_helper.rb, line 280
def context_partial(context, prefix)
  "#{prefix}#{context.present? ? "_#{context.class.to_s.downcase}" : ''}"
end
controller_for(document) click to toggle source
# File app/helpers/application_helper.rb, line 177
def controller_for(document)
  document.class.to_s.downcase.pluralize
end
date_in_distance(date) click to toggle source
# File app/helpers/application_helper.rb, line 291
def date_in_distance(date)
  if date && date < 7.days.ago
    I18n.l(date.to_date, :format => :long)
  elsif date
    I18n.t('shared.hace_time', :time => distance_of_time_in_words_to_now(date))
  else 
    ''
  end
end
double_quote_quote(text) click to toggle source
# File app/helpers/application_helper.rb, line 173
def double_quote_quote(text)
  text.gsub("'", "\"")
end
enet_contact_form_lang_code(lang) click to toggle source
# File app/helpers/application_helper.rb, line 141
def enet_contact_form_lang_code(lang)
  Document::LANGUAGES.index(lang) + 1
end
for_every_locale(*args) { |*args + [code, lang]| ... } click to toggle source

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 %>

# File app/helpers/application_helper.rb, line 40
def for_every_locale(*args, &block)
  locales.each_pair do |code, lang|
    yield(*args + [code, lang])
  end    
end
ga_custom_vars() click to toggle source
# File app/helpers/application_helper.rb, line 107
def ga_custom_vars
  cvars = []
  cvars.push "_gaq.push(['_setCustomVar',1,'Acceso','Ciudadanos',3]);"
  
  current_section = ga_get_current_section()
  cvars.push "_gaq.push(['_setCustomVar',2,'Seccion','#{current_section.tildes.gsub(/\s+/, '_')}', 3]);" if current_section        
  
  cvars.join("\n")
end
ga_get_current_section() click to toggle source

Google Analytics’s specific functions

# File app/helpers/application_helper.rb, line 83
def ga_get_current_section
  sname = nil
  
  case controller.controller_name
  when 'events'
    sname ='Agenda'
  when 'videos', 'news', 'albums'
    sname = 'Multimedia'
  when 'site'
    sname = 'Redes y blogs' if params[:controller].eql?('snetwork')
  when 'proposals'
    sname = 'Propuestas ciudadanas'
  when 'categories'
    if @category && (@category.name_es.match('Multimedia') || @category.name_es.match('Hemeroteca'))
      sname = 'Multimedia'
    end
  when 'pages'
    if @flash_page
      sname = "Qué es irekia"
    end
  end
  sname
end
handheld_check() click to toggle source
# File app/helpers/application_helper.rb, line 309
def handheld_check
  {'iphone' => 'iPhone', 'android' => 'Android'}.each do |handheld_type, pretty_type|
    if self.send("#{handheld_type}_user_agent?")
      content_for :handheld_warning do
        content_tag(:p, t('site.usas_device', :device => pretty_type, :link => link_to(t('site.version_optimizada'), self.send("#{handheld_type}_path"))), :class => "mobile_warning")
      end
    end
  end
end
homepage?() click to toggle source
# File app/helpers/application_helper.rb, line 62
def homepage?
  controller_name.eql?('site') && action_name.eql?('show')
end
image_tip(options={}) click to toggle source
# File app/helpers/application_helper.rb, line 75
def image_tip(options={})
  content_tag(:div, '&nbsp;', :class => 'balloon-top') +
                    content_tag(:div, (options[:date] ? content_tag(:span, I18n.localize(options[:date], :format => :long), :class => 'date') : "") +
                                      content_tag(:span, h(options[:title])), 
                                      :class => 'balloon-bottom')
end
init_bootstrap_select() click to toggle source
# File app/helpers/application_helper.rb, line 203
def init_bootstrap_select
  content_for :css_data do
    stylesheet_link_tag('lib/bootstrap-select.min')
  end
  content_for :js_data do
    javascript_include_tag('lib/bootstrap-select.min')
  end
end
init_jquery_lightbox() click to toggle source
# File app/helpers/application_helper.rb, line 187
def init_jquery_lightbox
  content_for :js_data do
    stylesheet_link_tag('lib/jquery.lightbox.css') +
    javascript_include_tag('lib/jquery.lightbox.custom.min.js')
  end
end
init_jquery_tools_scrollable() click to toggle source
# File app/helpers/application_helper.rb, line 181
def init_jquery_tools_scrollable
  content_for :js_data do
    javascript_include_tag("lib/jquery.tools.scrollable.min")
  end 
end
init_jquery_videosub() click to toggle source
# File app/helpers/application_helper.rb, line 212
def init_jquery_videosub
  content_for :js_data  do
    javascript_include_tag('lib/jquery.videosub.min') +
    javascript_tag do
      "$(document).ready(function(){
        Irekia.hostWithPort = 'http://#{request.host_with_port}';
        $('video').videoSub();
      });"
    end
  end
end
init_photo_video_viewer(lightbox=:false) click to toggle source
# File app/helpers/application_helper.rb, line 194
def init_photo_video_viewer(lightbox=:false)
  content_for :css_data do
    stylesheet_link_tag("public/photo_video_viewer") + (lightbox.eql?(:true) ? stylesheet_link_tag('lib/jquery.lightbox') : '')
  end
  content_for :js_data do
    javascript_include_tag("public/photo_video_viewer") + (lightbox.eql?(:true) ? javascript_include_tag('lib/jquery.lightbox.custom.min') : '')
  end 
end
ipad_user_agent?() click to toggle source
# File app/helpers/application_helper.rb, line 159
def ipad_user_agent?
  # Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) 
  # Version/4.0.4 Mobile/7B314 Safari/531.21.10
  request.env["HTTP_USER_AGENT"] && !request.env["HTTP_USER_AGENT"].match(/(iPad)/).nil?
end
iphone_user_agent?() click to toggle source

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

# File app/helpers/application_helper.rb, line 155
def iphone_user_agent?
  request.env["HTTP_USER_AGENT"] && !request.env["HTTP_USER_AGENT"].match(/iPhone/).nil?
end
locale_es_or_eu() click to toggle source
# File app/helpers/application_helper.rb, line 332
def locale_es_or_eu
  I18n.locale.to_s.eql?('eu') ? 'eu' : 'es'
end
mobile_user_agent?() click to toggle source
# File app/helpers/application_helper.rb, line 165
def mobile_user_agent?
  ipad_user_agent? || iphone_user_agent? || floki_user_agent?
end
notifications_count() click to toggle source
# File app/helpers/application_helper.rb, line 265
def notifications_count
  logged_in? ? current_user.notifications.pending.count : 0
end
render_date(date='-') click to toggle source
# File app/helpers/application_helper.rb, line 301
def render_date(date='-')
  date_text = (date.is_a?(Time) || date.is_a?(Date)) ? I18n.l(date.to_date, :format => :long) : date
  output = []
  output << content_tag(:i, '', :class => 'ico_date')
  output << content_tag(:div, date_text, :class => 'meta_text')
  content_tag(:div, output.join, :class => 'date meta_article')
end
render_loading_spinner(type=nil) click to toggle source
# File app/helpers/application_helper.rb, line 319
def render_loading_spinner(type=nil)
  output = []
  output << image_tag('ajax-loader.gif')
  output << content_tag(:span, t("#{type}.loading"), :class => 'spinner_text') if type.present?
  content_tag(:div, output.join, :class => 'spinner')
end
section_heading_with_context(wrapper, text, context=nil) click to toggle source
# File app/helpers/application_helper.rb, line 284
def section_heading_with_context(wrapper, text, context=nil)
  if context
    text << " #{t('shared.from_context', :name => context.public_name)}"
  end  
  content_tag(wrapper, text, :class => 'section_heading')
end
show_context() click to toggle source
# File app/helpers/application_helper.rb, line 276
def show_context
  !(@area.present? || @politician.present? || @user.present? || @debate.present?)
end
show_see_more_heading(type, context=nil) click to toggle source
# File app/helpers/application_helper.rb, line 326
def show_see_more_heading(type, context=nil)
  output = t("#{type}.more")
  output << " #{t('shared.from_context', :name => context.public_name)}" if context
  output
end
translation_missing_info() click to toggle source
# File app/helpers/application_helper.rb, line 261
def translation_missing_info
  content_tag(:div, t('shared.traslation_missing'), :class => "alert alert-info traslation_missing")
end
video_or_streaming?() click to toggle source

Returns true if a fetured video o streaming is defined.

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