Module: ApplicationHelper
- Defined in:
- lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb
Instance Attribute Summary collapse
-
#page_title(default_title = '') ⇒ Object
This prints page title.
Instance Method Summary collapse
- #admin_area(&block) ⇒ Object
- #flash_messages ⇒ Object
- #google_account_id ⇒ Object
- #google_api_key ⇒ Object
- #heading(heading, tag = :h1) ⇒ Object
-
#heading_with_title(heading, tag = nil) ⇒ Object
Print heading (h1 by default) and set page title at the same time.
- #ie_body(attrs = {}, &block) ⇒ Object
- #ie_html(attrs = {}, &block) ⇒ Object
-
#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.
- #link_to_delete(link, title, heading_tag = :h3) ⇒ Object
- #link_to_section(name, options = {}, html_options = {}, &block) ⇒ Object
- #link_to_website(url, html_options = {}) ⇒ Object
- #page_id ⇒ Object
-
#title(page_title) ⇒ Object
Set page title.
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) content_tag(:div, content, :class => 'admin') end end |
#flash_messages ⇒ Object
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 return unless flash.any? items = [] flash.each do |name, msg| msg << content_tag(:a, raw('×'), :href => "#") items << content_tag(:li, raw(msg), :id => "flash-#{name}") end content_tag :div, :id => 'flash-messages' do content_tag :ul, raw(items.join) end end |
#google_account_id ⇒ Object
112 113 114 |
# File 'lib/playmo/recipes/templates/application_helper_recipe/application_helper.rb', line 112 def google_account_id ENV['GOOGLE_ACCOUNT_ID'] || google_config(:google_account_id) end |
#google_api_key ⇒ Object
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? content_tag(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 += content_tag name, attrs do "<!--<![endif]-->\n".html_safe + with_output_buffer(&block) end result end |
#link_to_delete(link, title, heading_tag = :h3) ⇒ Object
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 content_tag :div, :class => 'danger-zone' do result = content_tag 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 |
#link_to_section(name, options = {}, html_options = {}, &block) ⇒ Object
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, = {}, = {}, &block) url_string = url_for() if "/#{request.path.split('/')[1]}" == url_string [:class] = "#{html_options[:class]} current" end link_to(name, , , &block) end |
#link_to_website(url, html_options = {}) ⇒ Object
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, = {}) return nil if url.blank? url = "http://#{url}" unless url =~ /^(ht|f)tps?:\/\//i [:href] = url content_tag(:a, url, ) end |
#page_id ⇒ Object
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 |