ultra_settings 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03ea6a74f391d7955bf6091ed6573e306d49120a01652740fb3c279297bac1c1
4
- data.tar.gz: bda3d1a00eee06b8e2d306862134010461c3703a841d44cfcc0df782a9174e7a
3
+ metadata.gz: 5d1abe56c058f7f49b6779f96ff26d30d1ee3e5999bf87c968ad33e8facc6373
4
+ data.tar.gz: 6874bafd6563bc37df15cfa4fb14119a8ad4ec4b82e70360701939942079c2a3
5
5
  SHA512:
6
- metadata.gz: 7adbf8dce11f66cee346f74bf74a58730c509163bc4cc5dddb574d73fb8668b29639d3af5a20c3a1612208fa209161b56cfee99231ad909fbb68e6b52d1e9c05
7
- data.tar.gz: 8d5b5e32d41b9a9b9aa79729e7b2f5e04ea8a00b4a5e65961ba4a4470d084d495fbb6f97e1862d2772ed75c58d33af2637488a283a2c52ac0d02b6453ef5cf41
6
+ metadata.gz: 0d06174f43873463ec1fa05d7289d4a32e404a9baaa582eac26c79182bfa530ebe9cf4852cf6835d09e4cf98a6b06a788c659d54b488198b0f2c5072e725b7a8
7
+ data.tar.gz: 7426f9c5ff9bfd7153a3d4d916bc45f6f10821b891c821371800449eeec29e0bce3b2bf9693f85b8a6c780a2fb6044fd5bfd66f003ffd77ef005c21dada4a3b9
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.1.2
8
+
9
+ ### Added
10
+
11
+ - Added `UltraSettings::ApplicationView` which can be used to embed the web UI application showing the configuration inside your own templates. So now you can more seamlessly integrate the settings UI into your own admin tools.
12
+
7
13
  ## 1.1.1
8
14
 
9
15
  ### Added
@@ -20,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
26
 
21
27
  - Revamped web UI that can now display setting values.
22
28
  - Added option to specify fields as a secret in the configuration to prevent exposing sensitive information in the web interface. By default all fields are considered secrets. This can be changed per configuration by setting the `fields_secret_by_default` property to `false`.
23
- - Added `UltraSettings::ConfigurationView` which can be used to embed the HTML table showing the configuration options and values other admin views. So now you can integrate the settings view into your own admin tools.
29
+ - Added `UltraSettings::ConfigurationView` which can be used to embed the HTML table showing the configuration options and values inside other admin views. So now you can more seamlessly integrate the settings view into your own admin tools.
24
30
  - Add `__to_hash__` method to `UltraSettings::Configuration` which can to serialize the current configuration values as a hash. This value can be used for comparing configuration between environments.
25
31
 
26
32
  ## 1.0.1
data/README.md CHANGED
@@ -348,15 +348,23 @@ end, at: "/ultra_settings"
348
348
 
349
349
  #### Embedding the Settings View in Admin Tools
350
350
 
351
- If you prefer to embed the settings view directly into your own admin tools or dashboard, you can use the `UltraSettings::ConfigurationView` class to render the settings interface within your existing views:
351
+ If you prefer to embed the settings view directly into your own admin tools or dashboard, you can use the `UltraSettings::ApplicationView` class to render the settings interface within your existing views:
352
352
 
353
353
  ```erb
354
- <h1>My Service Settings</h1>
354
+ <h1>Configuration</h1>
355
355
 
356
- <%= UltraSettings::ConfigurationView.new(MyServiceConfiguration.instance).render %>
356
+ <%= UltraSettings::ApplicationView.new.render(select_class: "form-select", table_class: "table table-striped") %>
357
357
  ```
358
358
 
359
- This approach allows for seamless integration of the settings UI into your application's admin interface, leveraging your existing authentication and authorization mechanisms. The settings are rendered in an HTML table which you can format with your own CSS.
359
+ This approach allows for seamless integration of the settings UI into your application's admin interface, leveraging your existing authentication and authorization mechanisms. The settings are rendered in an HTML table with navigation handled by an HTML select element. You can specify the CSS classes for these elements and use your own stylesheets to customize the appearance.
360
+
361
+ You can also embed the view for individual configurations within your own views using the `UltraSettings::ConfigurationView` class if you want more customization:
362
+
363
+ ```erb
364
+ <h1>My Service Settings</h1>
365
+
366
+ <%= UltraSettings::ConfigurationView.new(MyServiceConfiguration.instance).render(table_class: "table table-striped") %>
367
+ ```
360
368
 
361
369
  ### Testing With UltraSettings
362
370
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
data/app/index.html.erb CHANGED
@@ -1,8 +1,8 @@
1
1
  <div class="ultra-settings-nav">
2
2
  <form onsubmit="return false">
3
- <select class="ultra-settings-select" size="1" id="config-selector">
3
+ <select class="<%= html_escape(select_class) %>" size="1" id="config-selector">
4
4
  <% UltraSettings.__configuration_names__.sort.each do |name| %>
5
- <option value="config-<%= name %>"><%= name %></option>
5
+ <option value="config-<%= html_escape(name) %>"><%= html_escape(name) %></option>
6
6
  <% end %>
7
7
  </select>
8
8
  </form>
@@ -11,11 +11,11 @@
11
11
  <% UltraSettings.__configuration_names__.sort.each do |name| %>
12
12
  <% configuration = UltraSettings.send(name) %>
13
13
 
14
- <div class="ultra-settings-configuration" id="config-<%= name %>" style="display:none;">
15
- <%= UltraSettings::ConfigurationView.new(configuration) %>
14
+ <div class="ultra-settings-configuration" id="config-<%= html_escape(name) %>" style="display:none;">
15
+ <%= UltraSettings::ConfigurationView.new(configuration).render(table_class: table_class) %>
16
16
  </div>
17
17
  <% end %>
18
18
 
19
19
  <script>
20
- <%= @javascript %>
20
+ <%= javascript %>
21
21
  </script>
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UltraSettings
4
+ # This class can render information about all configurations. It is used by the bundled
5
+ # web UI, but you can use it to embed the configuration information in your own web pages.
6
+ #
7
+ # The output will be a simple HTML drop down list that can be used to display an HTML table
8
+ # showing each configuration. You can specify the CSS class for the select element and the tables
9
+ # by passing the `select_class` and `table_class` option to the `render` method. By default the
10
+ # select elewment have the class `ultra-settings-select` and the table will have the class
11
+ # `ultra-settings-table`.
12
+ #
13
+ # @example
14
+ # <h1>Application Configuration</h1>
15
+ # <%= UltraSettings::ApplicationView.new.render(select_class: 'form-control', table_class: "table table-striped") %>
16
+ class ApplicationView
17
+ @template = nil
18
+
19
+ class << self
20
+ def template
21
+ @template ||= ERB.new(read_app_file("index.html.erb"))
22
+ end
23
+
24
+ def javascript
25
+ @javascript = read_app_file("application.js")
26
+ end
27
+
28
+ private
29
+
30
+ def read_app_file(path)
31
+ File.read(File.join(app_dir, path))
32
+ end
33
+
34
+ def app_dir
35
+ File.expand_path(File.join("..", "..", "app"), __dir__)
36
+ end
37
+ end
38
+
39
+ def render(select_class: "ultra-settings-select", table_class: "ultra-settings-table")
40
+ html = self.class.template.result(binding)
41
+ html = html.html_safe if html.respond_to?(:html_safe)
42
+ html
43
+ end
44
+
45
+ def to_s
46
+ render
47
+ end
48
+
49
+ private
50
+
51
+ def html_escape(value)
52
+ ERB::Util.html_escape(value)
53
+ end
54
+
55
+ def javascript
56
+ self.class.javascript
57
+ end
58
+ end
59
+ end
@@ -6,11 +6,9 @@ module UltraSettings
6
6
  attr_reader :css
7
7
 
8
8
  def initialize
9
- @index_template = erb_template("index.html.erb")
10
9
  @layout_template = erb_template("layout.html.erb")
11
10
  @layout_css = read_app_file("layout.css")
12
11
  @css = read_app_file("application.css")
13
- @javascript = read_app_file("application.js")
14
12
  end
15
13
 
16
14
  def render_settings
@@ -18,7 +16,7 @@ module UltraSettings
18
16
  end
19
17
 
20
18
  def content
21
- @index_template.result(binding)
19
+ UltraSettings::ApplicationView.new.render
22
20
  end
23
21
 
24
22
  private
@@ -12,6 +12,7 @@ require_relative "ultra_settings/coerce"
12
12
  require_relative "ultra_settings/field"
13
13
  require_relative "ultra_settings/rack_app"
14
14
  require_relative "ultra_settings/web_view"
15
+ require_relative "ultra_settings/application_view"
15
16
  require_relative "ultra_settings/configuration_view"
16
17
  require_relative "ultra_settings/yaml_config"
17
18
  require_relative "ultra_settings/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -42,6 +42,7 @@ files:
42
42
  - app/layout.css
43
43
  - app/layout.html.erb
44
44
  - lib/ultra_settings.rb
45
+ - lib/ultra_settings/application_view.rb
45
46
  - lib/ultra_settings/coerce.rb
46
47
  - lib/ultra_settings/configuration.rb
47
48
  - lib/ultra_settings/configuration_view.rb