Class: UltraSettings::ApplicationView

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

Examples:

<h1>Application Configuration</h1>
<%= UltraSettings::ApplicationView.new.render %>

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RenderHelper

#html_escape, #render_partial

Constructor Details

#initialize(color_scheme: :light) ⇒ ApplicationView

Initialize the application view with a color scheme.

Parameters:

  • color_scheme (Symbol) (defaults to: :light)

    The color scheme to use (:light, :dark, or :system).



21
22
23
24
# File 'lib/ultra_settings/application_view.rb', line 21

def initialize(color_scheme: :light)
  @css = application_css(color_scheme)
  @css = @css.html_safe if @css.respond_to?(:html_safe)
end

Instance Attribute Details

#cssObject (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.

Parameters:

  • select_class (String) (defaults to: nil)

    Deprecated; no longer used.

  • table_class (String) (defaults to: nil)

    Deprecated; no longer used.

Returns:

  • (String)

    The rendered HTML.



31
32
33
34
35
# File 'lib/ultra_settings/application_view.rb', line 31

def render(select_class: nil, table_class: nil)
  html = ViewHelper.erb_template("index.html.erb").result(binding)
  html = html.html_safe if html.respond_to?(:html_safe)
  html
end

#style_tagString

Generate an HTML style tag with the CSS for the view.

Returns:

  • (String)

    The HTML style tag with CSS.



40
41
42
43
44
# File 'lib/ultra_settings/application_view.rb', line 40

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_sString

Convert the view to a string by rendering it.

Returns:

  • (String)

    The rendered HTML.



49
50
51
# File 'lib/ultra_settings/application_view.rb', line 49

def to_s
  render
end