Class: UltraSettings::ConfigurationView

Inherits:
Object
  • Object
show all
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.

Examples:

<h1>Service Configuration</h1>
<%= UltraSettings::ConfigurationView.new(ServiceConfiguration.instance).render %>

Instance Method Summary collapse

Methods included from RenderHelper

#html_escape, #render_partial

Constructor Details

#initialize(configuration, locale: UltraSettings::MiniI18n::DEFAULT_LOCALE) ⇒ ConfigurationView

Initialize the configuration view with a configuration instance.

Parameters:

  • configuration (UltraSettings::Configuration)

    The configuration instance to display.

  • locale (String) (defaults to: UltraSettings::MiniI18n::DEFAULT_LOCALE)

    The locale code for translations.



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.

Parameters:

  • table_class (String) (defaults to: "")

    @deprecated CSS class for the table element (maintained for backwards compatibility).

Returns:

  • (String)

    The rendered HTML.



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_sString

Convert the view to a string by rendering it.

Returns:

  • (String)

    The rendered HTML.



50
51
52
# File 'lib/ultra_settings/configuration_view.rb', line 50

def to_s
  render
end