Module: ApplicationHelper

Defined in:
lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#page_title(default_title = '') ⇒ Object

This prints page title. Call this helper inside title tag of your layout



40
41
42
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 40

def page_title
  @page_title
end

Instance Method Details

#admin_area(&block) ⇒ Object



56
57
58
59
60
61
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 56

def admin_area(&block)
  if user_signed_in?
    content = with_output_buffer(&block)
    (:div, content, :class => 'admin')
  end
end

#flash_messagesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 19

def flash_messages
  return unless flash.any?

  items = []
  flash.each do |name, msg|
    msg   << (:a, raw('&times;'), :href => "#")
    items << (:li, raw(msg), :id => "flash-#{name}")
  end

   :div, :id => 'flash-messages' do
     :ul, raw(items.join)
  end
end

#google_account_idObject



112
113
114
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 112

def 
  ENV['GOOGLE_ACCOUNT_ID'] || google_config(:google_account_id)
end

#google_api_keyObject



116
117
118
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 116

def google_api_key
  ENV['GOOGLE_API_KEY'] || google_config(:google_api_key)
end

#heading(heading, tag = :h1) ⇒ Object



51
52
53
54
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 51

def heading(heading, tag=:h1)
  tag = :h1 if tag.nil?
  (tag, heading)
end

#heading_with_title(heading, tag = nil) ⇒ Object

Print heading (h1 by default) and set page title at the same time. Use this method in your views



46
47
48
49
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 46

def heading_with_title(heading, tag=nil)
  title(heading)
  heading(heading, tag)
end

#ie_body(attrs = {}, &block) ⇒ Object



108
109
110
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 108

def ie_body(attrs={}, &block)
  ie_tag(:body, attrs, &block)
end

#ie_html(attrs = {}, &block) ⇒ Object



104
105
106
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 104

def ie_html(attrs={}, &block)
  ie_tag(:html, attrs, &block)
end

#ie_tag(name = :body, attrs = {}, &block) ⇒ Object

Create a named haml tag to wrap IE conditional around a block paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 89

def ie_tag(name=:body, attrs={}, &block)
  attrs.symbolize_keys!
  result  = "<!--[if lt IE 7 ]> #{ tag(name, add_class('ie6', attrs), true) } <![endif]-->\n".html_safe
  result += "<!--[if IE 7 ]>    #{ tag(name, add_class('ie7', attrs), true) } <![endif]-->\n".html_safe
  result += "<!--[if IE 8 ]>    #{ tag(name, add_class('ie8', attrs), true) } <![endif]-->\n".html_safe
  result += "<!--[if IE 9 ]>    #{ tag(name, add_class('ie9', attrs), true) } <![endif]-->\n".html_safe
  result += "<!--[if (gte IE 9)|!(IE)]><!-->".html_safe

  result +=  name, attrs do
    "<!--<![endif]-->\n".html_safe + with_output_buffer(&block)
  end

  result
end


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 6

def link_to_delete(link, title, heading_tag = :h3)
  content_for :sidebar do
     :div, :class => 'danger-zone' do
      result       =  heading_tag, raw(title)
      link_text    = t('helpers.application.link_to_delete.link_text')
      confirmation = t('helpers.application.link_to_delete.confirmation')

      result << link_to(link_text, link, confirm: confirmation, method: :delete)
      result
    end
  end
end


63
64
65
66
67
68
69
70
71
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 63

def link_to_section(name, options = {}, html_options = {}, &block)
  url_string = url_for(options)

  if "/#{request.path.split('/')[1]}" == url_string
    html_options[:class] = "#{html_options[:class]} current"
  end

  link_to(name, options, html_options, &block)
end


79
80
81
82
83
84
85
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 79

def link_to_website(url, html_options = {})
  return nil if url.blank?

  url = "http://#{url}" unless url =~ /^(ht|f)tps?:\/\//i
  html_options[:href] = url
  (:a, url, html_options)
end

#page_idObject



73
74
75
76
77
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 73

def page_id
  name = 'page-' + request.path_parameters[:controller] + '-' + request.path_parameters[:action]
  name.gsub!(/_+/, '-')
  name
end

#title(page_title) ⇒ Object

Set page title. Use this method in your views



34
35
36
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 34

def title(page_title)
  @page_title = page_title
end