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
```
This commit is contained in:
David Taylor 2019-02-05 14:14:53 +00:00
parent 7b7bc3db39
commit a3b47c1dd1
5 changed files with 26 additions and 1 deletions

View File

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

View File

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

View File

@ -38,6 +38,8 @@ class ThemeSettingsParser
opts[:list_type] = raw_opts[:list_type]
end
opts[:textarea] = !!raw_opts[:textarea]
opts
end

View File

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

View File

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