Module: PagesHelper
- Includes:
- AssetsHelper, NavigationHelper
- Defined in:
- app/helpers/pages_helper.rb
Overview
This module provides helper methods rendering pages and slices.
Instance Method Summary collapse
-
#add_tracking_code? ⇒ Boolean
If a tracking code should be added to the page.
-
#container(container, options = {}) ⇒ String
Defines and renders a container in a layout.
-
#edit_in_cms ⇒ String
Quick link to edit the current page in the CMS.
-
#google_analytics_tracking_code(*web_property_ids) ⇒ String
Asynchronous Google Analytics Tracking Code.
-
#if_t(key, options = {}) ⇒ String
Translates the key and return an empty string if there is no translation.
-
#markdown(text) ⇒ String
Converts markdown to html.
-
#textilize(text) ⇒ String
Returns the text with all the Textile codes turned into HTML tags.
Methods included from AssetsHelper
#image_if_present, #link_image_if_linkable
Methods included from NavigationHelper
#link_to_page, #navigation, #primary_navigation, #secondary_navigation
Instance Method Details
#add_tracking_code? ⇒ Boolean
If a tracking code should be added to the page. Returns true when the app is in production mode and the user is not signed into the CMS
115 116 117 |
# File 'app/helpers/pages_helper.rb', line 115 def add_tracking_code? Rails.env.production? && ! admin_signed_in? end |
#container(container, options = {}) ⇒ String
Defines and renders a container in a layout.
For example adding the following to a layout will create two containers called container_one and container_two
<article class="container_one">
<%= container "container_one" %>
</article>
<aside class="container_two">
<%= container "container_two" %>
</aside>
21 22 23 24 25 |
# File 'app/helpers/pages_helper.rb', line 21 def container(container, = {}) if @slice_renderer.present? @slice_renderer.render_container(container) end end |
#edit_in_cms ⇒ String
Quick link to edit the current page in the CMS
56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/pages_helper.rb', line 56 def edit_in_cms if admin_signed_in? links = [] links << link_to("Edit #{@page.class.to_s.underscore.humanize} in CMS", admin_page_path(@page), target: '_blank') links << link_to('Edit template in CMS', admin_page_path(@page.parent, entries: 1), target: '_blank') if @page.entry? content = links.collect {|l| content_tag(:p, l) }.join.html_safe content_tag(:div, content, id: 'edit_in_cms') end end |
#google_analytics_tracking_code(*web_property_ids) ⇒ String
Asynchronous Google Analytics Tracking Code. Only added in production when the user is not signed into the CMS.
google_analytics_tracking_code('ABC132')
To track multiple accounts use the following
google_analytics_tracking_code('ABC132', 'DEF546')
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/helpers/pages_helper.rb', line 90 def google_analytics_tracking_code(*web_property_ids) if web_property_ids.first.present? && add_tracking_code? analytics_que = "['_setAccount', '#{web_property_ids.shift}'], ['_trackPageview'], ['_trackPageLoadTime']" web_property_ids.each_with_index do |web_property_id, index| account = (index + 98).chr analytics_que << ", ['#{account}._setAccount', '#{web_property_id}'], ['#{account}._trackPageview'], ['#{account}._trackPageLoadTime']" end javascript_tag <<-JAVASCRIPT var _gaq = _gaq || []; _gaq.push(#{analytics_que}); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); JAVASCRIPT end end |
#if_t(key, options = {}) ⇒ String
Translates the key and return an empty string if there is no translation.
74 75 76 |
# File 'app/helpers/pages_helper.rb', line 74 def if_t(key, = {}) translate(key, ) || '' end |
#markdown(text) ⇒ String
Converts markdown to html.
45 46 47 48 49 50 |
# File 'app/helpers/pages_helper.rb', line 45 def markdown(text) return if text.blank? renderer = Redcarpet::Render::HTML.new(hard_wrap: true) parser = Redcarpet::Markdown.new(renderer) parser.render(text).html_safe end |
#textilize(text) ⇒ String
Returns the text with all the Textile codes turned into HTML tags.
32 33 34 35 36 37 38 |
# File 'app/helpers/pages_helper.rb', line 32 def textilize(text) unless text.blank? red_cloth = RedCloth.new(text) red_cloth.no_span_caps = true red_cloth.to_html.html_safe end end |