Class: Trek::Icon::SpriteComponent
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Trek::Icon::SpriteComponent
show all
- Defined in:
- app/components/trek/icon/sprite_component.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#stimulus_action, #stimulus_class, #stimulus_class_hash, #stimulus_class_key, #stimulus_target, #stimulus_target_hash, #stimulus_target_key, #stimulus_value, #stimulus_value_hash, #stimulus_value_key
#class_for, #class_names_for, #root_class
#identifier
Class Method Details
.all(scope: "*") ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/components/trek/icon/sprite_component.rb', line 21
def all(scope: "*")
if scope == "*"
prefix = ""
else
prefix = "#{scope}/"
scope = File.join(scope, "*")
end
Dir.glob(File.join(icon_paths.first, scope))
.select { |f| File.file?(f) && File.extname(f) == ".svg" }
.map { |f| prefix + Pathname.new(f).basename(".svg").to_s }
.sort
end
|
.icon_paths ⇒ Object
35
36
37
38
39
40
41
|
# File 'app/components/trek/icon/sprite_component.rb', line 35
def icon_paths
[
Rails.root.join("app/assets/icons/"),
Engine.root.join("app/assets/icons/")
]
end
|
Instance Method Details
#call ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'app/components/trek/icon/sprite_component.rb', line 6
def call
tag.svg(class: root_class, style: "display: none") do
tag.defs do
safe_join(Current.icons.map do |key|
svg_as_symbol(key)
end)
end
end
end
|
#render? ⇒ Boolean
16
17
18
|
# File 'app/components/trek/icon/sprite_component.rb', line 16
def render?
Current.icons.present?
end
|