Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_tab(tab) ⇒ Object


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

def active_tab tab
  return "active" if params[:controller] == tab
  return ""
end

#avatar_url(user) ⇒ Object


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

def avatar_url(user)
  if user.image_url.present?
    user.image_url
  else
    gravatar_id = Digest::MD5::hexdigest(user.email).downcase
    "http://gravatar.com/avatar/#{gravatar_id}.png?r=g&s=25&d=mm"
  end
end

#branding_textObject


41
42
43
# File 'app/helpers/application_helper.rb', line 41

def branding_text
  t('branding', scope: :"header_text", default: '')
end

#fix_me_statement(thing = "") ⇒ Object


45
46
47
# File 'app/helpers/application_helper.rb', line 45

def fix_me_statement(thing = "")
  t('fix_me', scope: :"header_text", thing: thing)
end

#get_header_text(params) ⇒ Object

— fetch strings from en.header_text.yml


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

def get_header_text (params)
  page_name, element, add_in, no_scope, no_msg = params.values_at(:page_name, :element, :add_in, :no_scope, :no_msg)
  return fix_me_statement("element") if element.blank?
 
  scope = (no_scope || page_name.blank?) ? '' : "header_text"
  key = "#{page_name}.#{element}"
  msg = (no_msg) ? '' : fix_me_statement(key)
  default_key = "#{(scope.blank?) ? 'header_text.' : ''}default.#{element}"

  t(key, scope: scope, branding: branding_text, add_in: "#{add_in}", default: [:"#{default_key}", msg])
end

#get_view_text(element) ⇒ Object


36
37
38
39
# File 'app/helpers/application_helper.rb', line 36

def get_view_text(element)
  return fix_me_statement("element") if element.blank?
  t(".#{element}", default: fix_me_statement(".#{element}"))
end

#seo_tag(element, page_name, add_options = {}) ⇒ Object

— set meta tags


53
54
55
# File 'app/helpers/application_helper.rb', line 53

def seo_tag(element, page_name, add_options={})
  content_for (:"#{element}") {get_header_text({element: element, page_name: page_name}.merge(add_options))}
end

#spinner_tag(id) ⇒ Object


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

def spinner_tag id  #Assuming spinner image is called "spinner.gif"

  image_tag("spinner.gif", :id => id, :alt => t(:loading, :scope => 'myinfo.buttons'), :style => "display:none")
end

#yield_or_default(section, default = "") ⇒ Object


57
58
59
60
61
62
63
64
65
# File 'app/helpers/application_helper.rb', line 57

def yield_or_default(section, default="")
  tag_text = content_for(section)  # if content_for() not set, check locale file for controller/action default

  if tag_text.blank?
    tag_text = get_header_text(element: section, page_name: "#{controller_name}.#{action_name}", no_scope: true, no_msg: true)
    tag_text = default if tag_text.blank? # use optional default as last resort
  end
  tag_text
end