Class: UltraSettings::ApplicationView
- Inherits:
-
Object
- Object
- UltraSettings::ApplicationView
- Includes:
- RenderHelper
- Defined in:
- lib/ultra_settings/application_view.rb
Overview
This class can render information about all configurations. It is used by the bundled web UI, but you can use it to embed the configuration information in your own web pages.
The output will be a simple HTML drop down menu that can be used to select the configuration you want to see.
Instance Attribute Summary collapse
-
#css ⇒ Object
readonly
Returns the value of attribute css.
Instance Method Summary collapse
-
#initialize(color_scheme: :light, dark_mode_selector: nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ ApplicationView
constructor
Initialize the application view with a color scheme.
-
#render(select_class: nil, table_class: nil) ⇒ String
Render the HTML for the configuration settings UI.
-
#style_tag ⇒ String
Generate an HTML style tag with the CSS for the view.
-
#to_s ⇒ String
Convert the view to a string by rendering it.
Methods included from RenderHelper
Constructor Details
#initialize(color_scheme: :light, dark_mode_selector: nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ ApplicationView
Initialize the application view with a color scheme.
23 24 25 26 27 |
# File 'lib/ultra_settings/application_view.rb', line 23 def initialize(color_scheme: :light, dark_mode_selector: nil, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) @css = application_css(color_scheme, dark_mode_selector) @css = @css.html_safe if @css.respond_to?(:html_safe) @locale = locale end |
Instance Attribute Details
#css ⇒ Object (readonly)
Returns the value of attribute css.
16 17 18 |
# File 'lib/ultra_settings/application_view.rb', line 16 def css @css end |
Instance Method Details
#render(select_class: nil, table_class: nil) ⇒ String
Render the HTML for the configuration settings UI.
The runtime settings cache is reloaded before rendering so that values changed from the UI are displayed immediately rather than after the runtime settings engine next refreshes itself.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ultra_settings/application_view.rb', line 38 def render(select_class: nil, table_class: nil) UltraSettings.with_runtime_settings_reloaded do # Expose locale as a local for the ERB template without a direct # assignment, which would emit an unused variable warning under ruby -w. template_binding = binding template_binding.local_variable_set(:locale, @locale) html = ViewHelper.erb_template("index.html.erb").result(template_binding) html = html.html_safe if html.respond_to?(:html_safe) html end end |
#style_tag ⇒ String
Generate an HTML style tag with the CSS for the view.
53 54 55 56 57 |
# File 'lib/ultra_settings/application_view.rb', line 53 def style_tag tag = "<style type=\"text/css\">\n#{css}\n</style>" tag = tag.html_safe if tag.respond_to?(:html_safe) tag end |
#to_s ⇒ String
Convert the view to a string by rendering it.
62 63 64 |
# File 'lib/ultra_settings/application_view.rb', line 62 def to_s render end |