Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_70890014
gitlabhq
提交
d47b3e63
G
gitlabhq
项目概览
m0_70890014
/
gitlabhq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlabhq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d47b3e63
编写于
1月 06, 2016
作者:
R
Robert Speicher
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'more-opengraph' into 'master'
Add Open Graph data for group, project and commit. See merge request !2211
上级
b93744e3
639d4280
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
76 deletion
+40
-76
app/helpers/page_layout_helper.rb
app/helpers/page_layout_helper.rb
+5
-20
app/views/layouts/_head.html.haml
app/views/layouts/_head.html.haml
+5
-2
app/views/layouts/group.html.haml
app/views/layouts/group.html.haml
+4
-3
app/views/layouts/project.html.haml
app/views/layouts/project.html.haml
+4
-3
app/views/projects/commit/show.html.haml
app/views/projects/commit/show.html.haml
+3
-1
app/views/projects/show.html.haml
app/views/projects/show.html.haml
+1
-1
spec/helpers/page_layout_helper_spec.rb
spec/helpers/page_layout_helper_spec.rb
+18
-46
未找到文件。
app/helpers/page_layout_helper.rb
浏览文件 @
d47b3e63
...
...
@@ -27,35 +27,20 @@ module PageLayoutHelper
#
# Returns an HTML-safe String.
def
page_description
(
description
=
nil
)
@page_description
||=
page_description_default
if
description
.
present?
@page_description
=
description
.
squish
els
e
els
if
@page_description
.
present?
sanitize
(
@page_description
,
tags:
[]).
truncate_words
(
30
)
end
end
# Default value for page_description when one hasn't been defined manually by
# a view
def
page_description_default
if
@project
@project
.
description
||
brand_title
else
brand_title
end
end
def
page_image
default
=
image_url
(
'gitlab_logo.png'
)
if
@project
@project
.
avatar_url
||
default
elsif
@user
avatar_icon
(
@user
)
else
default
end
subject
=
@project
||
@user
||
@group
image
=
subject
.
avatar_url
if
subject
.
present?
image
||
default
end
# Define or get attributes to be used as Twitter card metadata
...
...
app/views/layouts/_head.html.haml
浏览文件 @
d47b3e63
-
page_description
brand_title
unless
page_description
-
site_name
=
"GitLab"
%head
{
prefix:
"og: http://ogp.me/ns#"
}
%meta
{
charset:
"utf-8"
}
%meta
{
'http-equiv'
=>
'X-UA-Compatible'
,
content:
'IE=edge'
}
-# Open Graph - http://ogp.me/
%meta
{
property:
'og:type'
,
content:
"object"
}
%meta
{
property:
'og:site_name'
,
content:
"GitLab"
}
%meta
{
property:
'og:site_name'
,
content:
site_name
}
%meta
{
property:
'og:title'
,
content:
page_title
}
%meta
{
property:
'og:description'
,
content:
page_description
}
%meta
{
property:
'og:image'
,
content:
page_image
}
...
...
@@ -17,7 +20,7 @@
%meta
{
property:
'twitter:image'
,
content:
page_image
}
=
page_card_meta_tags
%title
=
page_title
(
'GitLab'
)
%title
=
page_title
(
site_name
)
%meta
{
name:
"description"
,
content:
page_description
}
=
favicon_link_tag
'favicon.ico'
...
...
app/views/layouts/group.html.haml
浏览文件 @
d47b3e63
-
page_title
@group
.
name
-
header_title
group_title
(
@group
)
unless
header_title
-
sidebar
"group"
unless
sidebar
-
page_title
@group
.
name
-
page_description
@group
.
description
unless
page_description
-
header_title
group_title
(
@group
)
unless
header_title
-
sidebar
"group"
unless
sidebar
=
render
template:
"layouts/application"
app/views/layouts/project.html.haml
浏览文件 @
d47b3e63
-
page_title
@project
.
name_with_namespace
-
header_title
project_title
(
@project
)
unless
header_title
-
sidebar
"project"
unless
sidebar
-
page_title
@project
.
name_with_namespace
-
page_description
@project
.
description
unless
page_description
-
header_title
project_title
(
@project
)
unless
header_title
-
sidebar
"project"
unless
sidebar
-
content_for
:scripts_body_top
do
-
project
=
@target_project
||
@project
...
...
app/views/projects/commit/show.html.haml
浏览文件 @
d47b3e63
-
page_title
"
#{
@commit
.
title
}
(
#{
@commit
.
short_id
}
)"
,
"Commits"
-
page_title
"
#{
@commit
.
title
}
(
#{
@commit
.
short_id
}
)"
,
"Commits"
-
page_description
@commit
.
description
=
render
"projects/commits/header_title"
=
render
"commit_box"
-
if
@ci_commit
...
...
app/views/projects/show.html.haml
浏览文件 @
d47b3e63
...
...
@@ -68,4 +68,4 @@
=
render
'projects/last_commit'
,
commit:
@repository
.
commit
,
project:
@project
%div
{
class:
"project-show-#{default_project_view}"
}
=
render
default_project_view
\ No newline at end of file
=
render
default_project_view
spec/helpers/page_layout_helper_spec.rb
浏览文件 @
d47b3e63
...
...
@@ -2,10 +2,8 @@ require 'rails_helper'
describe
PageLayoutHelper
do
describe
'page_description'
do
it
'defaults to value returned by page_description_default helper'
do
allow
(
helper
).
to
receive
(
:page_description_default
).
and_return
(
'Foo'
)
expect
(
helper
.
page_description
).
to
eq
'Foo'
it
'defaults to nil'
do
expect
(
helper
.
page_description
).
to
eq
nil
end
it
'returns the last-pushed description'
do
...
...
@@ -42,58 +40,32 @@ describe PageLayoutHelper do
end
end
describe
'page_description_default'
do
it
'uses Project description when available'
do
project
=
double
(
description:
'Project Description'
)
helper
.
instance_variable_set
(
:@project
,
project
)
expect
(
helper
.
page_description_default
).
to
eq
'Project Description'
end
it
'uses brand_title when Project description is nil'
do
project
=
double
(
description:
nil
)
helper
.
instance_variable_set
(
:@project
,
project
)
expect
(
helper
).
to
receive
(
:brand_title
).
and_return
(
'Brand Title'
)
expect
(
helper
.
page_description_default
).
to
eq
'Brand Title'
end
it
'falls back to brand_title'
do
allow
(
helper
).
to
receive
(
:brand_title
).
and_return
(
'Brand Title'
)
expect
(
helper
.
page_description_default
).
to
eq
'Brand Title'
end
end
describe
'page_image'
do
it
'defaults to the GitLab logo'
do
expect
(
helper
.
page_image
).
to
end_with
'assets/gitlab_logo.png'
end
context
'with @project'
do
it
'uses Project avatar if available'
do
project
=
double
(
avatar_url:
'http://example.com/uploads/avatar.png'
)
helper
.
instance_variable_set
(
:@project
,
project
)
%w(project user group)
.
each
do
|
type
|
context
"with @
#{
type
}
assigned"
do
it
"uses
#{
type
.
titlecase
}
avatar if available"
do
object
=
double
(
avatar_url:
'http://example.com/uploads/avatar.png'
)
assign
(
type
,
object
)
expect
(
helper
.
page_image
).
to
eq
pro
ject
.
avatar_url
end
expect
(
helper
.
page_image
).
to
eq
ob
ject
.
avatar_url
end
it
'falls back to the default
'
do
pro
ject
=
double
(
avatar_url:
nil
)
helper
.
instance_variable_set
(
:@project
,
pro
ject
)
it
'falls back to the default when avatar_url is nil
'
do
ob
ject
=
double
(
avatar_url:
nil
)
assign
(
type
,
ob
ject
)
expect
(
helper
.
page_image
).
to
end_with
'assets/gitlab_logo.png'
expect
(
helper
.
page_image
).
to
end_with
'assets/gitlab_logo.png'
end
end
end
context
'with @user'
do
it
'delegates to avatar_icon helper'
do
user
=
double
(
'User'
)
helper
.
instance_variable_set
(
:@user
,
user
)
expect
(
helper
).
to
receive
(
:avatar_icon
).
with
(
user
)
helper
.
page_image
context
"with no assignments"
do
it
'falls back to the default'
do
expect
(
helper
.
page_image
).
to
end_with
'assets/gitlab_logo.png'
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录