Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ab3d855c
Commit
ab3d855c
authored
Dec 24, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for `twitter:label` meta tags
parent
99dc1fce
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
4 deletions
+86
-4
app/helpers/page_layout_helper.rb
app/helpers/page_layout_helper.rb
+24
-0
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+8
-0
app/views/layouts/_head.html.haml
app/views/layouts/_head.html.haml
+1
-0
app/views/projects/issues/show.html.haml
app/views/projects/issues/show.html.haml
+3
-2
app/views/projects/merge_requests/_show.html.haml
app/views/projects/merge_requests/_show.html.haml
+3
-2
spec/helpers/page_layout_helper_spec.rb
spec/helpers/page_layout_helper_spec.rb
+29
-0
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+18
-0
No files found.
app/helpers/page_layout_helper.rb
View file @
ab3d855c
...
...
@@ -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
...
...
app/models/concerns/issuable.rb
View file @
ab3d855c
...
...
@@ -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
...
...
app/views/layouts/_head.html.haml
View file @
ab3d855c
...
...
@@ -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
...
...
app/views/projects/issues/show.html.haml
View file @
ab3d855c
-
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"
...
...
app/views/projects/merge_requests/_show.html.haml
View file @
ab3d855c
-
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"
...
...
spec/helpers/page_layout_helper_spec.rb
View file @
ab3d855c
...
...
@@ -97,4 +97,33 @@ describe PageLayoutHelper do
end
end
end
describe
'page_card_attributes'
do
it
'raises ArgumentError when given more than two attributes'
do
map
=
{
foo:
'foo'
,
bar:
'bar'
,
baz:
'baz'
}
expect
{
helper
.
page_card_attributes
(
map
)
}.
to
raise_error
(
ArgumentError
,
/more than two attributes/
)
end
it
'rejects blank values'
do
map
=
{
foo:
'foo'
,
bar:
''
}
helper
.
page_card_attributes
(
map
)
expect
(
helper
.
page_card_attributes
).
to
eq
({
foo:
'foo'
})
end
end
describe
'page_card_meta_tags'
do
it
'returns the twitter:label and twitter:data tags'
do
allow
(
helper
).
to
receive
(
:page_card_attributes
).
and_return
(
foo:
'bar'
)
tags
=
helper
.
page_card_meta_tags
aggregate_failures
do
expect
(
tags
).
to
include
%q(<meta property="twitter:label1" content="foo" />)
expect
(
tags
).
to
include
%q(<meta property="twitter:data1" content="bar" />)
end
end
end
end
spec/models/concerns/issuable_spec.rb
View file @
ab3d855c
...
...
@@ -81,4 +81,22 @@ describe Issue, "Issuable" do
expect
(
hook_data
[
:object_attributes
]).
to
eq
(
issue
.
hook_attrs
)
end
end
describe
'#card_attributes'
do
it
'includes the author name'
do
allow
(
issue
).
to
receive
(
:author
).
and_return
(
double
(
name:
'Robert'
))
allow
(
issue
).
to
receive
(
:assignee
).
and_return
(
nil
)
expect
(
issue
.
card_attributes
).
to
eq
({
'Author'
=>
'Robert'
,
'Assignee'
=>
nil
})
end
it
'includes the assignee name'
do
allow
(
issue
).
to
receive
(
:author
).
and_return
(
double
(
name:
'Robert'
))
allow
(
issue
).
to
receive
(
:assignee
).
and_return
(
double
(
name:
'Douwe'
))
expect
(
issue
.
card_attributes
).
to
eq
({
'Author'
=>
'Robert'
,
'Assignee'
=>
'Douwe'
})
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment