FEATURE: introduces list/compact_list components

This commit is contained in:
Joffrey JAFFEUX
2018-08-03 16:41:37 -04:00
committed by GitHub
parent 072f5ce825
commit 066010db7d
20 changed files with 297 additions and 160 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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