From edcdbe1946dc56969c9c8e1f4a9c777dd5e540a7 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 4 Feb 2019 15:41:58 -0500 Subject: [PATCH] DEV: Restore textarea type for site settings Currenty, no settings in core use this, but textareas will be useful in theme settings and plugins. --- lib/site_settings/type_supervisor.rb | 9 ++++++++- spec/components/site_settings/type_supervisor_spec.rb | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rb index 0f4f483faaa..93da66333e7 100644 --- a/lib/site_settings/type_supervisor.rb +++ b/lib/site_settings/type_supervisor.rb @@ -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 diff --git a/spec/components/site_settings/type_supervisor_spec.rb b/spec/components/site_settings/type_supervisor_spec.rb index 9648b0ec272..181a06a146e 100644 --- a/spec/components/site_settings/type_supervisor_spec.rb +++ b/spec/components/site_settings/type_supervisor_spec.rb @@ -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