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
a068fe3f
Commit
a068fe3f
authored
4 years ago
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memoize the rendered icon tags and partials
parent
c0dfeca4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
app/helpers/icons_helper.rb
app/helpers/icons_helper.rb
+28
-16
No files found.
app/helpers/icons_helper.rb
View file @
a068fe3f
...
@@ -24,10 +24,12 @@ module IconsHelper
...
@@ -24,10 +24,12 @@ module IconsHelper
end
end
def
custom_icon
(
icon_name
,
size:
DEFAULT_ICON_SIZE
)
def
custom_icon
(
icon_name
,
size:
DEFAULT_ICON_SIZE
)
memoized_icon
(
"
#{
icon_name
}
_
#{
size
}
"
)
do
# We can't simply do the below, because there are some .erb SVGs.
# We can't simply do the below, because there are some .erb SVGs.
# File.read(Rails.root.join("app/views/shared/icons/_#{icon_name}.svg")).html_safe
# File.read(Rails.root.join("app/views/shared/icons/_#{icon_name}.svg")).html_safe
render
"shared/icons/
#{
icon_name
}
.svg"
,
size:
size
render
"shared/icons/
#{
icon_name
}
.svg"
,
size:
size
end
end
end
def
sprite_icon_path
def
sprite_icon_path
@sprite_icon_path
||=
begin
@sprite_icon_path
||=
begin
...
@@ -46,6 +48,7 @@ module IconsHelper
...
@@ -46,6 +48,7 @@ module IconsHelper
end
end
def
sprite_icon
(
icon_name
,
size:
DEFAULT_ICON_SIZE
,
css_class:
nil
)
def
sprite_icon
(
icon_name
,
size:
DEFAULT_ICON_SIZE
,
css_class:
nil
)
memoized_icon
(
"
#{
icon_name
}
_
#{
size
}
_
#{
css_class
}
"
)
do
if
known_sprites
&
.
exclude?
(
icon_name
)
if
known_sprites
&
.
exclude?
(
icon_name
)
exception
=
ArgumentError
.
new
(
"
#{
icon_name
}
is not a known icon in @gitlab-org/gitlab-svg"
)
exception
=
ArgumentError
.
new
(
"
#{
icon_name
}
is not a known icon in @gitlab-org/gitlab-svg"
)
Gitlab
::
ErrorTracking
.
track_and_raise_for_dev_exception
(
exception
)
Gitlab
::
ErrorTracking
.
track_and_raise_for_dev_exception
(
exception
)
...
@@ -62,6 +65,7 @@ module IconsHelper
...
@@ -62,6 +65,7 @@ module IconsHelper
data:
{
testid:
"
#{
icon_name
}
-icon"
}
data:
{
testid:
"
#{
icon_name
}
-icon"
}
)
)
end
end
end
def
loading_icon
(
container:
false
,
color:
'orange'
,
size:
'sm'
,
css_class:
nil
)
def
loading_icon
(
container:
false
,
color:
'orange'
,
size:
'sm'
,
css_class:
nil
)
css_classes
=
[
'gl-spinner'
,
"gl-spinner-
#{
color
}
"
,
"gl-spinner-
#{
size
}
"
]
css_classes
=
[
'gl-spinner'
,
"gl-spinner-
#{
color
}
"
,
"gl-spinner-
#{
size
}
"
]
...
@@ -169,4 +173,12 @@ module IconsHelper
...
@@ -169,4 +173,12 @@ module IconsHelper
@known_sprites
||=
Gitlab
::
Json
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'node_modules/@gitlab/svgs/dist/icons.json'
)))[
'icons'
]
@known_sprites
||=
Gitlab
::
Json
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'node_modules/@gitlab/svgs/dist/icons.json'
)))[
'icons'
]
end
end
def
memoized_icon
(
key
)
@rendered_icons
||=
{}
@rendered_icons
[
key
]
||
(
@rendered_icons
[
key
]
=
yield
)
end
end
end
This diff is collapsed.
Click to expand it.
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