summaryrefslogtreecommitdiff
path: root/app/helpers/page_layout_helper.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-24 17:03:54 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-24 17:11:08 -0500
commitab3d855c0e1869fd1986c3bcdf7519f6b1cf1fa8 (patch)
tree7d0a1117b4cae0660004c00684dcbab1cde4069a /app/helpers/page_layout_helper.rb
parent99dc1fce5ed84fb78bd993423db9c470021ea3a2 (diff)
downloadgitlab-ce-ab3d855c0e1869fd1986c3bcdf7519f6b1cf1fa8.tar.gz
Add support for `twitter:label` meta tagsrs-opengraph
Diffstat (limited to 'app/helpers/page_layout_helper.rb')
-rw-r--r--app/helpers/page_layout_helper.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb
index 4f1276f93ec..791cb9e50bd 100644
--- a/app/helpers/page_layout_helper.rb
+++ b/app/helpers/page_layout_helper.rb
@@ -58,6 +58,30 @@ module PageLayoutHelper
end
end
+ # Define or get attributes to be used as Twitter card metadata
+ #
+ # map - Hash of label => data pairs. Keys become labels, values become data
+ #
+ # Raises ArgumentError if given more than two attributes
+ def page_card_attributes(map = {})
+ raise ArgumentError, 'cannot provide more than two attributes' if map.length > 2
+
+ @page_card_attributes ||= {}
+ @page_card_attributes = map.reject { |_,v| v.blank? } if map.present?
+ @page_card_attributes
+ end
+
+ def page_card_meta_tags
+ tags = ''
+
+ page_card_attributes.each_with_index do |pair, i|
+ tags << tag(:meta, property: "twitter:label#{i + 1}", content: pair[0])
+ tags << tag(:meta, property: "twitter:data#{i + 1}", content: pair[1])
+ end
+
+ tags.html_safe
+ end
+
def header_title(title = nil, title_url = nil)
if title
@header_title = title