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
(also: #page_title)
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.
-
#google_analytics_tags(account_id) ⇒ Object
Outputs Google Analytics tracking code.
-
#head_tag(&block) ⇒ 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.
-
#typekit_tags(kit_id) ⇒ Object
Outputs Typekit tags.
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.
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.
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 ( = {}) feeds = Page.enabled_feeds(@locale, ) return unless feeds.any? = [ 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(, "\n") end |
#google_analytics_tags(account_id) ⇒ Object
Outputs Google Analytics tracking code.
"UA-12345678-1"
50 51 52 53 |
# File 'app/helpers/pages_core/head_tags_helper.rb', line 50 def (account_id) render(partial: "pages_core/google_analytics", locals: { account_id: 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 |
#rss_link_tag(title, href) ⇒ Object
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.
"aadgrag"
94 95 96 97 98 99 |
# File 'app/helpers/pages_core/head_tags_helper.rb', line 94 def (kit_id) safe_join([ javascript_include_tag("http://use.typekit.com/#{kit_id}.js"), javascript_tag("try{Typekit.load();}catch(e){}") ], "\n") end |