Module: NeonSakura::IconHelper
- Included in:
- StyleGuideController
- Defined in:
- lib/neon_sakura/icon_helper.rb
Instance Method Summary collapse
-
#available_icons ⇒ Array<String>
Get a list of all available icons.
-
#icon_exists?(name) ⇒ Boolean
Check if an icon exists.
-
#render_icon(name, options = {}) ⇒ String
Renders an icon partial with the given options All other options are passed through to the icon partial as local_assigns.
-
#render_icon_list(icon_names, options = {}) ⇒ String
Renders a list of icons with consistent styling.
-
#render_login_logo(options = {}) ⇒ String?
Renders the configured login logo from NeonSakura configuration Falls back to app icon if no login logo is configured.
Instance Method Details
#available_icons ⇒ Array<String>
Get a list of all available icons
23 24 25 26 27 28 29 30 |
# File 'lib/neon_sakura/icon_helper.rb', line 23 def available_icons # Use gem's icon directory when running within the gem, otherwise use app's directory root_path = defined?(NeonSakura::Engine) ? NeonSakura::Engine.root : Rails.root icon_files = Dir.glob(File.join(root_path, "app", "views", "shared", "icons", "_*.html.erb")) icon_files.map do |file| File.basename(file, ".html.erb").gsub(/^_/, "") end.sort end |
#icon_exists?(name) ⇒ Boolean
Check if an icon exists
35 36 37 38 39 |
# File 'lib/neon_sakura/icon_helper.rb', line 35 def icon_exists?(name) # Use gem's icon directory when running within the gem, otherwise use app's directory root_path = defined?(NeonSakura::Engine) ? NeonSakura::Engine.root : Rails.root File.exist?(File.join(root_path, "app", "views", "shared", "icons", "_#{name}.html.erb")) end |
#render_icon(name, options = {}) ⇒ String
Renders an icon partial with the given options All other options are passed through to the icon partial as local_assigns
13 14 15 16 17 18 19 |
# File 'lib/neon_sakura/icon_helper.rb', line 13 def render_icon(name, = {}) # Set default CSS class if not provided [:css_class] ||= "w-4 h-4" # Pass all options to the partial as local_assigns render "shared/icons/#{name}", end |
#render_icon_list(icon_names, options = {}) ⇒ String
Renders a list of icons with consistent styling
45 46 47 48 49 50 51 52 |
# File 'lib/neon_sakura/icon_helper.rb', line 45 def render_icon_list(icon_names, = {}) css_class = [:css_class] || "flex items-center gap-2" icons_html = icon_names.map do |icon_name| render_icon(icon_name, .merge(css_class: [:icon_css_class])) end.join("\n") "<div class=\"#{css_class}\">#{icons_html}</div>".html_safe end |
#render_login_logo(options = {}) ⇒ String?
Renders the configured login logo from NeonSakura configuration Falls back to app icon if no login logo is configured
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/neon_sakura/icon_helper.rb', line 61 def render_login_logo( = {}) config = NeonSakura.config.login_logo || {} # Determine which icon to use icon_name = [:icon] || config[:icon] || NeonSakura.config.app_icon # Return nil if no icon is configured return nil if icon_name.blank? # Build render options = { css_class: [:css_class] || config[:css_class] || "w-12 h-12 sm:w-16 sm:h-16", gradient_id: [:gradient_id] || config[:gradient_id] }.compact # Render the icon using render_theme_icon (which supports gradient_id) render_theme_icon(icon_name, ) end |