Module: TailwindThemePicker::ViewHelper
- Defined in:
- app/helpers/tailwind_theme_picker/view_helper.rb
Constant Summary collapse
- DEFAULT_ICONS =
Emoji defaults so the gem has no icon-library dependency. Override by passing :icons to render_tailwind_theme_picker.
{ palette: "🎨", times: "❌", sun: "☀️", moon: "🌙" }.freeze
Instance Method Summary collapse
- #render_tailwind_theme_picker(themes: nil, default: nil, icons: {}) ⇒ Object
-
#tailwind_theme_picker_cookies_present? ⇒ Boolean
Whether the current request already has theme cookies set.
-
#tailwind_theme_picker_fouc_script(force: false) ⇒ Object
Inline
56 57 58 59 60 61 62 63 64 65 66 67 68 69
# File 'app/helpers/tailwind_theme_picker/view_helper.rb', line 56 def render_tailwind_theme_picker(themes: nil, default: nil, icons: {}) config = TailwindThemePicker.configuration render( partial: "tailwind_theme_picker/picker", locals: { themes: (themes || config.themes).map(&:to_s), default: (default || config.default).to_s, theme_cookie: config., mode_cookie: config., cookie_max_age: config., icons: DEFAULT_ICONS.merge(icons) } ) end
#tailwind_theme_picker_cookies_present? ⇒ Boolean
Whether the current request already has theme cookies set. Useful for skipping the FOUC fallback script.
28 29 30 31
# File 'app/helpers/tailwind_theme_picker/view_helper.rb', line 28 def config = TailwindThemePicker.configuration [config.].present? && [config.].present? end
#tailwind_theme_picker_fouc_script(force: false) ⇒ Object
Inline
Returns HTML attributes for the tag based on the request's cookies. Use like: html lang="en" *tailwind_theme_picker_html_attrs
16 17 18 19 20 21 22 23 24
# File 'app/helpers/tailwind_theme_picker/view_helper.rb', line 16 def tailwind_theme_picker_html_attrs config = TailwindThemePicker.configuration theme = [config.].presence theme = config.default unless config.themes.include?(theme) mode = [config.] == "dark" ? "dark" : nil classes = ["theme-#{theme}", mode].compact.join(" ") { class: classes } end