line-message-builder 0.8.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 +41 -0
- data/CLAUDE.md +124 -0
- data/CONVENTIONS.md +36 -0
- data/README.md +61 -43
- data/claudekit.json +11 -0
- data/docs/rubrics/rdoc.md +169 -0
- data/lib/line/message/builder/actions/message.rb +52 -31
- data/lib/line/message/builder/actions/postback.rb +63 -33
- 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 +64 -69
- data/lib/line/message/builder/context.rb +55 -80
- data/lib/line/message/builder/flex/actionable.rb +53 -32
- data/lib/line/message/builder/flex/box.rb +366 -79
- data/lib/line/message/builder/flex/bubble.rb +78 -51
- data/lib/line/message/builder/flex/builder.rb +47 -36
- data/lib/line/message/builder/flex/button.rb +96 -48
- data/lib/line/message/builder/flex/carousel.rb +57 -29
- data/lib/line/message/builder/flex/icon.rb +152 -0
- data/lib/line/message/builder/flex/image.rb +103 -42
- data/lib/line/message/builder/flex/partial.rb +58 -55
- data/lib/line/message/builder/flex/position.rb +187 -100
- data/lib/line/message/builder/flex/separator.rb +84 -0
- data/lib/line/message/builder/flex/size.rb +67 -47
- data/lib/line/message/builder/flex/span.rb +184 -0
- data/lib/line/message/builder/flex/text.rb +210 -54
- data/lib/line/message/builder/flex.rb +31 -26
- 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 +16 -13
- data/lib/line/message/rspec/matchers/have_flex_bubble.rb +1 -1
- data/lib/line/message/rspec/matchers/have_flex_component.rb +26 -5
- data/lib/line/message/rspec/matchers/have_flex_message.rb +1 -1
- data/lib/line/message/rspec/matchers/have_flex_separator.rb +20 -0
- 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/lib/line/message/rspec/matchers.rb +1 -0
- data/llm.txt +367 -45
- data/release-please-config.json +3 -1
- metadata +12 -3
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Line
|
|
4
|
+
module Message
|
|
5
|
+
module Builder
|
|
6
|
+
module Flex
|
|
7
|
+
# Represents a span component in a LINE Flex Message.
|
|
8
|
+
#
|
|
9
|
+
# Span components are used within a Text component to apply different styling
|
|
10
|
+
# to specific portions of text. They offer various styling options, including
|
|
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
|
|
17
|
+
#
|
|
18
|
+
# Line::Message::Builder.with do
|
|
19
|
+
# flex alt_text: "Span Example" do
|
|
20
|
+
# bubble do
|
|
21
|
+
# body do
|
|
22
|
+
# text do
|
|
23
|
+
# span "Hello, ", color: "#FF0000"
|
|
24
|
+
# span "Flex ", weight: :bold
|
|
25
|
+
# span "World!", size: :xl, decoration: :underline
|
|
26
|
+
# end
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
#
|
|
32
|
+
# See also:
|
|
33
|
+
# - https://developers.line.biz/en/reference/messaging-api/#span
|
|
34
|
+
# - Size::Shared for common size keywords (e.g., +:xl+, +:sm+)
|
|
35
|
+
class Span < Line::Message::Builder::Base
|
|
36
|
+
include Size::Shared # Adds `size` option (e.g., :sm, :md, :xl).
|
|
37
|
+
|
|
38
|
+
# The actual text content to be displayed. This is a required attribute.
|
|
39
|
+
attr_reader :text
|
|
40
|
+
|
|
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"
|
|
54
|
+
option :color, default: nil
|
|
55
|
+
|
|
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
|
|
69
|
+
option :weight, default: nil, validator: Validators::Enum.new(:regular, :bold)
|
|
70
|
+
|
|
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
|
|
84
|
+
option :decoration, default: nil, validator: Validators::Enum.new(:none, :underline, :"line-through")
|
|
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
|
+
|
|
101
|
+
# Initializes a new Flex Message Span component.
|
|
102
|
+
#
|
|
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
|
|
116
|
+
def initialize(text_content, context: nil, **options, &)
|
|
117
|
+
@text = text_content # The text content is mandatory.
|
|
118
|
+
|
|
119
|
+
super(context: context, **options, &) # Sets options and evals block
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Sets weight to bold.
|
|
123
|
+
#
|
|
124
|
+
# == Example
|
|
125
|
+
#
|
|
126
|
+
# span "Bold text" do
|
|
127
|
+
# bold!
|
|
128
|
+
# end
|
|
129
|
+
def bold!
|
|
130
|
+
weight(:bold)
|
|
131
|
+
end
|
|
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
|
+
|
|
144
|
+
# Sets decoration to underline.
|
|
145
|
+
#
|
|
146
|
+
# == Example
|
|
147
|
+
#
|
|
148
|
+
# span "Underlined text" do
|
|
149
|
+
# underline!
|
|
150
|
+
# end
|
|
151
|
+
def underline!
|
|
152
|
+
decoration(:underline)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Sets decoration to line-through.
|
|
156
|
+
#
|
|
157
|
+
# == Example
|
|
158
|
+
#
|
|
159
|
+
# span "Strikethrough text" do
|
|
160
|
+
# line_through!
|
|
161
|
+
# end
|
|
162
|
+
def line_through!
|
|
163
|
+
decoration(:"line-through")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# :nodoc:
|
|
167
|
+
def to_h
|
|
168
|
+
raise RequiredError, "text content is required for a span component" if text.nil?
|
|
169
|
+
|
|
170
|
+
{
|
|
171
|
+
type: "span",
|
|
172
|
+
text: text,
|
|
173
|
+
color: color,
|
|
174
|
+
size: size,
|
|
175
|
+
weight: weight,
|
|
176
|
+
style: style,
|
|
177
|
+
decoration: decoration
|
|
178
|
+
}.compact
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
@@ -4,39 +4,74 @@ 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
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
15
|
+
# Text components also support embedded Span components, which allow parts of
|
|
16
|
+
# the text to have different styling. Spans can be added to a text component
|
|
17
|
+
# using the +span+ method within the Text component block.
|
|
18
|
+
#
|
|
19
|
+
# == Example: Creating a text component within a box
|
|
20
|
+
#
|
|
21
|
+
# Line::Message::Builder.with do
|
|
22
|
+
# flex alt_text: "Text Example" do
|
|
23
|
+
# bubble do
|
|
24
|
+
# body do
|
|
25
|
+
# text "Hello, Flex World!",
|
|
26
|
+
# size: :xl,
|
|
27
|
+
# color: "#FF0000",
|
|
28
|
+
# wrap: true do
|
|
29
|
+
# message "Tell me more about text", label: "More info"
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
36
|
+
# == Example: Creating a text component with spans
|
|
37
|
+
#
|
|
38
|
+
# Line::Message::Builder.with do
|
|
39
|
+
# flex alt_text: "Span Example" do
|
|
40
|
+
# bubble do
|
|
41
|
+
# body do
|
|
42
|
+
# text "This message has styled spans:" do
|
|
43
|
+
# span "Red", color: "#FF0000"
|
|
44
|
+
# span " and ", size: :sm
|
|
45
|
+
# span "Bold", weight: :bold
|
|
25
46
|
# end
|
|
26
47
|
# end
|
|
27
48
|
# end
|
|
28
49
|
# end
|
|
29
50
|
# end
|
|
30
51
|
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
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
|
|
40
75
|
class Text < Line::Message::Builder::Base
|
|
41
76
|
include Actionable # Enables defining an action for the text.
|
|
42
77
|
include Position::Horizontal # Adds `align` option.
|
|
@@ -47,60 +82,167 @@ module Line
|
|
|
47
82
|
include Size::Shared # Adds `size` option (e.g., :sm, :md, :xl).
|
|
48
83
|
include Size::AdjustMode # Adds `adjust_mode` option.
|
|
49
84
|
|
|
50
|
-
#
|
|
51
|
-
# @return [String] The actual text content to be displayed.
|
|
52
|
-
# This is a required attribute.
|
|
85
|
+
# The actual text content to be displayed (required attribute).
|
|
53
86
|
attr_reader :text
|
|
54
87
|
|
|
55
|
-
#
|
|
88
|
+
# Array of Span components for styled text segments.
|
|
89
|
+
attr_reader :contents
|
|
90
|
+
|
|
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
|
|
56
97
|
# the component's width.
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
98
|
+
#
|
|
99
|
+
# [value]
|
|
100
|
+
# +true+ to enable text wrapping, +false+ (default) to disable
|
|
60
101
|
option :wrap, default: false
|
|
61
102
|
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
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>)
|
|
67
113
|
option :line_spacing, default: nil # API key: lineSpacing
|
|
68
114
|
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
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>)
|
|
73
124
|
option :color, default: nil
|
|
74
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
|
+
|
|
75
186
|
# Initializes a new Flex Message Text component.
|
|
76
187
|
#
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
|
|
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+).
|
|
199
|
+
def initialize(text_content = nil, context: nil, **options, &)
|
|
86
200
|
@text = text_content # The text content is mandatory.
|
|
201
|
+
@contents = [] # Initialize contents for spans, if any.
|
|
87
202
|
|
|
88
203
|
super(context: context, **options, &) # Sets options and evals block (for action).
|
|
89
204
|
end
|
|
90
205
|
|
|
91
|
-
# A convenience DSL method to set the
|
|
206
|
+
# A convenience DSL method to set the +wrap+ property to +true+.
|
|
207
|
+
#
|
|
208
|
+
# == Example
|
|
92
209
|
#
|
|
93
|
-
# @example
|
|
94
210
|
# text_component.text "Long text..."
|
|
95
211
|
# text_component.wrap! # Enables text wrapping
|
|
96
|
-
#
|
|
97
|
-
# @return [true]
|
|
98
212
|
def wrap!
|
|
99
213
|
wrap(true) # Use the setter generated by `option`
|
|
100
214
|
end
|
|
101
215
|
|
|
216
|
+
# Adds a Span component to this text component's contents.
|
|
217
|
+
#
|
|
218
|
+
# Spans allow different styling for parts of the text, such as color,
|
|
219
|
+
# weight, size, and decoration.
|
|
220
|
+
#
|
|
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
|
+
#
|
|
230
|
+
# text "Message with spans:" do
|
|
231
|
+
# span "Important", color: "#FF0000", weight: :bold
|
|
232
|
+
# span " normal text"
|
|
233
|
+
# end
|
|
234
|
+
def span(text_content, **options, &)
|
|
235
|
+
@contents << Span.new(text_content, context: @context, **options, &)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# :nodoc:
|
|
239
|
+
def any_content?
|
|
240
|
+
!contents.empty? || !text.nil?
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# :nodoc:
|
|
102
244
|
def to_h
|
|
103
|
-
raise RequiredError, "text content is required for a text component"
|
|
245
|
+
raise RequiredError, "text content is required for a text component" unless any_content?
|
|
104
246
|
|
|
105
247
|
return to_sdkv2 if context.sdkv2?
|
|
106
248
|
|
|
@@ -109,13 +251,20 @@ module Line
|
|
|
109
251
|
|
|
110
252
|
private
|
|
111
253
|
|
|
254
|
+
# :nodoc:
|
|
112
255
|
def to_api # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
113
256
|
{
|
|
114
257
|
type: "text",
|
|
115
258
|
text: text,
|
|
259
|
+
contents: contents.map(&:to_h), # Convert spans to hash
|
|
116
260
|
wrap: wrap, # From option
|
|
117
261
|
color: color, # From option
|
|
118
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
|
|
119
268
|
# Position::Horizontal & Position::Vertical
|
|
120
269
|
align: align, # From Position::Horizontal
|
|
121
270
|
gravity: gravity, # From Position::Vertical
|
|
@@ -137,13 +286,20 @@ module Line
|
|
|
137
286
|
}.compact
|
|
138
287
|
end
|
|
139
288
|
|
|
289
|
+
# :nodoc:
|
|
140
290
|
def to_sdkv2 # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
141
291
|
{
|
|
142
292
|
type: "text",
|
|
143
293
|
text: text,
|
|
294
|
+
contents: contents.map(&:to_h), # Convert spans to hash
|
|
144
295
|
wrap: wrap, # From option
|
|
145
296
|
color: color, # From option
|
|
146
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
|
|
147
303
|
# Position::Horizontal & Position::Vertical
|
|
148
304
|
align: align, # From Position::Horizontal
|
|
149
305
|
gravity: gravity, # From Position::Vertical
|
|
@@ -3,46 +3,48 @@
|
|
|
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
27
|
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
28
|
+
# == Example
|
|
29
|
+
#
|
|
30
|
+
# Line::Message::Builder.with do
|
|
31
|
+
# # This +flex+ call on root_container would utilize Flex::Builder
|
|
32
|
+
# flex alt_text: "My Flex Message" do
|
|
33
|
+
# bubble do
|
|
33
34
|
# # ... define bubble content ...
|
|
34
35
|
# end
|
|
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,9 @@ 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
|
|
70
|
+
require_relative "flex/separator" # Visual separator
|
|
71
|
+
require_relative "flex/span" # Text span for styling parts of text
|
|
67
72
|
end
|
|
68
73
|
end
|
|
69
74
|
end
|