Class: UltraSettings::WebView
- Inherits:
-
Object
- Object
- UltraSettings::WebView
- Includes:
- RenderHelper
- Defined in:
- lib/ultra_settings/web_view.rb
Overview
Helper class for rendering the settings information in an HTML page.
Instance Attribute Summary collapse
-
#layout_css ⇒ Object
readonly
Returns the value of attribute layout_css.
Instance Method Summary collapse
-
#content ⇒ String
Get the content for the settings page.
-
#initialize(color_scheme: :light) ⇒ WebView
constructor
Initialize a new WebView with the specified color scheme.
-
#render_layout ⇒ String
private
Render the layout template in the context of this instance.
-
#render_settings(request = nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ String
Render the complete settings page HTML.
-
#t(key) ⇒ String
Look up a translation key for the current locale.
-
#text_direction ⇒ String
Return the text direction (+"ltr"+ or
"rtl") for the current locale.
Methods included from RenderHelper
Constructor Details
#initialize(color_scheme: :light) ⇒ WebView
Initialize a new WebView with the specified color scheme.
15 16 17 18 19 20 21 |
# File 'lib/ultra_settings/web_view.rb', line 15 def initialize(color_scheme: :light) @color_scheme = color_scheme&.to_sym @dark_mode_selector = @color_scheme.nil? ? "[data-theme=dark]" : nil @layout_template = ViewHelper.erb_template("layout.html.erb") @layout_css = scheme_layout_css(@color_scheme, @dark_mode_selector) @locale = nil end |
Instance Attribute Details
#layout_css ⇒ Object (readonly)
Returns the value of attribute layout_css.
8 9 10 |
# File 'lib/ultra_settings/web_view.rb', line 8 def layout_css @layout_css end |
Instance Method Details
#content ⇒ String
Get the content for the settings page.
50 51 52 53 54 55 56 |
# File 'lib/ultra_settings/web_view.rb', line 50 def content UltraSettings::ApplicationView.new( color_scheme: @color_scheme || :light, dark_mode_selector: @dark_mode_selector, locale: @locale || UltraSettings::MiniI18n::DEFAULT_LOCALE ).render end |
#render_layout ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render the layout template in the context of this instance.
43 44 45 |
# File 'lib/ultra_settings/web_view.rb', line 43 def render_layout @layout_template.result(binding) end |
#render_settings(request = nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ String
Render the complete settings page HTML.
This instance may be shared between concurrent requests, so per-request state is set on a copy of the view rather than on the shared instance.
33 34 35 36 37 |
# File 'lib/ultra_settings/web_view.rb', line 33 def render_settings(request = nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) renderer = dup renderer.instance_variable_set(:@locale, locale) renderer.render_layout end |
#t(key) ⇒ String
Look up a translation key for the current locale.
62 63 64 |
# File 'lib/ultra_settings/web_view.rb', line 62 def t(key) UltraSettings::MiniI18n.t(key, locale: @locale || UltraSettings::MiniI18n::DEFAULT_LOCALE) end |
#text_direction ⇒ String
Return the text direction (+"ltr"+ or "rtl") for the current locale.
69 70 71 |
# File 'lib/ultra_settings/web_view.rb', line 69 def text_direction UltraSettings::MiniI18n.text_direction(@locale || UltraSettings::MiniI18n::DEFAULT_LOCALE) end |