lato_settings 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f13fef2e4c2fd7f13af8b268f8d4cf7dc61bf61224fbd30f2453ea735e7a2df
4
- data.tar.gz: 7183ed20e93e11bb9f9306e7f80017a38831f08d9c4042c0da43ccec3077804c
3
+ metadata.gz: f7846bd6973838754257a88b5bf060b39a4d0935cbaa7aff241b4c168da26471
4
+ data.tar.gz: d2edd11c94389baf016177ef70abddb461995d0f68741a5bcc11a664b27cf61a
5
5
  SHA512:
6
- metadata.gz: f1714c04b34ef6b7d7aa7687e0c55e045a6c3cf7a1a868fc319eb05eaf5ea40afd22ee248e0861299604032742767fece921d06f6237da9993063ae3a3a3366b
7
- data.tar.gz: 4f36b0730a7e2ec348fa9d840b18751a821924f2ebe616e3571bfeceefd8d64d5b006ab6a510d03d53576de44df029dceaafa7f2f8c78c2db8c651f709dc9900
6
+ metadata.gz: a1c19bd6a38bf6fa666bd4910a555676740e672e60cf1894f7db72686fa448689b56ca6580ad5f328488d41e7289d0dfe204e4708a5b724588ecc20233ea463c
7
+ data.tar.gz: cb84a9f9e4801a48db34e65f1935388817276e5f7a3f228272cbc785da83a5af5256055ff41b9e23c1540d19d244bdb1477bcab48afd84063e5db799d526096b
@@ -3,7 +3,7 @@ module LatoSettings
3
3
  def index
4
4
  @settings = lato_index_collection(
5
5
  Setting.all,
6
- columns: %i[key label value updated_at actions],
6
+ columns: %i[label value key updated_at actions],
7
7
  searchable_columns: %i[key label value],
8
8
  sortable_columns: %i[updated_at],
9
9
  pagination: true,
@@ -1,9 +1,11 @@
1
1
  module LatoSettings
2
2
  module SettingsHelper
3
3
  def lato_settings_setting_key(setting)
4
- content_tag(:span, class: 'font-monospace') do
5
- setting.key
6
- end
4
+ print_content(setting, setting.key, :key)
5
+ end
6
+
7
+ def lato_settings_setting_value(setting)
8
+ print_content(setting, setting.value_formatted, :value)
7
9
  end
8
10
 
9
11
  def lato_settings_setting_label(setting)
@@ -24,9 +26,20 @@ module LatoSettings
24
26
  concat link_to(I18n.t('lato_settings.cta_edit'), lato_settings.edit_setting_path(setting), class: 'btn btn-primary', data: { lato_action_target: 'trigger', turbo_frame: dom_id(setting, 'form'), action_title: I18n.t('lato_settings.edit_setting') })
25
27
 
26
28
  unless setting.required
27
- concat link_to(I18n.t('lato_settings.cta_delete'), lato_settings.setting_path(setting), class: 'btn btn-danger', data: { turbo_confirm: 'Are you sure?', turbo_method: :delete })
29
+ concat link_to(I18n.t('lato_settings.cta_delete'), lato_settings.setting_path(setting), class: 'btn btn-danger', data: { turbo_confirm: I18n.t('lato_settings.cta_delete_confirm'), turbo_method: :delete })
28
30
  end
29
31
  end
30
32
  end
33
+
34
+ def print_content(setting, content, type)
35
+ raw "
36
+ <div class=\"input-group input-group-sm\" data-controller=\"lato-copyclip\">
37
+ <input type=\"text\" class=\"form-control\" placeholder=\"#{setting.label || setting.key}\" aria-label=\"#{setting.label || setting.key}\" aria-describedby=\"#{type}_#{setting.id}\" value=\"#{content}\" data-lato-copyclip-target=\"input\" readonly>
38
+ <button class=\"btn btn-primary\" type=\"button\" id=\"#{type}_#{setting.id}\" data-lato-copyclip-target=\"button\" data-action=\"lato-copyclip#onButtonClick\" title=\"#{I18n.t('lato_settings.cta_copy')}\" aria-label=\"#{I18n.t('lato_settings.cta_copy')}\" data-copy-text=\"<i class='bi bi-clipboard-check'></i>\">
39
+ <i class=\"bi bi-clipboard\"></i>
40
+ </button>
41
+ </div>
42
+ "
43
+ end
31
44
  end
32
45
  end
@@ -7,6 +7,7 @@ module LatoSettings
7
7
  number: 1,
8
8
  date: 2,
9
9
  select: 3,
10
+ integer: 4,
10
11
  }, prefix: true
11
12
 
12
13
  validates :key, presence: true, uniqueness: true, format: { with: /\A[a-zA-Z0-9_]+\z/ }
@@ -36,6 +37,25 @@ module LatoSettings
36
37
  # Helpers
37
38
  ##
38
39
 
40
+ def value_formatted
41
+ return nil if value.nil?
42
+
43
+ case typology
44
+ when 'string'
45
+ value.to_s
46
+ when 'number'
47
+ value.to_f
48
+ when 'date'
49
+ Date.parse(value)
50
+ when 'select'
51
+ option_values.include?(value) ? value : nil
52
+ when 'integer'
53
+ value.to_i
54
+ else
55
+ value.to_s
56
+ end
57
+ end
58
+
39
59
  def option_min
40
60
  options&.dig('min') || nil
41
61
  end
@@ -55,13 +75,15 @@ module LatoSettings
55
75
  # Class
56
76
  ##
57
77
 
78
+ # DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS
58
79
  def self.get(key, default = nil)
59
- Rails.logger.warn "LatoSettings.get is deprecated. Use LatoSettings.get instead."
80
+ Rails.logger.warn "LatoSettings::Setting.get is deprecated. Use LatoSettings.get instead."
60
81
  LatoSettings.get(key, default)
61
82
  end
62
83
 
84
+ # DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS
63
85
  def self.load_cache
64
- Rails.logger.warn "LatoSettings.load_cache is deprecated. Use LatoSettings.reset_cache instead."
86
+ Rails.logger.warn "LatoSettings::Setting.load_cache is deprecated. Use LatoSettings.reset_cache instead."
65
87
  LatoSettings.reset_cache
66
88
  end
67
89
  end
@@ -29,6 +29,11 @@ setting ||= LatoSettings::Setting.new
29
29
  <%= lato_form_item_label form, :value %>
30
30
  <%= lato_form_item_input_number form, :value, required: true, min: setting.option_min, max: setting.option_max, step: setting.option_step %>
31
31
  </div>
32
+ <% elsif setting.typology == 'integer' %>
33
+ <div class="mb-3">
34
+ <%= lato_form_item_label form, :value %>
35
+ <%= lato_form_item_input_number form, :value, required: true, min: setting.option_min, max: setting.option_max, step: 1 %>
36
+ </div>
32
37
  <% elsif setting.typology == 'date' %>
33
38
  <div class="mb-3">
34
39
  <%= lato_form_item_label form, :value %>
@@ -6,4 +6,6 @@ en:
6
6
  cta_edit: Edit
7
7
  cta_update: Update
8
8
  cta_delete: Delete
9
- cta_confirm: Confirm
9
+ cta_confirm: Confirm
10
+ cta_copy: Copy
11
+ cta_delete_confirm: Are you sure you want to delete this setting?
@@ -7,6 +7,8 @@ it:
7
7
  cta_update: Aggiorna
8
8
  cta_delete: Cancella
9
9
  cta_confirm: Conferma
10
+ cta_copy: Copia
11
+ cta_delete_confirm: Sei sicuro di voler cancellare questa impostazione?
10
12
  activerecord:
11
13
  attributes:
12
14
  lato_settings/setting:
@@ -1,3 +1,3 @@
1
1
  module LatoSettings
2
- VERSION = "3.0.3"
2
+ VERSION = "3.0.4"
3
3
  end
data/lib/lato_settings.rb CHANGED
@@ -24,8 +24,7 @@ module LatoSettings
24
24
  @cache = Rails.cache.fetch('LatoSettings/cache') do
25
25
  cache = {}
26
26
  LatoSettings::Setting.all.select(:key, :value, :typology).each do |setting|
27
- cache[setting.key] = setting.value
28
- cache[setting.key] = setting.value.to_f if setting.typology_number?
27
+ cache[setting.key] = setting.value_formatted
29
28
  end
30
29
 
31
30
  cache
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-15 00:00:00.000000000 Z
11
+ date: 2025-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails