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
# File 'app/helpers/pages_core/head_tags_helper.rb', line 50

def google_analytics_tags()
  render(partial: "pages_core/google_analytics",
         locals: { account_id:  })
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 %>


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/pages_core/head_tags_helper.rb', line 65

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"


83
84
85
86
87
88
# File 'app/helpers/pages_core/head_tags_helper.rb', line 83

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"


94
95
96
97
98
99
# File 'app/helpers/pages_core/head_tags_helper.rb', line 94

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