summaryrefslogtreecommitdiff
path: root/app
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
parent99dc1fce5ed84fb78bd993423db9c470021ea3a2 (diff)
downloadgitlab-ce-ab3d855c0e1869fd1986c3bcdf7519f6b1cf1fa8.tar.gz
Add support for `twitter:label` meta tagsrs-opengraph
Diffstat (limited to 'app')
-rw-r--r--app/helpers/page_layout_helper.rb24
-rw-r--r--app/models/concerns/issuable.rb8
-rw-r--r--app/views/layouts/_head.html.haml1
-rw-r--r--app/views/projects/issues/show.html.haml5
-rw-r--r--app/views/projects/merge_requests/_show.html.haml5
5 files changed, 39 insertions, 4 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
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index f56fd3e02d4..919833f6df5 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -161,6 +161,14 @@ module Issuable
self.class.to_s.underscore
end
+ # Returns a Hash of attributes to be used for Twitter card metadata
+ def card_attributes
+ {
+ 'Author' => author.try(:name),
+ 'Assignee' => assignee.try(:name)
+ }
+ end
+
def notes_with_associations
notes.includes(:author, :project)
end
diff --git a/app/views/layouts/_head.html.haml b/app/views/layouts/_head.html.haml
index d1cb07eaa66..434605e59ae 100644
--- a/app/views/layouts/_head.html.haml
+++ b/app/views/layouts/_head.html.haml
@@ -12,6 +12,7 @@
%meta{property: 'og:description', content: page_description}
%meta{property: 'og:image', content: page_image}
%meta{property: 'og:url', content: request.base_url + request.fullpath}
+ = page_card_meta_tags
%title= page_title
diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml
index f2a261ab426..f548383008d 100644
--- a/app/views/projects/issues/show.html.haml
+++ b/app/views/projects/issues/show.html.haml
@@ -1,5 +1,6 @@
-- page_title "#{@issue.title} (##{@issue.iid})", "Issues"
-- page_description @issue.description
+- page_title "#{@issue.title} (##{@issue.iid})", "Issues"
+- page_description @issue.description
+- page_card_attributes @issue.card_attributes
= render "header_title"
diff --git a/app/views/projects/merge_requests/_show.html.haml b/app/views/projects/merge_requests/_show.html.haml
index 75f44557964..ba7c2c01e93 100644
--- a/app/views/projects/merge_requests/_show.html.haml
+++ b/app/views/projects/merge_requests/_show.html.haml
@@ -1,5 +1,6 @@
-- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests"
-- page_description @merge_request.description
+- page_title "#{@merge_request.title} (##{@merge_request.iid})", "Merge Requests"
+- page_description @merge_request.description
+- page_card_attributes @merge_request.card_attributes
= render "header_title"