Module: NeonSakura::ThemeHelper

Included in:
StyleGuideController
Defined in:
lib/neon_sakura/theme_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_themes_jsonObject

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_themeObject

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 = cookies[:theme_name] || session[:theme_name]
  theme_mode = cookies[: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

Parameters:

  • name (String)

    The icon name (without underscore prefix)

  • options (Hash) (defaults to: {})

    Options for the icon

Returns:

  • (String)

    Rendered icon partial



55
56
57
58
59
60
61
# File 'lib/neon_sakura/theme_helper.rb', line 55

def render_theme_icon(name, options = {})
  # Set default CSS class if not provided
  options[:css_class] ||= "w-4 h-4"

  # Pass all options to the partial as local_assigns
  render "shared/icons/#{name}", options
end

#theme_countObject

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_attributesObject

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_modeObject

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