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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
df1b6340
Commit
df1b6340
authored
Jan 18, 2019
by
Fabian Schneider
Committed by
Grzegorz Bizon
Jan 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add flat-square badge style
parent
b479ddc7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
4 deletions
+94
-4
app/controllers/projects/badges_controller.rb
app/controllers/projects/badges_controller.rb
+12
-1
app/views/projects/badges/badge_flat-square.svg.erb
app/views/projects/badges/badge_flat-square.svg.erb
+17
-0
changelogs/unreleased/30120-add-flat-square-badge-style.yml
changelogs/unreleased/30120-add-flat-square-badge-style.yml
+5
-0
doc/user/project/pipelines/settings.md
doc/user/project/pipelines/settings.md
+21
-1
spec/controllers/projects/badges_controller_spec.rb
spec/controllers/projects/badges_controller_spec.rb
+39
-2
No files found.
app/controllers/projects/badges_controller.rb
View file @
df1b6340
...
...
@@ -21,11 +21,22 @@ class Projects::BadgesController < Projects::ApplicationController
private
def
badge_layout
case
params
[
:style
]
when
'flat'
'badge'
when
'flat-square'
'badge_flat-square'
else
'badge'
end
end
def
render_badge
(
badge
)
respond_to
do
|
format
|
format
.
html
{
render_404
}
format
.
svg
do
render
'badge'
,
locals:
{
badge:
badge
.
template
}
render
badge_layout
,
locals:
{
badge:
badge
.
template
}
end
end
end
...
...
app/views/projects/badges/badge_flat-square.svg.erb
0 → 100644
View file @
df1b6340
<svg
xmlns=
"http://www.w3.org/2000/svg"
width=
"
<%=
badge
.
width
%>
"
height=
"20"
>
<g
shape-rendering=
"crispEdges"
>
<path
fill=
"
<%=
badge
.
key_color
%>
"
d=
"M0 0 h
<%=
badge
.
key_width
%>
v20 H0 z"
/>
<path
fill=
"
<%=
badge
.
value_color
%>
"
d=
"M
<%=
badge
.
key_width
%>
0 h
<%=
badge
.
value_width
%>
v20 H
<%=
badge
.
key_width
%>
z"
/>
</g>
<g
fill=
"#fff"
text-anchor=
"middle"
>
<g
font-family=
"DejaVu Sans,Verdana,Geneva,sans-serif"
font-size=
"11"
>
<text
x=
"
<%=
badge
.
key_text_anchor
%>
"
y=
"14"
>
<%=
badge
.
key_text
%>
</text>
<text
x=
"
<%=
badge
.
value_text_anchor
%>
"
y=
"14"
>
<%=
badge
.
value_text
%>
</text>
</g>
</g>
</svg>
changelogs/unreleased/30120-add-flat-square-badge-style.yml
0 → 100644
View file @
df1b6340
---
title
:
Add flat-square badge style
merge_request
:
24172
author
:
Fabian Schneider @fabsrc
type
:
added
doc/user/project/pipelines/settings.md
View file @
df1b6340
...
...
@@ -157,7 +157,27 @@ into your `README.md`:
![
coverage
](
https://gitlab.com/gitlab-org/gitlab-ce/badges/master/coverage.svg?job=coverage
)
```
### Environment Variables
### Badge styles
Pipeline badges can be rendered in different styles by adding the
`style=style_name`
parameter to the URL. Currently two styles are available:
#### Flat (default)
```
https://example.gitlab.com/<namespace>/<project>/badges/<branch>/coverage.svg?style=flat
```
![
Badge flat style
](
https://gitlab.com/gitlab-org/gitlab-ce/badges/master/coverage.svg?job=coverage&style=flat
)
#### Flat square
```
https://example.gitlab.com/<namespace>/<project>/badges/<branch>/coverage.svg?style=flat-square
```
![
Badge flat square style
](
https://gitlab.com/gitlab-org/gitlab-ce/badges/master/coverage.svg?job=coverage&style=flat-square
)
## Environment Variables
[
Environment variables
](
../../../ci/variables/README.html#variables
)
can be set in an environment to be available to a runner.
...
...
spec/controllers/projects/badges_controller_spec.rb
View file @
df1b6340
...
...
@@ -22,7 +22,44 @@ describe Projects::BadgesController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
def
get_badge
(
badge
)
get
badge
,
params:
{
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
ref:
pipeline
.
ref
},
format: :svg
it
'renders the `flat` badge layout by default'
do
get_badge
(
:coverage
)
expect
(
response
).
to
render_template
(
'projects/badges/badge'
)
end
context
'when style param is set to `flat`'
do
it
'renders the `flat` badge layout'
do
get_badge
(
:coverage
,
'flat'
)
expect
(
response
).
to
render_template
(
'projects/badges/badge'
)
end
end
context
'when style param is set to an invalid type'
do
it
'renders the `flat` (default) badge layout'
do
get_badge
(
:coverage
,
'xxx'
)
expect
(
response
).
to
render_template
(
'projects/badges/badge'
)
end
end
context
'when style param is set to `flat-square`'
do
it
'renders the `flat-square` badge layout'
do
get_badge
(
:coverage
,
'flat-square'
)
expect
(
response
).
to
render_template
(
'projects/badges/badge_flat-square'
)
end
end
def
get_badge
(
badge
,
style
=
nil
)
params
=
{
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
,
ref:
pipeline
.
ref
,
style:
style
}
get
badge
,
params:
params
,
format: :svg
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