FEATURE: Allow string theme settings to display with multiple lines

FEATURE: Allow string theme settings to display with multiple lines

To use, add textarea: true to the theme settings.yml. For example:

my_setting:
  default: "some string"
  textarea: true
diff --git a/app/serializers/theme_settings_serializer.rb b/app/serializers/theme_settings_serializer.rb
index d7fe44c..1bd892f 100644
--- a/app/serializers/theme_settings_serializer.rb
+++ b/app/serializers/theme_settings_serializer.rb
@@ -1,6 +1,6 @@
 class ThemeSettingsSerializer < ApplicationSerializer
   attributes :setting, :type, :default, :value, :description, :valid_values,
-             :list_type
+             :list_type, :textarea
 
   def setting
     object.name
@@ -41,4 +41,13 @@ class ThemeSettingsSerializer < ApplicationSerializer
   def include_list_type?
     object.type == ThemeSetting.types[:list]
   end
+
+  def textarea
+    object.textarea
+  end
+
+  def include_textarea?
+    object.type == ThemeSetting.types[:string]
+  end
+
 end
diff --git a/lib/theme_settings_manager.rb b/lib/theme_settings_manager.rb
index 81c2a7e..c59b148 100644
--- a/lib/theme_settings_manager.rb
+++ b/lib/theme_settings_manager.rb
@@ -105,6 +105,10 @@ class ThemeSettingsManager
     def is_valid_value?(new_value)
       (@opts[:min]..@opts[:max]).include? new_value.to_s.length
     end
+
+    def textarea
+      @opts[:textarea]
+    end
   end
 
   class Bool < self
diff --git a/lib/theme_settings_parser.rb b/lib/theme_settings_parser.rb
index 064dd7e..ab2ee43 100644
--- a/lib/theme_settings_parser.rb
+++ b/lib/theme_settings_parser.rb
@@ -38,6 +38,8 @@ class ThemeSettingsParser
       opts[:list_type] = raw_opts[:list_type]
     end
 
+    opts[:textarea] = !!raw_opts[:textarea]
+
     opts
   end
 
diff --git a/spec/components/theme_settings_manager_spec.rb b/spec/components/theme_settings_manager_spec.rb
index feb0382..525d98d 100644
--- a/spec/components/theme_settings_manager_spec.rb
+++ b/spec/components/theme_settings_manager_spec.rb
@@ -128,6 +128,12 @@ describe ThemeSettingsManager do
 
       expect { string_setting.value = ("a" * 21) }.to raise_error(Discourse::InvalidParameters)
     end
+
+    it "can be a textarea" do
+      string_setting = find_by_name(:string_setting_02)
+      expect(find_by_name(:string_setting_02).textarea).to eq(false)
+      expect(find_by_name(:string_setting_03).textarea).to eq(true)
+    end
   end
 
   context "List" do
diff --git a/spec/fixtures/theme_settings/valid_settings.yaml b/spec/fixtures/theme_settings/valid_settings.yaml
index 8250f34..2885fba 100644
--- a/spec/fixtures/theme_settings/valid_settings.yaml
+++ b/spec/fixtures/theme_settings/valid_settings.yaml
@@ -10,6 +10,10 @@ string_setting_02:
   min: 2
   max: 20
 
+string_setting_03:
+  default: "string value"
+  textarea: true
+
 integer_setting: 51
 
 integer_setting_02:

GitHub sha: a3b47c1d

1 Like