DEV: Restore textarea type for site settings
Currenty, no settings in core use this, but textareas will be useful in theme settings and plugins.
This commit is contained in:
parent
e5a81aeb6e
commit
edcdbe1946
|
@ -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 list_type].freeze
|
||||
CONSUMED_OPTS = %i[enum choices type validator min max regex hidden regex_error allow_any list_type textarea].freeze
|
||||
VALIDATOR_OPTS = %i[min max regex hidden regex_error].freeze
|
||||
|
||||
# For plugins, so they can tell if a feature is supported
|
||||
|
@ -65,11 +65,16 @@ class SiteSettings::TypeSupervisor
|
|||
@types = {}
|
||||
@allow_any = {}
|
||||
@list_type = {}
|
||||
@textareas = {}
|
||||
end
|
||||
|
||||
def load_setting(name_arg, opts = {})
|
||||
name = name_arg.to_sym
|
||||
|
||||
if opts[:textarea]
|
||||
@textareas[name] = opts[:textarea]
|
||||
end
|
||||
|
||||
if (enum = opts[:enum])
|
||||
@enums[name] = enum.is_a?(String) ? enum.constantize : enum
|
||||
opts[:type] ||= :enum
|
||||
|
@ -148,6 +153,8 @@ class SiteSettings::TypeSupervisor
|
|||
|
||||
result[:choices] = @choices[name] if @choices.has_key? name
|
||||
result[:list_type] = @list_type[name] if @list_type.has_key? name
|
||||
result[:textarea] = @textareas[name] if @textareas.has_key? name
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
|
|
|
@ -331,6 +331,7 @@ describe SiteSettings::TypeSupervisor do
|
|||
settings.setting(:type_float, 2.3232)
|
||||
settings.setting(:type_string, 'string')
|
||||
settings.setting(:type_url_list, 'string', type: 'url_list')
|
||||
settings.setting(:type_textarea, 'string', textarea: true)
|
||||
settings.setting(:type_enum_choices, '2', type: 'enum', choices: ['1', '2'])
|
||||
settings.setting(:type_enum_class, 'a', enum: 'TestEnumClass2')
|
||||
settings.setting(:type_list, 'a', type: 'list', choices: ['a', 'b'], list_type: 'compact')
|
||||
|
@ -355,6 +356,9 @@ describe SiteSettings::TypeSupervisor do
|
|||
it 'returns url_list type' do
|
||||
expect(settings.type_supervisor.type_hash(:type_url_list)[:type]).to eq 'url_list'
|
||||
end
|
||||
it 'returns textarea type' do
|
||||
expect(settings.type_supervisor.type_hash(:type_textarea)[:textarea]).to eq true
|
||||
end
|
||||
it 'returns enum type' do
|
||||
expect(settings.type_supervisor.type_hash(:type_enum_choices)[:type]).to eq 'enum'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue