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
Boxiang Sun
gitlab-ce
Commits
25eea058
Commit
25eea058
authored
Nov 09, 2017
by
Tim Zallmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Icon Sprite URL is also local even if asset_host is set
parent
20ac30a7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
2 deletions
+31
-2
app/helpers/icons_helper.rb
app/helpers/icons_helper.rb
+9
-1
lib/gitlab/gon_helper.rb
lib/gitlab/gon_helper.rb
+1
-1
spec/helpers/icons_helper_spec.rb
spec/helpers/icons_helper_spec.rb
+21
-0
No files found.
app/helpers/icons_helper.rb
View file @
25eea058
module
IconsHelper
extend
self
include
Gitlab
::
CurrentSettings
include
FontAwesome
::
Rails
::
IconHelper
# Creates an icon tag given icon name(s) and possible icon modifiers.
...
...
@@ -23,10 +24,17 @@ module IconsHelper
render
"shared/icons/
#{
icon_name
}
.svg"
,
size:
size
end
def
sprite_icon_path
# 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
sprite_base_url
=
ActionController
::
Base
.
asset_host
.
present?
?
Gitlab
.
config
.
gitlab
.
url
:
nil
ActionController
::
Base
.
helpers
.
image_path
(
'icons.svg'
,
host:
sprite_base_url
)
end
def
sprite_icon
(
icon_name
,
size:
nil
,
css_class:
nil
)
css_classes
=
size
?
"s
#{
size
}
"
:
""
css_classes
<<
"
#{
css_class
}
"
unless
css_class
.
blank?
content_tag
(
:svg
,
content_tag
(
:use
,
""
,
{
"xlink:href"
=>
"
#{
image_path
(
'icons.svg'
)
}
#
#{
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
def
audit_icon
(
names
,
options
=
{})
...
...
lib/gitlab/gon_helper.rb
View file @
25eea058
...
...
@@ -20,7 +20,7 @@ module Gitlab
gon
.
gitlab_url
=
Gitlab
.
config
.
gitlab
.
url
gon
.
revision
=
Gitlab
::
REVISION
gon
.
gitlab_logo
=
ActionController
::
Base
.
helpers
.
asset_path
(
'gitlab_logo.png'
)
gon
.
sprite_icons
=
ActionController
::
Base
.
helpers
.
asset_path
(
'icons.svg'
)
gon
.
sprite_icons
=
IconsHelper
.
sprite_icon_path
if
current_user
gon
.
current_user_id
=
current_user
.
id
...
...
spec/helpers/icons_helper_spec.rb
View file @
25eea058
...
...
@@ -16,6 +16,27 @@ describe IconsHelper do
end
end
describe
'sprite_icon'
do
it
'returns relative path'
do
expect
(
sprite_icon_path
())
.
to
eq
"/image/icons.svg"
end
context
'when an asset_host is set in the config it will return an absolute local URL'
do
let
(
:asset_host
)
{
'http://assets'
}
before
do
allow
(
ActionController
::
Base
).
to
receive
(
:asset_host
).
and_return
(
asset_host
)
end
it
'returns an absolute URL on that asset host'
do
gitlab_url
=
Gitlab
.
config
.
gitlab
.
url
expect
(
sprite_icon_path
())
.
to
eq
"
#{
gitlab_url
}
/image/icons.svg"
end
end
end
describe
'sprite_icon'
do
icon_name
=
'clock'
...
...
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