Module: NeonSakura::ThemeHelper
- Included in:
- StyleGuideController
- Defined in:
- lib/neon_sakura/theme_helper.rb
Instance Method Summary collapse
-
#available_themes_json ⇒ Object
Returns available themes as JSON for JavaScript.
-
#current_theme ⇒ Object
Returns the current theme as a hash with :name and :mode keys Priority: session/cookies (from JS localStorage) -> default_theme from config.
-
#render_theme_icon(name, options = {}) ⇒ String
Renders an icon partial for the current theme All options are passed through to the icon partial as local_assigns.
-
#theme_count ⇒ Object
Returns the number of available themes.
-
#theme_data_attributes ⇒ Object
Returns HTML data attributes for the current theme Usage: <html <%= theme_data_attributes %>>.
-
#theme_switcher_mode ⇒ Object
Helper to determine theme switcher mode Returns: :disabled (1 theme), :toggle (2 themes), :dropdown (3+ themes).
Instance Method Details
#available_themes_json ⇒ Object
Returns available themes as JSON for JavaScript
28 29 30 |
# File 'lib/neon_sakura/theme_helper.rb', line 28 def available_themes_json NeonSakura.config.available_themes.to_json.html_safe end |
#current_theme ⇒ Object
Returns the current theme as a hash with :name and :mode keys Priority: session/cookies (from JS localStorage) -> default_theme from config
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/neon_sakura/theme_helper.rb', line 7 def current_theme # Try to get theme from session (set by JavaScript via cookie) theme_name = [:theme_name] || session[:theme_name] theme_mode = [:theme_mode] || session[:theme_mode] if theme_name && theme_mode { name: theme_name.to_s, mode: theme_mode.to_s } else # Fall back to default theme from configuration NeonSakura.config.default_theme end end |
#render_theme_icon(name, options = {}) ⇒ String
Renders an icon partial for the current theme All options are passed through to the icon partial as local_assigns
55 56 57 58 59 60 61 |
# File 'lib/neon_sakura/theme_helper.rb', line 55 def render_theme_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 |
#theme_count ⇒ Object
Returns the number of available themes
33 34 35 |
# File 'lib/neon_sakura/theme_helper.rb', line 33 def theme_count NeonSakura.config.available_themes.length end |
#theme_data_attributes ⇒ Object
Returns HTML data attributes for the current theme Usage: <html <%= theme_data_attributes %>>
22 23 24 25 |
# File 'lib/neon_sakura/theme_helper.rb', line 22 def theme_data_attributes theme = current_theme "data-theme-name='#{theme[:name]}' data-theme-mode='#{theme[:mode]}'".html_safe end |
#theme_switcher_mode ⇒ Object
Helper to determine theme switcher mode Returns: :disabled (1 theme), :toggle (2 themes), :dropdown (3+ themes)
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/neon_sakura/theme_helper.rb', line 39 def theme_switcher_mode case theme_count when 0, 1 :disabled when 2 :toggle else :dropdown end end |