mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -38,6 +38,8 @@ class ThemeSettingsParser
|
|||
opts[:list_type] = raw_opts[:list_type]
|
||||
end
|
||||
|
||||
opts[:textarea] = !!raw_opts[:textarea]
|
||||
|
||||
opts
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user