Module: PagesCore::HeadTagsHelper
- Included in:
- ApplicationHelper, Frontend::PagesController
- Defined in:
- app/helpers/pages_core/head_tags_helper.rb
Instance Method Summary collapse
-
#document_title(*args) ⇒ Object
Sets a document title.
-
#document_title? ⇒ Boolean
Returns true if document title has been set.
-
#feed_tags(options = {}) ⇒ Object
Generates links for all RSS feeds.
-
#head_tag ⇒ Object
Outputs a HTML5 doctype and head tags, with document title and relevant meta tags.
-
#rss_link_tag(title, href) ⇒ Object
Generates a link to an RSS feed.
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.
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.
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 ( = {}) feeds = Page.enabled_feeds(content_locale, ) return unless feeds.any? = [ 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(, "\n") end |
#head_tag ⇒ 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 %>
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 |
#rss_link_tag(title, href) ⇒ Object
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 |