ultra_settings 1.1.1 → 2.0.0

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: 0ff5c5961b5070a9234049d2588bd59150e82d2cf87b46c0686067c6d72dd815
4
+ data.tar.gz: 8df668372d8f6c7dd4c72ad55a789c8bd854bf0bfa0509a5e4a1da69bc74e93e
5
5
  SHA512:
6
- metadata.gz: 7adbf8dce11f66cee346f74bf74a58730c509163bc4cc5dddb574d73fb8668b29639d3af5a20c3a1612208fa209161b56cfee99231ad909fbb68e6b52d1e9c05
7
- data.tar.gz: 8d5b5e32d41b9a9b9aa79729e7b2f5e04ea8a00b4a5e65961ba4a4470d084d495fbb6f97e1862d2772ed75c58d33af2637488a283a2c52ac0d02b6453ef5cf41
6
+ metadata.gz: 7734298e87bd1fa4b7649ee5ddc64a0ef50f0e6e439bda7eb2042af055141ad5147ee07187ea53bbafbd5372430674a442f77e8c0277099cc8ff9ad7e1b20429
7
+ data.tar.gz: 565fc7f9071292490d41a634c1b0c89530cbc065f925d52c3dcc25d8e1009bf8fe45ed84aa809fe6ab150d20d79bd9f90f47524ee2a161dfc9d90fc60ae5fb65
data/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ 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
+ ## 2.0.0
8
+
9
+ ### Fixed
10
+
11
+ - **Breaking Change:** Fix conflict with overridding the standard `include?` method on configuration classes. These methods are now defined as `UltraSettings.added?` and `UltraSettings::Configuration.include_field?`.
12
+ - **Breaking Change:** Include namespace in autoloaded configuration names for Rails applications to avoid conflicts on classes in different namespaces.
13
+
14
+ ### Changed
15
+
16
+ - Use configuration class in in web UI dropdown menu.
17
+
18
+ ## 1.1.2
19
+
20
+ ### Added
21
+
22
+ - 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.
23
+
7
24
  ## 1.1.1
8
25
 
9
26
  ### Added
@@ -20,7 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
37
 
21
38
  - Revamped web UI that can now display setting values.
22
39
  - 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.
40
+ - 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
41
  - 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
42
 
26
43
  ## 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
+ 2.0.0
data/app/index.html.erb CHANGED
@@ -1,8 +1,8 @@
1
1
  <div class="ultra-settings-nav">
2
- <form onsubmit="return false">
3
- <select class="ultra-settings-select" size="1" id="config-selector">
2
+ <form onsubmit="return false" style="margin-bottom: 0.5rem;">
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(UltraSettings.send(name).class.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
@@ -86,12 +86,12 @@ module UltraSettings
86
86
  #
87
87
  # @param name [Symbol, String] The name of the field.
88
88
  # @return [Boolean]
89
- def include?(name)
89
+ def include_field?(name)
90
90
  name = name.to_s
91
91
  return true if defined_fields.include?(name)
92
92
 
93
93
  if superclass <= Configuration
94
- superclass.include?(name)
94
+ superclass.include_field?(name)
95
95
  else
96
96
  false
97
97
  end
@@ -446,7 +446,7 @@ module UltraSettings
446
446
  end
447
447
 
448
448
  def include?(name)
449
- self.class.include?(name.to_s)
449
+ self.class.include_field?(name.to_s)
450
450
  end
451
451
 
452
452
  def override!(values, &block)
@@ -23,9 +23,12 @@ module UltraSettings
23
23
 
24
24
  app_config_dir = Rails.root.join(directory)
25
25
  app_config_dir.glob("**/*_configuration.rb").each do |file_path|
26
- config_name = file_path.basename("_configuration.rb")
27
- class_name = file_path.relative_path_from(app_config_dir).to_s.chomp(".rb").classify
28
- UltraSettings.add(config_name, class_name)
26
+ relative_path = file_path.relative_path_from(app_config_dir).to_s
27
+ class_name = relative_path.chomp(".rb").classify
28
+ unless UltraSettings.added?(class_name)
29
+ config_name = class_name.delete_suffix("Configuration").underscore.tr("/", "_")
30
+ UltraSettings.add(config_name, class_name)
31
+ end
29
32
  end
30
33
  end
31
34
  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"
@@ -45,7 +46,7 @@ module UltraSettings
45
46
  def add(name, klass = nil)
46
47
  name = name.to_s
47
48
  unless name.match?(VALID_NAME__PATTERN)
48
- raise ArgementError.new("Invalid configuration name: #{name.inspect}")
49
+ raise ArgumentError.new("Invalid configuration name: #{name.inspect}")
49
50
  end
50
51
 
51
52
  class_name = klass&.to_s
@@ -66,7 +67,7 @@ module UltraSettings
66
67
  #
67
68
  # @param class_name [Class, String] The name of the configuration class.
68
69
  # @return [Boolean]
69
- def include?(class_name)
70
+ def added?(class_name)
70
71
  @configurations.values.collect(&:to_s).include?(class_name.to_s)
71
72
  end
72
73
 
metadata CHANGED
@@ -1,14 +1,14 @@
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: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-18 00:00:00.000000000 Z
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -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