Class: SuperSettings::Configuration::Controller
- Inherits:
-
Object
- Object
- SuperSettings::Configuration::Controller
- Defined in:
- lib/super_settings/configuration.rb
Overview
Configuration for the controller.
Constant Summary collapse
- VALID_COLOR_SCHEMES =
[:light, :dark, :system].freeze
Instance Attribute Summary collapse
-
#application_link ⇒ Object
Optional URL for a link back to the rest of the application.
-
#application_logo ⇒ Object
Optional image URL for the application logo.
-
#application_name ⇒ Object
Optional name of the application displayed in the view.
-
#color_scheme ⇒ Symbol?
Return the configured color scheme.
-
#dark_mode_selector ⇒ Object
Set a CSS selector that sets dark mode.
- #enhancement ⇒ Object readonly private
- #superclass ⇒ Object
-
#web_ui_enabled ⇒ Object
writeonly
Enable or disable the web UI (the REST API will always be enabled).
Instance Method Summary collapse
-
#authentication_url=(value) ⇒ Object
Optional URL for a link to the login page for the application.
-
#changed_by(controller) ⇒ Object
private
Return the value of
define_changed_byblock. -
#define_changed_by { ... } ⇒ Object
Define how the
changed_byattibute on the setting history will be filled from the controller. -
#enhance { ... } ⇒ Object
Enhance the controller.
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
-
#resolved_dark_mode_selector ⇒ String?
Return the selector used to enable dark mode from host page state.
- #web_ui_enabled? ⇒ Boolean
-
#web_ui_javascript=(script) ⇒ Object
Javascript to inject into the settings application HTML page.
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/super_settings/configuration.rb', line 27 def initialize @superclass = nil @web_ui_enabled = true @color_scheme = nil @changed_by_block = nil @enhancement = nil @application_name = nil @application_logo = nil @application_link = nil @dark_mode_selector = nil end |
Instance Attribute Details
#application_link ⇒ Object
Optional URL for a link back to the rest of the application.
54 55 56 |
# File 'lib/super_settings/configuration.rb', line 54 def application_link @application_link end |
#application_logo ⇒ Object
Optional image URL for the application logo.
51 52 53 |
# File 'lib/super_settings/configuration.rb', line 51 def application_logo @application_logo end |
#application_name ⇒ Object
Optional name of the application displayed in the view.
48 49 50 |
# File 'lib/super_settings/configuration.rb', line 48 def application_name @application_name end |
#color_scheme ⇒ Symbol?
Return the configured color scheme.
81 82 83 84 |
# File 'lib/super_settings/configuration.rb', line 81 def color_scheme scheme = @color_scheme&.to_sym VALID_COLOR_SCHEMES.include?(scheme) ? scheme : nil end |
#dark_mode_selector ⇒ Object
Set a CSS selector that sets dark mode. This is an alternative to using the color_scheme option and can be used if you have a custom implementation for dark mode in your application. Dark mode will be enabled in the settings web UI when the selector matches an element in the page.
89 90 91 |
# File 'lib/super_settings/configuration.rb', line 89 def dark_mode_selector @dark_mode_selector end |
#enhancement ⇒ Object (readonly)
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.
18 19 20 |
# File 'lib/super_settings/configuration.rb', line 18 def enhancement @enhancement end |
#superclass ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/super_settings/configuration.rb', line 39 def superclass if @superclass.is_a?(String) @superclass.constantize else @superclass end end |
#web_ui_enabled=(value) ⇒ Object (writeonly)
Enable or disable the web UI (the REST API will always be enabled).
68 69 70 |
# File 'lib/super_settings/configuration.rb', line 68 def web_ui_enabled=(value) @web_ui_enabled = value end |
Instance Method Details
#authentication_url=(value) ⇒ Object
Optional URL for a link to the login page for the application.
57 58 59 |
# File 'lib/super_settings/configuration.rb', line 57 def authentication_url=(value) SuperSettings.authentication_url = value end |
#changed_by(controller) ⇒ Object
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.
Return the value of define_changed_by block.
127 128 129 130 131 |
# File 'lib/super_settings/configuration.rb', line 127 def changed_by(controller) if @changed_by_block controller.instance_eval(&@changed_by_block) end end |
#define_changed_by { ... } ⇒ Object
Define how the changed_by attibute on the setting history will be filled from the controller.
The block will be evaluated in the context of the controller when the settings are changed.
The value returned by the block will be stored in the changed_by attribute. For example, if
your base controller class defines a method current_user and you'd like the name to be stored
in the history, you could call
120 121 122 |
# File 'lib/super_settings/configuration.rb', line 120 def define_changed_by(&block) @changed_by_block = block end |
#enhance { ... } ⇒ Object
Enhance the controller. You can define methods or call controller class methods like
before_action, etc. in the block. These will be applied to the engine controller.
This is essentially the same a monkeypatching the controller class.
106 107 108 |
# File 'lib/super_settings/configuration.rb', line 106 def enhance(&block) @enhancement = block end |
#resolved_dark_mode_selector ⇒ String?
Return the selector used to enable dark mode from host page state.
94 95 96 97 98 99 |
# File 'lib/super_settings/configuration.rb', line 94 def resolved_dark_mode_selector return @dark_mode_selector if @dark_mode_selector return "[data-theme=dark]" if color_scheme.nil? nil end |
#web_ui_enabled? ⇒ Boolean
70 71 72 |
# File 'lib/super_settings/configuration.rb', line 70 def web_ui_enabled? !!@web_ui_enabled end |
#web_ui_javascript=(script) ⇒ Object
Javascript to inject into the settings application HTML page. This can be used, for example, to set authorization credentials stored client side to access the settings API.
63 64 65 |
# File 'lib/super_settings/configuration.rb', line 63 def web_ui_javascript=(script) SuperSettings.web_ui_javascript = script end |