Class: UltraSettings::ConfigurationView
- Inherits:
-
Object
- Object
- UltraSettings::ConfigurationView
- Includes:
- RenderHelper
- Defined in:
- lib/ultra_settings/configuration_view.rb
Overview
This class can render information about a configuration in a clean card-based layout. 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 HTML with a card-based layout for better readability. The table_class option is
still supported for backward compatibility but is no longer used in the new card layout.
Instance Method Summary collapse
-
#initialize(configuration, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ ConfigurationView
constructor
Initialize the configuration view with a configuration instance.
-
#render(table_class: "") ⇒ String
Render the HTML for the configuration view.
-
#to_s ⇒ String
Convert the view to a string by rendering it.
Methods included from RenderHelper
Constructor Details
#initialize(configuration, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ ConfigurationView
Initialize the configuration view with a configuration instance.
20 21 22 23 |
# File 'lib/ultra_settings/configuration_view.rb', line 20 def initialize(configuration, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) @configuration = configuration @locale = locale end |
Instance Method Details
#render(table_class: "") ⇒ String
Render the HTML for the configuration view.
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. If a page renders more than one view, wrap them all
in UltraSettings.with_runtime_settings_reloaded so that the settings are only
reloaded once for the page instead of once per view.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ultra_settings/configuration_view.rb', line 35 def render(table_class: "") UltraSettings.with_runtime_settings_reloaded do # Expose configuration 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(:configuration, @configuration) html = ViewHelper.erb_template("configuration.html.erb").result(template_binding) html = html.html_safe if html.respond_to?(:html_safe) html end end |
#to_s ⇒ String
Convert the view to a string by rendering it.
50 51 52 |
# File 'lib/ultra_settings/configuration_view.rb', line 50 def to_s render end |