mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: introduces list/compact_list components
This commit is contained in:
@@ -6,7 +6,7 @@ module SiteSettings; end
|
||||
class SiteSettings::TypeSupervisor
|
||||
include SiteSettings::Validations
|
||||
|
||||
CONSUMED_OPTS = %i[enum choices type validator min max regex hidden regex_error allow_any].freeze
|
||||
CONSUMED_OPTS = %i[enum choices type validator min max regex hidden regex_error allow_any list_type].freeze
|
||||
VALIDATOR_OPTS = %i[min max regex hidden regex_error].freeze
|
||||
|
||||
# For plugins, so they can tell if a feature is supported
|
||||
@@ -63,6 +63,7 @@ class SiteSettings::TypeSupervisor
|
||||
@validators = {}
|
||||
@types = {}
|
||||
@allow_any = {}
|
||||
@list_type = {}
|
||||
end
|
||||
|
||||
def load_setting(name_arg, opts = {})
|
||||
@@ -88,6 +89,7 @@ class SiteSettings::TypeSupervisor
|
||||
|
||||
if type.to_sym == :list
|
||||
@allow_any[name] = opts[:allow_any] == false ? false : true
|
||||
@list_type[name] = opts[:list_type] if opts[:list_type]
|
||||
end
|
||||
end
|
||||
@types[name] = get_data_type(name, @defaults_provider[name])
|
||||
@@ -144,6 +146,7 @@ class SiteSettings::TypeSupervisor
|
||||
end
|
||||
|
||||
result[:choices] = @choices[name] if @choices.has_key? name
|
||||
result[:list_type] = @list_type[name] if @list_type.has_key? name
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
@@ -93,8 +93,13 @@ class ThemeSettingsManager
|
||||
(max.is_a?(::Integer) || max.is_a?(::Float)) && max != ::Float::INFINITY
|
||||
end
|
||||
|
||||
class List < self; end
|
||||
class String < self
|
||||
class List < self
|
||||
def list_type
|
||||
@opts[:list_type]
|
||||
end
|
||||
end
|
||||
|
||||
class String < self
|
||||
def is_valid_value?(new_value)
|
||||
(@opts[:min]..@opts[:max]).include? new_value.to_s.length
|
||||
end
|
||||
|
||||
@@ -33,6 +33,11 @@ class ThemeSettingsParser
|
||||
opts[:max] = raw_opts[:max].is_a?(Numeric) ? raw_opts[:max] : Float::INFINITY
|
||||
opts[:min] = raw_opts[:min].is_a?(Numeric) ? raw_opts[:min] : -Float::INFINITY
|
||||
end
|
||||
|
||||
if raw_opts[:list_type]
|
||||
opts[:list_type] = raw_opts[:list_type]
|
||||
end
|
||||
|
||||
opts
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user