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

Sets a document title.

document_title "Dashboard"


9
10
11
12
13
14
15
16
# 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)


19
20
21
# File 'app/helpers/pages_core/head_tags_helper.rb', line 19

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


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/pages_core/head_tags_helper.rb', line 29

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

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

#head_tagObject

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 %>


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

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

  tag.head { safe_join(head_tag_contents(block_output), "\n") }
end

Generates a link to an RSS feed.

rss_link_tag "My feed", "feed.rss"


64
65
66
67
68
69
# File 'app/helpers/pages_core/head_tags_helper.rb', line 64

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