Module: FluentIcons
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/fluent-icons.rb,
lib/fluent-icons/cache.rb,
lib/fluent-icons/fluent.rb,
lib/fluent-icons/helper.rb,
lib/fluent-icons/railtie.rb,
lib/fluent-icons/scanner.rb,
lib/fluent-icons/version.rb,
lib/fluent-icons/component.rb,
lib/fluent-icons/lazy_loader.rb,
lib/fluent-icons/configuration.rb,
lib/generators/fluent_icons/install_generator.rb
Defined Under Namespace
Modules: Generators Classes: Cache, Component, Configuration, Fluent, LazyLoader, Railtie, Scanner
Constant Summary collapse
- ROOT_PATH =
Root path for the gem (used by rake tasks)
File.dirname(__FILE__)
- SYMBOLS =
For backwards compatibility
LazyLoader.symbols.freeze
- FLUENT_UI_ICONS_VERSION =
'1.1.324'.freeze
- VERSION =
'3.0.0.324'.freeze
Class Method Summary collapse
-
.configuration ⇒ FluentIcons::Configuration
The current configuration.
-
.configure {|configuration| ... } ⇒ Object
Configure FluentIcons.
-
.reset_configuration! ⇒ Object
Reset configuration to defaults.
-
.symbols ⇒ Object
Lazy-loaded symbols (supports compiled data.json in production).
Instance Method Summary collapse
- #clear_fluent_helper_cache ⇒ Object
- #fluent(symbol, options = {}, fallback_text = 'Error?') ⇒ Object (also: #fluent_icon)
Class Method Details
.configuration ⇒ FluentIcons::Configuration
Returns The current configuration.
15 16 17 |
# File 'lib/fluent-icons/configuration.rb', line 15 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configure FluentIcons
27 28 29 |
# File 'lib/fluent-icons/configuration.rb', line 27 def configure yield(configuration) end |
.reset_configuration! ⇒ Object
Reset configuration to defaults
32 33 34 |
# File 'lib/fluent-icons/configuration.rb', line 32 def reset_configuration! @configuration = Configuration.new end |
.symbols ⇒ Object
Lazy-loaded symbols (supports compiled data.json in production)
23 24 25 |
# File 'lib/fluent-icons.rb', line 23 def self.symbols LazyLoader.symbols end |
Instance Method Details
#clear_fluent_helper_cache ⇒ Object
50 51 52 53 |
# File 'lib/fluent-icons/helper.rb', line 50 def clear_fluent_helper_cache fluent_helper_cache.clear Cache.clear end |
#fluent(symbol, options = {}, fallback_text = 'Error?') ⇒ Object Also known as: fluent_icon
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fluent-icons/helper.rb', line 10 def fluent(symbol, = {}, fallback_text = 'Error?') # Normalize symbol to string symbol = symbol.to_s if symbol.is_a?(Symbol) # If ViewComponent is enabled via configuration, use the component if FluentIcons.configuration.use_view_component && defined?(FluentIcons::Component) # Extract style and weight from options style = .delete(:style) || 'regular' weight = .delete(:weight) || 20 # Render the component component = FluentIcons::Component.new( name: symbol, style: style, weight: weight, ** ) return component.render_in(self) end # Fallback to direct SVG rendering # Layer 1: In-memory cache (fastest) cache_key = [symbol, ] tag = fluent_helper_cache.dig(*cache_key) return tag.html_safe if tag # Layer 2: File-based cache (persistent) tag = Cache.fetch(symbol, ) do icon = FluentIcons::Fluent.new(symbol, ) icon.to_svg end # Store in memory cache for this request fluent_helper_cache[cache_key] = tag if tag tag.html_safe end |