Skip to content

Commit 1a91e5d

Browse files
committed
enable consisten text option access
1 parent 164b505 commit 1a91e5d

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/matestack/ui/core/properties.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ module Initializer
1212
def initialize(html_tag = nil, text = nil, options = {}, &block)
1313
extract_options(text, options)
1414
create_context
15-
# warn "[DEPRECATION] passing text with option :text is deprecated. Please pass text as first argument." if self.options.has_key?(:text)
16-
self.text = self.options.delete(:text) if self.options.has_key?(:text)
15+
set_text
1716
super
1817
end
1918
end
@@ -78,6 +77,28 @@ def create_context_for_properties(properties, required: false)
7877
end if properties
7978
end
8079

80+
def set_text
81+
# the text property is treated specially since 2.0.0 enables text injection for all components like:
82+
#
83+
# some_component "foo", class: "whatever" -> self.text -> "foo"
84+
#
85+
# prior to 2.0.0, text injection happened like that:
86+
#
87+
# some_component text: "foo", class: "whatever" -> self.options[:text] -> "foo"
88+
#
89+
# in both cases "foo" should be available via self.context.text AND self.text
90+
#
91+
# in 2.0.0 text is available via context.text if text is marked as required or optional
92+
# in order to have a consistent access, we make this text accessable via self.text as well in this case
93+
# in all cases, text is accessable via self.text AND self.context.text
94+
# we make the passed in text option available via context.text by default, even if not marked as required or optional
95+
#
96+
# additionally we need to delete text from the options, as they might be used to be rendered as
97+
# tag attributes without any whitelisting as happened prior to 2.0.0
98+
self.text = self.options.delete(:text) if self.options.has_key?(:text)
99+
self.context.text = self.text
100+
end
101+
81102
end
82103
end
83104
end

0 commit comments

Comments
 (0)