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:
parent
7b7bc3db39
commit
a3b47c1dd1
|
@ -1,6 +1,6 @@
|
||||||
class ThemeSettingsSerializer < ApplicationSerializer
|
class ThemeSettingsSerializer < ApplicationSerializer
|
||||||
attributes :setting, :type, :default, :value, :description, :valid_values,
|
attributes :setting, :type, :default, :value, :description, :valid_values,
|
||||||
:list_type
|
:list_type, :textarea
|
||||||
|
|
||||||
def setting
|
def setting
|
||||||
object.name
|
object.name
|
||||||
|
@ -41,4 +41,13 @@ class ThemeSettingsSerializer < ApplicationSerializer
|
||||||
def include_list_type?
|
def include_list_type?
|
||||||
object.type == ThemeSetting.types[:list]
|
object.type == ThemeSetting.types[:list]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def textarea
|
||||||
|
object.textarea
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_textarea?
|
||||||
|
object.type == ThemeSetting.types[:string]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -105,6 +105,10 @@ class ThemeSettingsManager
|
||||||
def is_valid_value?(new_value)
|
def is_valid_value?(new_value)
|
||||||
(@opts[:min]..@opts[:max]).include? new_value.to_s.length
|
(@opts[:min]..@opts[:max]).include? new_value.to_s.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def textarea
|
||||||
|
@opts[:textarea]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Bool < self
|
class Bool < self
|
||||||
|
|
|
@ -38,6 +38,8 @@ class ThemeSettingsParser
|
||||||
opts[:list_type] = raw_opts[:list_type]
|
opts[:list_type] = raw_opts[:list_type]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts[:textarea] = !!raw_opts[:textarea]
|
||||||
|
|
||||||
opts
|
opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,12 @@ describe ThemeSettingsManager do
|
||||||
|
|
||||||
expect { string_setting.value = ("a" * 21) }.to raise_error(Discourse::InvalidParameters)
|
expect { string_setting.value = ("a" * 21) }.to raise_error(Discourse::InvalidParameters)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "List" do
|
context "List" do
|
||||||
|
|
|
@ -10,6 +10,10 @@ string_setting_02:
|
||||||
min: 2
|
min: 2
|
||||||
max: 20
|
max: 20
|
||||||
|
|
||||||
|
string_setting_03:
|
||||||
|
default: "string value"
|
||||||
|
textarea: true
|
||||||
|
|
||||||
integer_setting: 51
|
integer_setting: 51
|
||||||
|
|
||||||
integer_setting_02:
|
integer_setting_02:
|
||||||
|
|
Loading…
Reference in New Issue