Module: PagesCore::HeadTagsHelper

Included in:
ApplicationHelper, Frontend::PagesController
Defined in:
app/helpers/pages_core/head_tags_helper.rb

Instance Method Summary collapse

Instance Method Details

#document_title(*args) ⇒ Object Also known as: page_title

Sets a document title.

document_title "Dashboard"


9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/pages_core/head_tags_helper.rb', line 9

def document_title(*args)
  if args.any?
    @document_title = args.first
  else
    safe_join(
      [@document_title, PagesCore.config(:site_name)].compact.uniq,
      " - "
    )
  end
end

#document_title?Boolean

Returns true if document title has been set.

Returns:

  • (Boolean)


22
23
24
# File 'app/helpers/pages_core/head_tags_helper.rb', line 22

def document_title?
  @document_title ? true : false
end

#feed_tags(options = {}) ⇒ Object

Generates links for all RSS feeds. Specify :include_hidden to also include hidden pages.

feed_tags
feed_tags include_hidden: true


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/pages_core/head_tags_helper.rb', line 32

def feed_tags(options = {})
  feeds = Page.enabled_feeds(@locale, options)
  return unless feeds.any?

  feed_tags = [
    rss_link_tag(PagesCore.config(:site_name),
                 pages_url(@locale, format: :rss))
  ] + feeds.map do |page|
    rss_link_tag("#{PagesCore.config(:site_name)}: #{page.name}",
                 page_url(@locale, page, format: :rss))
  end
  safe_join(feed_tags, "\n")
end

#google_analytics_tags(account_id) ⇒ Object

Outputs Google Analytics tracking code.

google_analytics_tags "UA-12345678-1"


50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/pages_core/head_tags_helper.rb', line 50

def google_analytics_tags()
  javascript_tag(
    "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||" \
      "function(){\n (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new " \
      "Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];" \
      "a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window," \
      "document,'script','//www.google-analytics.com/analytics.js','ga');" \
      "\n\nga('create', '#{account_id}', 'auto');\nga('send', 'pageview');"
  )
end

#head_tag(&block) ⇒ Object

Outputs a HTML5 doctype and head tags, with document title and relevant meta tags. Takes a block which will be placed inside <head>.

<%= head_tag do %>
  <%= stylesheet_link_tag "application" %>
  <%= javascript_include_tag "application" %>
  <%= feed_tags %>
<% end %>


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/pages_core/head_tags_helper.rb', line 71

def head_tag(&block)
  # The block output must be captured first
  block_output = block_given? ? capture(&block) : nil

  safe_join(
    [
      "<!doctype html>\n<html lang=\"#{I18n.locale}\">".html_safe,
      tag.head do
        safe_join(head_tag_contents(block_output), "\n")
      end
    ]
  )
end

Generates a link to an RSS feed.

rss_link_tag "My feed", "feed.rss"


89
90
91
92
93
94
95
96
97
# File 'app/helpers/pages_core/head_tags_helper.rb', line 89

def rss_link_tag(title, href)
  tag(
    :link,
    rel: "alternate",
    type: "application/rss+xml",
    title: title,
    href: href
  )
end

#typekit_tags(kit_id) ⇒ Object

Outputs Typekit tags.

typekit_tags "aadgrag"


103
104
105
106
107
108
# File 'app/helpers/pages_core/head_tags_helper.rb', line 103

def typekit_tags(kit_id)
  safe_join([
              javascript_include_tag("http://use.typekit.com/#{kit_id}.js"),
              javascript_tag("try{Typekit.load();}catch(e){}")
            ], "\n")
end