line-message-builder 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +20 -0
- data/CLAUDE.md +124 -0
- data/README.md +24 -16
- data/claudekit.json +11 -0
- data/docs/rubrics/rdoc.md +169 -0
- data/lib/line/message/builder/actions/message.rb +47 -26
- data/lib/line/message/builder/actions/postback.rb +56 -26
- data/lib/line/message/builder/actions/uri.rb +139 -0
- data/lib/line/message/builder/actions.rb +6 -3
- data/lib/line/message/builder/base.rb +92 -67
- data/lib/line/message/builder/container.rb +55 -60
- data/lib/line/message/builder/context.rb +51 -72
- data/lib/line/message/builder/flex/actionable.rb +53 -32
- data/lib/line/message/builder/flex/box.rb +342 -79
- data/lib/line/message/builder/flex/bubble.rb +73 -46
- data/lib/line/message/builder/flex/builder.rb +39 -28
- data/lib/line/message/builder/flex/button.rb +90 -42
- data/lib/line/message/builder/flex/carousel.rb +48 -20
- data/lib/line/message/builder/flex/icon.rb +152 -0
- data/lib/line/message/builder/flex/image.rb +95 -33
- data/lib/line/message/builder/flex/partial.rb +47 -49
- data/lib/line/message/builder/flex/position.rb +187 -100
- data/lib/line/message/builder/flex/separator.rb +49 -6
- data/lib/line/message/builder/flex/size.rb +67 -47
- data/lib/line/message/builder/flex/span.rb +106 -32
- data/lib/line/message/builder/flex/text.rb +166 -54
- data/lib/line/message/builder/flex.rb +26 -23
- data/lib/line/message/builder/quick_reply.rb +174 -4
- data/lib/line/message/builder/text.rb +70 -3
- data/lib/line/message/builder/version.rb +1 -1
- data/lib/line/message/builder.rb +14 -11
- data/lib/line/message/rspec/matchers/have_flex_bubble.rb +1 -1
- data/lib/line/message/rspec/matchers/have_flex_component.rb +16 -6
- data/lib/line/message/rspec/matchers/have_flex_message.rb +1 -1
- data/lib/line/message/rspec/matchers/have_flex_separator.rb +1 -1
- data/lib/line/message/rspec/matchers/have_quick_reply.rb +1 -1
- data/lib/line/message/rspec/matchers/have_text_message.rb +1 -1
- data/llm.txt +276 -35
- data/release-please-config.json +3 -1
- metadata +9 -3
|
@@ -4,14 +4,17 @@ module Line
|
|
|
4
4
|
module Message
|
|
5
5
|
module Builder
|
|
6
6
|
module Flex
|
|
7
|
-
# Represents a
|
|
7
|
+
# Represents a span component in a LINE Flex Message.
|
|
8
8
|
#
|
|
9
9
|
# Span components are used within a Text component to apply different styling
|
|
10
10
|
# to specific portions of text. They offer various styling options, including
|
|
11
|
-
#
|
|
12
|
-
# cannot have actions attached to them.
|
|
11
|
+
# +size+, +weight+, +color+, +style+ and +decoration+. Unlike Text
|
|
12
|
+
# components, spans cannot have actions attached to them.
|
|
13
|
+
#
|
|
14
|
+
# A +decoration+ set on the surrounding Text cannot be overridden by a span.
|
|
15
|
+
#
|
|
16
|
+
# == Example
|
|
13
17
|
#
|
|
14
|
-
# @example Creating a text component with spans
|
|
15
18
|
# Line::Message::Builder.with do
|
|
16
19
|
# flex alt_text: "Span Example" do
|
|
17
20
|
# bubble do
|
|
@@ -26,44 +29,90 @@ module Line
|
|
|
26
29
|
# end
|
|
27
30
|
# end
|
|
28
31
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
32
|
+
# See also:
|
|
33
|
+
# - https://developers.line.biz/en/reference/messaging-api/#span
|
|
34
|
+
# - Size::Shared for common size keywords (e.g., +:xl+, +:sm+)
|
|
31
35
|
class Span < Line::Message::Builder::Base
|
|
32
36
|
include Size::Shared # Adds `size` option (e.g., :sm, :md, :xl).
|
|
33
37
|
|
|
34
|
-
#
|
|
35
|
-
# @return [String] The actual text content to be displayed.
|
|
36
|
-
# This is a required attribute.
|
|
38
|
+
# The actual text content to be displayed. This is a required attribute.
|
|
37
39
|
attr_reader :text
|
|
38
40
|
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
41
|
+
# :method: color
|
|
42
|
+
# :call-seq:
|
|
43
|
+
# color() -> String or nil
|
|
44
|
+
# color(value) -> String
|
|
45
|
+
#
|
|
46
|
+
# Sets or gets the text color.
|
|
47
|
+
#
|
|
48
|
+
# [value]
|
|
49
|
+
# Hexadecimal color code (e.g., <code>"#RRGGBB"</code>, <code>"#RRGGBBAA"</code>)
|
|
50
|
+
#
|
|
51
|
+
# == Example
|
|
52
|
+
#
|
|
53
|
+
# span "Hello", color: "#FF0000"
|
|
43
54
|
option :color, default: nil
|
|
44
55
|
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
56
|
+
# :method: weight
|
|
57
|
+
# :call-seq:
|
|
58
|
+
# weight() -> Symbol, String, or nil
|
|
59
|
+
# weight(value) -> Symbol or String
|
|
60
|
+
#
|
|
61
|
+
# Sets or gets the text weight.
|
|
62
|
+
#
|
|
63
|
+
# [value]
|
|
64
|
+
# Text weight. Valid values are +:regular+ and +:bold+
|
|
65
|
+
#
|
|
66
|
+
# == Example
|
|
67
|
+
#
|
|
68
|
+
# span "Bold text", weight: :bold
|
|
49
69
|
option :weight, default: nil, validator: Validators::Enum.new(:regular, :bold)
|
|
50
70
|
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
71
|
+
# :method: decoration
|
|
72
|
+
# :call-seq:
|
|
73
|
+
# decoration() -> Symbol, String, or nil
|
|
74
|
+
# decoration(value) -> Symbol or String
|
|
75
|
+
#
|
|
76
|
+
# Sets or gets the text decoration.
|
|
77
|
+
#
|
|
78
|
+
# [value]
|
|
79
|
+
# Text decoration. Valid values are +:none+, +:underline+, and <code>:line-through</code>
|
|
80
|
+
#
|
|
81
|
+
# == Example
|
|
82
|
+
#
|
|
83
|
+
# span "Underlined", decoration: :underline
|
|
56
84
|
option :decoration, default: nil, validator: Validators::Enum.new(:none, :underline, :"line-through")
|
|
57
85
|
|
|
86
|
+
# :method: style
|
|
87
|
+
# :call-seq:
|
|
88
|
+
# style() -> Symbol, String, or nil
|
|
89
|
+
# style(value) -> Symbol or String
|
|
90
|
+
#
|
|
91
|
+
# Sets or gets the text style.
|
|
92
|
+
#
|
|
93
|
+
# [value]
|
|
94
|
+
# Text style. Valid values are +:normal+ (default) and +:italic+
|
|
95
|
+
#
|
|
96
|
+
# == Example
|
|
97
|
+
#
|
|
98
|
+
# span "Emphasised", style: :italic
|
|
99
|
+
option :style, default: nil, validator: Validators::Enum.new(:normal, :italic)
|
|
100
|
+
|
|
58
101
|
# Initializes a new Flex Message Span component.
|
|
59
102
|
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
103
|
+
# [text_content]
|
|
104
|
+
# The text to display. This is required
|
|
105
|
+
# [context]
|
|
106
|
+
# An optional context for the builder
|
|
107
|
+
# [options]
|
|
108
|
+
# A hash of options to set instance variables (e.g., +:color+, +:weight+,
|
|
109
|
+
# +:decoration+, and options from included modules)
|
|
110
|
+
# [block]
|
|
111
|
+
# An optional block, typically not used for spans
|
|
112
|
+
#
|
|
113
|
+
# == Example
|
|
114
|
+
#
|
|
115
|
+
# span "Hello", color: "#FF0000", weight: :bold
|
|
67
116
|
def initialize(text_content, context: nil, **options, &)
|
|
68
117
|
@text = text_content # The text content is mandatory.
|
|
69
118
|
|
|
@@ -72,25 +121,49 @@ module Line
|
|
|
72
121
|
|
|
73
122
|
# Sets weight to bold.
|
|
74
123
|
#
|
|
75
|
-
#
|
|
124
|
+
# == Example
|
|
125
|
+
#
|
|
126
|
+
# span "Bold text" do
|
|
127
|
+
# bold!
|
|
128
|
+
# end
|
|
76
129
|
def bold!
|
|
77
130
|
weight(:bold)
|
|
78
131
|
end
|
|
79
132
|
|
|
133
|
+
# Sets style to italic.
|
|
134
|
+
#
|
|
135
|
+
# == Example
|
|
136
|
+
#
|
|
137
|
+
# span "Emphasised text" do
|
|
138
|
+
# italic!
|
|
139
|
+
# end
|
|
140
|
+
def italic!
|
|
141
|
+
style(:italic)
|
|
142
|
+
end
|
|
143
|
+
|
|
80
144
|
# Sets decoration to underline.
|
|
81
145
|
#
|
|
82
|
-
#
|
|
146
|
+
# == Example
|
|
147
|
+
#
|
|
148
|
+
# span "Underlined text" do
|
|
149
|
+
# underline!
|
|
150
|
+
# end
|
|
83
151
|
def underline!
|
|
84
152
|
decoration(:underline)
|
|
85
153
|
end
|
|
86
154
|
|
|
87
155
|
# Sets decoration to line-through.
|
|
88
156
|
#
|
|
89
|
-
#
|
|
157
|
+
# == Example
|
|
158
|
+
#
|
|
159
|
+
# span "Strikethrough text" do
|
|
160
|
+
# line_through!
|
|
161
|
+
# end
|
|
90
162
|
def line_through!
|
|
91
163
|
decoration(:"line-through")
|
|
92
164
|
end
|
|
93
165
|
|
|
166
|
+
# :nodoc:
|
|
94
167
|
def to_h
|
|
95
168
|
raise RequiredError, "text content is required for a span component" if text.nil?
|
|
96
169
|
|
|
@@ -100,6 +173,7 @@ module Line
|
|
|
100
173
|
color: color,
|
|
101
174
|
size: size,
|
|
102
175
|
weight: weight,
|
|
176
|
+
style: style,
|
|
103
177
|
decoration: decoration
|
|
104
178
|
}.compact
|
|
105
179
|
end
|
|
@@ -4,19 +4,20 @@ module Line
|
|
|
4
4
|
module Message
|
|
5
5
|
module Builder
|
|
6
6
|
module Flex
|
|
7
|
-
# Represents a
|
|
7
|
+
# Represents a text component in a LINE Flex Message.
|
|
8
8
|
#
|
|
9
9
|
# Text components are used to display strings of text. They offer various
|
|
10
|
-
# styling options, including font
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
10
|
+
# styling options, including font +size+, +weight+, +style+, +decoration+,
|
|
11
|
+
# +color+, +align+ment, +gravity+, text +wrap+ping, +line_spacing+,
|
|
12
|
+
# +max_lines+, +scaling+, and more. A text component can also have an
|
|
13
|
+
# action to make it tappable.
|
|
14
14
|
#
|
|
15
|
-
# Text components also support embedded
|
|
15
|
+
# Text components also support embedded Span components, which allow parts of
|
|
16
16
|
# the text to have different styling. Spans can be added to a text component
|
|
17
|
-
# using the
|
|
17
|
+
# using the +span+ method within the Text component block.
|
|
18
|
+
#
|
|
19
|
+
# == Example: Creating a text component within a box
|
|
18
20
|
#
|
|
19
|
-
# @example Creating a text component within a box
|
|
20
21
|
# Line::Message::Builder.with do
|
|
21
22
|
# flex alt_text: "Text Example" do
|
|
22
23
|
# bubble do
|
|
@@ -25,14 +26,15 @@ module Line
|
|
|
25
26
|
# size: :xl,
|
|
26
27
|
# color: "#FF0000",
|
|
27
28
|
# wrap: true do
|
|
28
|
-
# message "
|
|
29
|
+
# message "Tell me more about text", label: "More info"
|
|
29
30
|
# end
|
|
30
31
|
# end
|
|
31
32
|
# end
|
|
32
33
|
# end
|
|
33
34
|
# end
|
|
34
35
|
#
|
|
35
|
-
#
|
|
36
|
+
# == Example: Creating a text component with spans
|
|
37
|
+
#
|
|
36
38
|
# Line::Message::Builder.with do
|
|
37
39
|
# flex alt_text: "Span Example" do
|
|
38
40
|
# bubble do
|
|
@@ -47,15 +49,29 @@ module Line
|
|
|
47
49
|
# end
|
|
48
50
|
# end
|
|
49
51
|
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
52
|
+
# === Example: Emphasising a heading and truncating a long body
|
|
53
|
+
#
|
|
54
|
+
# Line::Message::Builder.with do
|
|
55
|
+
# flex alt_text: "Article" do
|
|
56
|
+
# bubble do
|
|
57
|
+
# body do
|
|
58
|
+
# text "Ruby Taiwan Meetup", weight: :bold, size: :xl
|
|
59
|
+
# text long_article_body, wrap: true, max_lines: 3
|
|
60
|
+
# end
|
|
61
|
+
# end
|
|
62
|
+
# end
|
|
63
|
+
# end
|
|
64
|
+
#
|
|
65
|
+
# See also:
|
|
66
|
+
# - https://developers.line.biz/en/reference/messaging-api/#text
|
|
67
|
+
# - Actionable for making the text tappable
|
|
68
|
+
# - Position::Horizontal for +align+ property
|
|
69
|
+
# - Position::Vertical for +gravity+ property
|
|
70
|
+
# - Position::Margin for +margin+ property
|
|
71
|
+
# - Position::Offset for offset properties
|
|
72
|
+
# - Size::Flex for +flex+ sizing property
|
|
73
|
+
# - Size::Shared for common +size+ keywords (e.g., +:xl+, +:sm+)
|
|
74
|
+
# - Size::AdjustMode for +adjust_mode+ property
|
|
59
75
|
class Text < Line::Message::Builder::Base
|
|
60
76
|
include Actionable # Enables defining an action for the text.
|
|
61
77
|
include Position::Horizontal # Adds `align` option.
|
|
@@ -66,41 +82,120 @@ module Line
|
|
|
66
82
|
include Size::Shared # Adds `size` option (e.g., :sm, :md, :xl).
|
|
67
83
|
include Size::AdjustMode # Adds `adjust_mode` option.
|
|
68
84
|
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
# The actual text content to be displayed (required attribute).
|
|
86
|
+
attr_reader :text
|
|
87
|
+
|
|
88
|
+
# Array of Span components for styled text segments.
|
|
89
|
+
attr_reader :contents
|
|
73
90
|
|
|
74
|
-
#
|
|
91
|
+
# :method: wrap
|
|
92
|
+
# :call-seq:
|
|
93
|
+
# wrap() -> Boolean
|
|
94
|
+
# wrap(value) -> Boolean
|
|
95
|
+
#
|
|
96
|
+
# Sets or gets whether the text should wrap or be truncated if it exceeds
|
|
75
97
|
# the component's width.
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
98
|
+
#
|
|
99
|
+
# [value]
|
|
100
|
+
# +true+ to enable text wrapping, +false+ (default) to disable
|
|
79
101
|
option :wrap, default: false
|
|
80
102
|
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
103
|
+
# :method: line_spacing
|
|
104
|
+
# :call-seq:
|
|
105
|
+
# line_spacing() -> String or nil
|
|
106
|
+
# line_spacing(value) -> String
|
|
107
|
+
#
|
|
108
|
+
# Sets or gets the spacing between lines of text.
|
|
109
|
+
# Can be a pixel value or a keyword.
|
|
110
|
+
#
|
|
111
|
+
# [value]
|
|
112
|
+
# The line spacing value (e.g., <code>"5px"</code>)
|
|
86
113
|
option :line_spacing, default: nil # API key: lineSpacing
|
|
87
114
|
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
115
|
+
# :method: color
|
|
116
|
+
# :call-seq:
|
|
117
|
+
# color() -> String or nil
|
|
118
|
+
# color(value) -> String
|
|
119
|
+
#
|
|
120
|
+
# Sets or gets the color of the text.
|
|
121
|
+
#
|
|
122
|
+
# [value]
|
|
123
|
+
# Hexadecimal color code (e.g., <code>"#RRGGBB"</code>, <code>"#RRGGBBAA"</code>)
|
|
92
124
|
option :color, default: nil
|
|
93
125
|
|
|
126
|
+
# :method: weight
|
|
127
|
+
# :call-seq:
|
|
128
|
+
# weight() -> Symbol or nil
|
|
129
|
+
# weight(value) -> Symbol
|
|
130
|
+
#
|
|
131
|
+
# Sets or gets the font weight of the text.
|
|
132
|
+
#
|
|
133
|
+
# [value]
|
|
134
|
+
# <code>:regular</code> (default) or <code>:bold</code>
|
|
135
|
+
option :weight, default: nil, validator: Validators::Enum.new(:regular, :bold)
|
|
136
|
+
|
|
137
|
+
# :method: max_lines
|
|
138
|
+
# :call-seq:
|
|
139
|
+
# max_lines() -> Integer or nil
|
|
140
|
+
# max_lines(value) -> Integer
|
|
141
|
+
#
|
|
142
|
+
# Sets or gets the maximum number of lines to display. Text exceeding
|
|
143
|
+
# this number of lines ends in an ellipsis. A value of +0+ displays the
|
|
144
|
+
# entire text.
|
|
145
|
+
#
|
|
146
|
+
# [value]
|
|
147
|
+
# The maximum number of lines
|
|
148
|
+
option :max_lines, default: nil # API key: maxLines
|
|
149
|
+
|
|
150
|
+
# :method: style
|
|
151
|
+
# :call-seq:
|
|
152
|
+
# style() -> Symbol or nil
|
|
153
|
+
# style(value) -> Symbol
|
|
154
|
+
#
|
|
155
|
+
# Sets or gets the font style of the text.
|
|
156
|
+
#
|
|
157
|
+
# [value]
|
|
158
|
+
# <code>:normal</code> (default) or <code>:italic</code>
|
|
159
|
+
option :style, default: nil, validator: Validators::Enum.new(:normal, :italic)
|
|
160
|
+
|
|
161
|
+
# :method: decoration
|
|
162
|
+
# :call-seq:
|
|
163
|
+
# decoration() -> Symbol or nil
|
|
164
|
+
# decoration(value) -> Symbol
|
|
165
|
+
#
|
|
166
|
+
# Sets or gets the decoration of the text. A decoration set here cannot
|
|
167
|
+
# be overwritten by the +decoration+ of a nested Span.
|
|
168
|
+
#
|
|
169
|
+
# [value]
|
|
170
|
+
# <code>:none</code> (default), <code>:underline</code> or
|
|
171
|
+
# <code>:"line-through"</code>
|
|
172
|
+
option :decoration, default: nil, validator: Validators::Enum.new(:none, :underline, :"line-through")
|
|
173
|
+
|
|
174
|
+
# :method: scaling
|
|
175
|
+
# :call-seq:
|
|
176
|
+
# scaling() -> Boolean or nil
|
|
177
|
+
# scaling(value) -> Boolean
|
|
178
|
+
#
|
|
179
|
+
# Sets or gets whether the font size follows the font size setting of
|
|
180
|
+
# the LINE app. Spans nested in this text are scaled as well.
|
|
181
|
+
#
|
|
182
|
+
# [value]
|
|
183
|
+
# +true+ to scale the font size, +false+ (default) to keep it fixed
|
|
184
|
+
option :scaling, default: nil
|
|
185
|
+
|
|
94
186
|
# Initializes a new Flex Message Text component.
|
|
95
187
|
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
188
|
+
# [text_content]
|
|
189
|
+
# The text to display (required)
|
|
190
|
+
# [context]
|
|
191
|
+
# An optional context for the builder
|
|
192
|
+
# [options]
|
|
193
|
+
# A hash of options to set instance variables
|
|
194
|
+
# (e.g., +:wrap+, +:color+, +:size+, and options from included modules)
|
|
195
|
+
# [block]
|
|
196
|
+
# An optional block, typically used to define an action for the text
|
|
197
|
+
#
|
|
198
|
+
# Raises RequiredError if +text_content+ is nil (in +to_h+).
|
|
104
199
|
def initialize(text_content = nil, context: nil, **options, &)
|
|
105
200
|
@text = text_content # The text content is mandatory.
|
|
106
201
|
@contents = [] # Initialize contents for spans, if any.
|
|
@@ -108,27 +203,30 @@ module Line
|
|
|
108
203
|
super(context: context, **options, &) # Sets options and evals block (for action).
|
|
109
204
|
end
|
|
110
205
|
|
|
111
|
-
# A convenience DSL method to set the
|
|
206
|
+
# A convenience DSL method to set the +wrap+ property to +true+.
|
|
207
|
+
#
|
|
208
|
+
# == Example
|
|
112
209
|
#
|
|
113
|
-
# @example
|
|
114
210
|
# text_component.text "Long text..."
|
|
115
211
|
# text_component.wrap! # Enables text wrapping
|
|
116
|
-
#
|
|
117
|
-
# @return [true]
|
|
118
212
|
def wrap!
|
|
119
213
|
wrap(true) # Use the setter generated by `option`
|
|
120
214
|
end
|
|
121
215
|
|
|
122
|
-
# Adds a
|
|
216
|
+
# Adds a Span component to this text component's contents.
|
|
123
217
|
#
|
|
124
218
|
# Spans allow different styling for parts of the text, such as color,
|
|
125
219
|
# weight, size, and decoration.
|
|
126
220
|
#
|
|
127
|
-
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
#
|
|
221
|
+
# [text_content]
|
|
222
|
+
# The span text content
|
|
223
|
+
# [options]
|
|
224
|
+
# Options for the span (see Span)
|
|
225
|
+
# [block]
|
|
226
|
+
# An optional block for advanced span configuration
|
|
227
|
+
#
|
|
228
|
+
# == Example
|
|
229
|
+
#
|
|
132
230
|
# text "Message with spans:" do
|
|
133
231
|
# span "Important", color: "#FF0000", weight: :bold
|
|
134
232
|
# span " normal text"
|
|
@@ -137,10 +235,12 @@ module Line
|
|
|
137
235
|
@contents << Span.new(text_content, context: @context, **options, &)
|
|
138
236
|
end
|
|
139
237
|
|
|
238
|
+
# :nodoc:
|
|
140
239
|
def any_content?
|
|
141
240
|
!contents.empty? || !text.nil?
|
|
142
241
|
end
|
|
143
242
|
|
|
243
|
+
# :nodoc:
|
|
144
244
|
def to_h
|
|
145
245
|
raise RequiredError, "text content is required for a text component" unless any_content?
|
|
146
246
|
|
|
@@ -151,6 +251,7 @@ module Line
|
|
|
151
251
|
|
|
152
252
|
private
|
|
153
253
|
|
|
254
|
+
# :nodoc:
|
|
154
255
|
def to_api # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
155
256
|
{
|
|
156
257
|
type: "text",
|
|
@@ -159,6 +260,11 @@ module Line
|
|
|
159
260
|
wrap: wrap, # From option
|
|
160
261
|
color: color, # From option
|
|
161
262
|
lineSpacing: line_spacing, # From option (maps to API key)
|
|
263
|
+
weight: weight, # From option
|
|
264
|
+
maxLines: max_lines, # From option (maps to API key)
|
|
265
|
+
style: style, # From option
|
|
266
|
+
decoration: decoration, # From option
|
|
267
|
+
scaling: scaling, # From option
|
|
162
268
|
# Position::Horizontal & Position::Vertical
|
|
163
269
|
align: align, # From Position::Horizontal
|
|
164
270
|
gravity: gravity, # From Position::Vertical
|
|
@@ -180,6 +286,7 @@ module Line
|
|
|
180
286
|
}.compact
|
|
181
287
|
end
|
|
182
288
|
|
|
289
|
+
# :nodoc:
|
|
183
290
|
def to_sdkv2 # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
184
291
|
{
|
|
185
292
|
type: "text",
|
|
@@ -188,6 +295,11 @@ module Line
|
|
|
188
295
|
wrap: wrap, # From option
|
|
189
296
|
color: color, # From option
|
|
190
297
|
line_spacing: line_spacing, # From option (maps to API key)
|
|
298
|
+
weight: weight, # From option
|
|
299
|
+
max_lines: max_lines, # From option (maps to API key)
|
|
300
|
+
style: style, # From option
|
|
301
|
+
decoration: decoration, # From option
|
|
302
|
+
scaling: scaling, # From option
|
|
191
303
|
# Position::Horizontal & Position::Vertical
|
|
192
304
|
align: align, # From Position::Horizontal
|
|
193
305
|
gravity: gravity, # From Position::Vertical
|
|
@@ -3,31 +3,32 @@
|
|
|
3
3
|
module Line
|
|
4
4
|
module Message
|
|
5
5
|
module Builder
|
|
6
|
-
# The
|
|
6
|
+
# The Line::Message::Builder::Flex module serves as the primary namespace
|
|
7
7
|
# for all classes, modules, and components related to the construction of
|
|
8
|
-
# LINE Flex Messages within the
|
|
8
|
+
# LINE Flex Messages within the +line-message-builder+ gem.
|
|
9
9
|
#
|
|
10
10
|
# Flex Messages are highly customizable messages that can display rich content
|
|
11
11
|
# with various layouts, components, and interactive elements. This module
|
|
12
12
|
# organizes the DSL for building these messages.
|
|
13
13
|
#
|
|
14
|
-
# This file
|
|
15
|
-
#
|
|
16
|
-
# -
|
|
17
|
-
# - Container components:
|
|
18
|
-
# - Basic components:
|
|
19
|
-
# - Mixin modules for shared functionality:
|
|
20
|
-
#
|
|
21
|
-
# - The partial system:
|
|
14
|
+
# This file is responsible for loading all necessary sub-components and builder
|
|
15
|
+
# logic for Flex Messages, such as:
|
|
16
|
+
# - Flex::Builder - The main class used to construct a complete Flex Message object
|
|
17
|
+
# - Container components: Flex::Bubble, Flex::Carousel
|
|
18
|
+
# - Basic components: Flex::Box, Flex::Text, Flex::Button, Flex::Image
|
|
19
|
+
# - Mixin modules for shared functionality: Flex::Actionable, modules within
|
|
20
|
+
# Flex::Position and Flex::Size
|
|
21
|
+
# - The partial system: Flex::HasPartial and Flex::Partial
|
|
22
22
|
#
|
|
23
23
|
# While this module itself is a namespace, the actual process of building a
|
|
24
|
-
# Flex Message typically starts within a
|
|
25
|
-
# block, by calling the
|
|
26
|
-
# instantiates and uses
|
|
24
|
+
# Flex Message typically starts within a Line::Message::Builder::Container
|
|
25
|
+
# block, by calling the +flex+ method on the container. This method then
|
|
26
|
+
# instantiates and uses Flex::Builder to define the Flex Message structure.
|
|
27
|
+
#
|
|
28
|
+
# == Example
|
|
27
29
|
#
|
|
28
|
-
# @example How a Flex Message is typically initiated (conceptual)
|
|
29
30
|
# Line::Message::Builder.with do
|
|
30
|
-
# # This
|
|
31
|
+
# # This +flex+ call on root_container would utilize Flex::Builder
|
|
31
32
|
# flex alt_text: "My Flex Message" do
|
|
32
33
|
# bubble do
|
|
33
34
|
# # ... define bubble content ...
|
|
@@ -35,14 +36,15 @@ module Line
|
|
|
35
36
|
# end
|
|
36
37
|
# end
|
|
37
38
|
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
39
|
+
# See also:
|
|
40
|
+
# - Flex::Builder - For the main Flex Message construction entry point
|
|
41
|
+
# - Flex::Bubble
|
|
42
|
+
# - Flex::Carousel
|
|
43
|
+
# - Flex::Box
|
|
44
|
+
# - Flex::Text
|
|
45
|
+
# - Flex::Button
|
|
46
|
+
# - Flex::Image
|
|
47
|
+
# - https://developers.line.biz/en/docs/messaging-api/using-flex-messages/
|
|
46
48
|
module Flex
|
|
47
49
|
# Main builder for the entire Flex Message object
|
|
48
50
|
require_relative "flex/builder"
|
|
@@ -64,6 +66,7 @@ module Line
|
|
|
64
66
|
require_relative "flex/text" # Text display
|
|
65
67
|
require_relative "flex/button" # Interactive button
|
|
66
68
|
require_relative "flex/image" # Image display
|
|
69
|
+
require_relative "flex/icon" # Icon decorating adjacent text
|
|
67
70
|
require_relative "flex/separator" # Visual separator
|
|
68
71
|
require_relative "flex/span" # Text span for styling parts of text
|
|
69
72
|
end
|