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
Jérome Perrin
gitlab-ce
Commits
01240a18
Commit
01240a18
authored
Nov 09, 2017
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Function + Test based on MR
parent
fb1b88de
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
12 deletions
+9
-12
app/helpers/icons_helper.rb
app/helpers/icons_helper.rb
+2
-3
spec/helpers/icons_helper_spec.rb
spec/helpers/icons_helper_spec.rb
+7
-9
No files found.
app/helpers/icons_helper.rb
View file @
01240a18
module
IconsHelper
module
IconsHelper
extend
self
extend
self
include
Gitlab
::
CurrentSettings
include
FontAwesome
::
Rails
::
IconHelper
include
FontAwesome
::
Rails
::
IconHelper
# Creates an icon tag given icon name(s) and possible icon modifiers.
# Creates an icon tag given icon name(s) and possible icon modifiers.
...
@@ -27,14 +26,14 @@ module IconsHelper
...
@@ -27,14 +26,14 @@ module IconsHelper
def
sprite_icon_path
def
sprite_icon_path
# SVG Sprites currently don't work across domains, so in the case of a CDN
# SVG Sprites currently don't work across domains, so in the case of a CDN
# we have to set the current path deliberately to prevent addition of asset_host
# we have to set the current path deliberately to prevent addition of asset_host
sprite_base_url
=
ActionController
::
Base
.
asset_host
.
present?
?
Gitlab
.
config
.
gitlab
.
url
:
nil
sprite_base_url
=
Gitlab
.
config
.
gitlab
.
url
if
ActionController
::
Base
.
asset_host
ActionController
::
Base
.
helpers
.
image_path
(
'icons.svg'
,
host:
sprite_base_url
)
ActionController
::
Base
.
helpers
.
image_path
(
'icons.svg'
,
host:
sprite_base_url
)
end
end
def
sprite_icon
(
icon_name
,
size:
nil
,
css_class:
nil
)
def
sprite_icon
(
icon_name
,
size:
nil
,
css_class:
nil
)
css_classes
=
size
?
"s
#{
size
}
"
:
""
css_classes
=
size
?
"s
#{
size
}
"
:
""
css_classes
<<
"
#{
css_class
}
"
unless
css_class
.
blank?
css_classes
<<
"
#{
css_class
}
"
unless
css_class
.
blank?
content_tag
(
:svg
,
content_tag
(
:use
,
""
,
{
"xlink:href"
=>
"
#{
sprite_icon_path
()
}
#
#{
icon_name
}
"
}
),
class:
css_classes
.
empty?
?
nil
:
css_classes
)
content_tag
(
:svg
,
content_tag
(
:use
,
""
,
{
"xlink:href"
=>
"
#{
sprite_icon_path
}
#
#{
icon_name
}
"
}
),
class:
css_classes
.
empty?
?
nil
:
css_classes
)
end
end
def
audit_icon
(
names
,
options
=
{})
def
audit_icon
(
names
,
options
=
{})
...
...
spec/helpers/icons_helper_spec.rb
View file @
01240a18
require
'spec_helper'
require
'spec_helper'
describe
IconsHelper
do
describe
IconsHelper
do
let
(
:icons_path
)
{
ActionController
::
Base
.
helpers
.
image_path
(
"icons.svg"
)
}
describe
'icon'
do
describe
'icon'
do
it
'returns aria-hidden by default'
do
it
'returns aria-hidden by default'
do
star
=
icon
(
'star'
)
star
=
icon
(
'star'
)
...
@@ -18,8 +20,8 @@ describe IconsHelper do
...
@@ -18,8 +20,8 @@ describe IconsHelper do
describe
'sprite_icon_path'
do
describe
'sprite_icon_path'
do
it
'returns relative path'
do
it
'returns relative path'
do
expect
(
sprite_icon_path
()
)
expect
(
sprite_icon_path
)
.
to
eq
icons_path
()
.
to
eq
icons_path
end
end
context
'when an asset_host is set in the config it will return an absolute local URL'
do
context
'when an asset_host is set in the config it will return an absolute local URL'
do
...
@@ -41,17 +43,17 @@ describe IconsHelper do
...
@@ -41,17 +43,17 @@ describe IconsHelper do
it
'returns svg icon html'
do
it
'returns svg icon html'
do
expect
(
sprite_icon
(
icon_name
).
to_s
)
expect
(
sprite_icon
(
icon_name
).
to_s
)
.
to
eq
"<svg><use xlink:href=
\"
#{
icons_path
()
}
#
#{
icon_name
}
\"
></use></svg>"
.
to
eq
"<svg><use xlink:href=
\"
#{
icons_path
}
#
#{
icon_name
}
\"
></use></svg>"
end
end
it
'returns svg icon html + size classes'
do
it
'returns svg icon html + size classes'
do
expect
(
sprite_icon
(
icon_name
,
size:
72
).
to_s
)
expect
(
sprite_icon
(
icon_name
,
size:
72
).
to_s
)
.
to
eq
"<svg class=
\"
s72
\"
><use xlink:href=
\"
#{
icons_path
()
}
#
#{
icon_name
}
\"
></use></svg>"
.
to
eq
"<svg class=
\"
s72
\"
><use xlink:href=
\"
#{
icons_path
}
#
#{
icon_name
}
\"
></use></svg>"
end
end
it
'returns svg icon html + size classes + additional class'
do
it
'returns svg icon html + size classes + additional class'
do
expect
(
sprite_icon
(
icon_name
,
size:
72
,
css_class:
'icon-danger'
).
to_s
)
expect
(
sprite_icon
(
icon_name
,
size:
72
,
css_class:
'icon-danger'
).
to_s
)
.
to
eq
"<svg class=
\"
s72 icon-danger
\"
><use xlink:href=
\"
#{
icons_path
()
}
#{
icon_name
}
\"
></use></svg>"
.
to
eq
"<svg class=
\"
s72 icon-danger
\"
><use xlink:href=
\"
#{
icons_path
}
#
#{
icon_name
}
\"
></use></svg>"
end
end
end
end
...
@@ -160,8 +162,4 @@ describe IconsHelper do
...
@@ -160,8 +162,4 @@ describe IconsHelper do
expect
(
file_type_icon_class
(
'file'
,
0
,
'CHANGELOG'
)).
to
eq
'file-text-o'
expect
(
file_type_icon_class
(
'file'
,
0
,
'CHANGELOG'
)).
to
eq
'file-text-o'
end
end
end
end
def
icons_path
ActionController
::
Base
.
helpers
.
image_path
(
"icons.svg"
)
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