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
|
@@ -8,54 +8,73 @@ module Line
|
|
|
8
8
|
# A bubble is a self-contained unit of content, structured into optional
|
|
9
9
|
# sections: header, hero (an image or box), body, and footer.
|
|
10
10
|
# Bubbles are the fundamental building blocks for single Flex Messages or
|
|
11
|
-
# for each item in a
|
|
11
|
+
# for each item in a Carousel container.
|
|
12
12
|
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
13
|
+
# == Example: Creating a simple bubble with a body
|
|
14
|
+
#
|
|
15
|
+
# Line::Message::Builder.with do
|
|
16
|
+
# flex alt_text: "Simple Bubble" do
|
|
17
|
+
# bubble do
|
|
18
|
+
# body do
|
|
19
|
+
# text "Hello, this is a bubble!"
|
|
19
20
|
# end
|
|
20
21
|
# end
|
|
21
22
|
# end
|
|
22
23
|
# end
|
|
23
24
|
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
25
|
+
# See also:
|
|
26
|
+
# - https://developers.line.biz/en/reference/messaging-api/#bubble
|
|
27
|
+
# - HasPartial
|
|
28
|
+
# - Box
|
|
29
|
+
# - Image
|
|
28
30
|
class Bubble < Line::Message::Builder::Base
|
|
29
31
|
include HasPartial # Allows including predefined partial component sets into sections.
|
|
30
32
|
|
|
33
|
+
# :method: size
|
|
34
|
+
#
|
|
35
|
+
# :call-seq:
|
|
36
|
+
# size() -> Symbol, String, or nil
|
|
37
|
+
# size(value) -> Symbol, String, or nil
|
|
38
|
+
#
|
|
31
39
|
# Specifies the size of the bubble.
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
40
|
+
#
|
|
41
|
+
# [value]
|
|
42
|
+
# Bubble size. Keywords: <code>:nano</code>, <code>:micro</code>,
|
|
43
|
+
# <code>:kilo</code>, <code>:mega</code>, <code>:giga</code>.
|
|
44
|
+
# Pixel/percentage values are not directly supported for bubble
|
|
45
|
+
# size by LINE; use keywords.
|
|
37
46
|
option :size, default: nil # E.g., :nano, :micro, :kilo, :mega, :giga
|
|
38
47
|
|
|
48
|
+
# :method: styles
|
|
49
|
+
#
|
|
50
|
+
# :call-seq:
|
|
51
|
+
# styles() -> Hash or nil
|
|
52
|
+
# styles(value) -> Hash or nil
|
|
53
|
+
#
|
|
39
54
|
# Defines custom styles for the bubble and its sections (header, hero, body, footer).
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
55
|
+
#
|
|
56
|
+
# [value]
|
|
57
|
+
# A hash defining style overrides. See LINE API documentation
|
|
58
|
+
# for the structure of the styles object.
|
|
59
|
+
#
|
|
60
|
+
# == Example
|
|
61
|
+
#
|
|
62
|
+
# bubble.styles(
|
|
63
|
+
# header: { backgroundColor: "#FF0000" },
|
|
64
|
+
# body: { separator: true, separatorColor: "#00FF00" }
|
|
65
|
+
# )
|
|
49
66
|
option :styles, default: nil
|
|
50
67
|
|
|
51
68
|
# Initializes a new Flex Message Bubble container.
|
|
52
69
|
# The provided block is instance-eval'd, allowing DSL methods for defining
|
|
53
|
-
# sections (e.g.,
|
|
70
|
+
# sections (e.g., #header, #body) to be called.
|
|
54
71
|
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
72
|
+
# [context]
|
|
73
|
+
# An optional context for the builder.
|
|
74
|
+
# [option]
|
|
75
|
+
# A hash of options to set instance variables (e.g., <code>:size</code>, <code>:styles</code>).
|
|
76
|
+
# [block]
|
|
77
|
+
# A block to define the sections of this bubble.
|
|
59
78
|
def initialize(context: nil, **options, &)
|
|
60
79
|
@header = nil
|
|
61
80
|
@hero = nil
|
|
@@ -65,57 +84,64 @@ module Line
|
|
|
65
84
|
super # Calls Base#initialize, sets options, and evals block
|
|
66
85
|
end
|
|
67
86
|
|
|
68
|
-
# Defines the header section of the bubble using a
|
|
87
|
+
# Defines the header section of the bubble using a Box component.
|
|
69
88
|
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
89
|
+
# [option]
|
|
90
|
+
# Options for the header Box. See Box#initialize.
|
|
91
|
+
# [block]
|
|
92
|
+
# A block to define the contents of the header Box.
|
|
73
93
|
def header(**options, &)
|
|
74
94
|
@header = Box.new(**options, context: context, &)
|
|
75
95
|
end
|
|
76
96
|
|
|
77
|
-
# Defines the hero section of the bubble using a
|
|
97
|
+
# Defines the hero section of the bubble using a Box component.
|
|
78
98
|
# The hero section is typically used for prominent content like a large image or video.
|
|
79
99
|
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
100
|
+
# [option]
|
|
101
|
+
# Options for the hero Box. See Box#initialize.
|
|
102
|
+
# [block]
|
|
103
|
+
# A block to define the contents of the hero Box.
|
|
83
104
|
def hero(**options, &)
|
|
84
105
|
@hero = Box.new(**options, context: context, &)
|
|
85
106
|
end
|
|
86
107
|
|
|
87
|
-
# Defines the hero section of the bubble using an
|
|
108
|
+
# Defines the hero section of the bubble using an Image component.
|
|
88
109
|
# This is a convenience method for common cases where the hero is a single image.
|
|
89
110
|
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
#
|
|
111
|
+
# [url]
|
|
112
|
+
# The URL of the image.
|
|
113
|
+
# [option]
|
|
114
|
+
# Options for the Image component. See Image#initialize.
|
|
115
|
+
# [block]
|
|
116
|
+
# An optional block for the Image component (e.g., for an action).
|
|
94
117
|
def hero_image(url, **options, &)
|
|
95
118
|
@hero = Image.new(url, **options, context: context, &)
|
|
96
119
|
end
|
|
97
120
|
|
|
98
|
-
# Defines the body section of the bubble using a
|
|
121
|
+
# Defines the body section of the bubble using a Box component.
|
|
99
122
|
# This is the main content area of the bubble.
|
|
100
123
|
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
124
|
+
# [option]
|
|
125
|
+
# Options for the body Box. See Box#initialize.
|
|
126
|
+
# [block]
|
|
127
|
+
# A block to define the contents of the body Box.
|
|
104
128
|
def body(**options, &)
|
|
105
129
|
@body = Box.new(**options, context: context, &)
|
|
106
130
|
end
|
|
107
131
|
|
|
108
|
-
# Defines the footer section of the bubble using a
|
|
132
|
+
# Defines the footer section of the bubble using a Box component.
|
|
109
133
|
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
134
|
+
# [option]
|
|
135
|
+
# Options for the footer Box. See Box#initialize.
|
|
136
|
+
# [block]
|
|
137
|
+
# A block to define the contents of the footer Box.
|
|
113
138
|
def footer(**options, &)
|
|
114
139
|
@footer = Box.new(**options, context: context, &)
|
|
115
140
|
end
|
|
116
141
|
|
|
117
142
|
private
|
|
118
143
|
|
|
144
|
+
# :nodoc:
|
|
119
145
|
def to_api
|
|
120
146
|
{
|
|
121
147
|
type: "bubble",
|
|
@@ -128,6 +154,7 @@ module Line
|
|
|
128
154
|
}.compact
|
|
129
155
|
end
|
|
130
156
|
|
|
157
|
+
# :nodoc:
|
|
131
158
|
def to_sdkv2
|
|
132
159
|
{
|
|
133
160
|
type: "bubble",
|
|
@@ -4,50 +4,59 @@ module Line
|
|
|
4
4
|
module Message
|
|
5
5
|
module Builder
|
|
6
6
|
module Flex
|
|
7
|
-
# The
|
|
7
|
+
# The +Builder+ class is the main entry point for constructing a complete
|
|
8
8
|
# LINE Flex Message. A Flex Message is a highly customizable message type
|
|
9
9
|
# that can contain one main content element, which is either a single
|
|
10
|
-
#
|
|
10
|
+
# Bubble or a Carousel of bubbles.
|
|
11
11
|
#
|
|
12
|
-
# This builder requires
|
|
12
|
+
# This builder requires +alt_text+ (alternative text) for accessibility and
|
|
13
13
|
# for display on devices or LINE versions that cannot render Flex Messages.
|
|
14
|
-
# It can also have a
|
|
14
|
+
# It can also have a +quickReply+ attached to it.
|
|
15
15
|
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
16
|
+
# === Example: Creating a Flex Message with a single bubble
|
|
17
|
+
#
|
|
18
|
+
# Line::Message::Builder.with do
|
|
19
|
+
# flex alt_text: "My Product" do
|
|
20
|
+
# flex_builder.bubble size: :giga do
|
|
21
|
+
# hero_image "https://example.com/product.jpg"
|
|
22
|
+
# body do
|
|
23
|
+
# text "Product Name", weight: :bold, size: :xl
|
|
23
24
|
# end
|
|
24
25
|
# end
|
|
25
|
-
#
|
|
26
|
-
#
|
|
26
|
+
# quick_reply do
|
|
27
|
+
# button action: :message, label: "Learn More", text: "Tell me more"
|
|
27
28
|
# end
|
|
28
29
|
# end
|
|
29
30
|
# end
|
|
30
31
|
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
32
|
+
# See also:
|
|
33
|
+
# - https://developers.line.biz/en/reference/messaging-api/#flex-messages
|
|
34
|
+
# - Bubble
|
|
35
|
+
# - Carousel
|
|
36
|
+
# - QuickReply
|
|
35
37
|
class Builder < Line::Message::Builder::Base
|
|
36
38
|
# Alternative text for the Flex Message. Displayed on devices that
|
|
37
39
|
# cannot render Flex Messages or used for accessibility.
|
|
38
40
|
# This is a required field for a valid Flex Message.
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
41
|
+
#
|
|
42
|
+
# :method: alt_text
|
|
43
|
+
# :call-seq:
|
|
44
|
+
# alt_text(value) -> String, nil
|
|
45
|
+
#
|
|
46
|
+
# [value]
|
|
47
|
+
# The alternative text. Max 400 characters.
|
|
42
48
|
option :alt_text, default: nil
|
|
43
49
|
|
|
44
50
|
# Initializes a new Flex Message Builder.
|
|
45
51
|
# The provided block is instance-eval'd, allowing DSL methods like
|
|
46
|
-
#
|
|
52
|
+
# #bubble or #carousel to define the main content.
|
|
47
53
|
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
54
|
+
# [context]
|
|
55
|
+
# An optional context for the builder.
|
|
56
|
+
# [option]
|
|
57
|
+
# A hash of options to set instance variables (e.g., <code>:alt_text</code>).
|
|
58
|
+
# [block]
|
|
59
|
+
# A block to define the content (bubble or carousel)
|
|
51
60
|
# of this Flex Message.
|
|
52
61
|
def initialize(context: nil, **options, &)
|
|
53
62
|
@contents = nil # Will hold either a Bubble or Carousel instance
|
|
@@ -55,29 +64,31 @@ module Line
|
|
|
55
64
|
super # Calls Base#initialize, sets options (like @alt_text), and evals block
|
|
56
65
|
end
|
|
57
66
|
|
|
58
|
-
# Defines the content of this Flex Message as a single
|
|
59
|
-
# If called, this will overwrite any previously defined
|
|
67
|
+
# Defines the content of this Flex Message as a single Bubble.
|
|
68
|
+
# If called, this will overwrite any previously defined +carousel+ content.
|
|
60
69
|
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
70
|
+
# [option]
|
|
71
|
+
# Options for the Bubble. See Bubble#initialize.
|
|
72
|
+
# [block]
|
|
73
|
+
# A block to define the sections of the Bubble.
|
|
64
74
|
def bubble(**options, &)
|
|
65
75
|
@contents = Line::Message::Builder::Flex::Bubble.new(context: context, **options, &)
|
|
66
76
|
end
|
|
67
77
|
|
|
68
|
-
# Defines the content of this Flex Message as a
|
|
69
|
-
# If called, this will overwrite any previously defined
|
|
78
|
+
# Defines the content of this Flex Message as a Carousel of bubbles.
|
|
79
|
+
# If called, this will overwrite any previously defined +bubble+ content.
|
|
70
80
|
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
#
|
|
81
|
+
# [option]
|
|
82
|
+
# Options for the Carousel. See Carousel#initialize.
|
|
83
|
+
# [block]
|
|
84
|
+
# A block to define the bubbles within the Carousel.
|
|
74
85
|
def carousel(**options, &)
|
|
75
86
|
@contents = Line::Message::Builder::Flex::Carousel.new(context: context, **options, &)
|
|
76
87
|
end
|
|
77
88
|
|
|
78
89
|
private
|
|
79
90
|
|
|
80
|
-
def to_api
|
|
91
|
+
def to_api # :nodoc:
|
|
81
92
|
raise Error, "Flex Message contents (bubble or carousel) must be defined." if @contents.nil?
|
|
82
93
|
|
|
83
94
|
{
|
|
@@ -88,7 +99,7 @@ module Line
|
|
|
88
99
|
}.compact
|
|
89
100
|
end
|
|
90
101
|
|
|
91
|
-
def to_sdkv2
|
|
102
|
+
def to_sdkv2 # :nodoc:
|
|
92
103
|
raise Error, "Flex Message contents (bubble or carousel) must be defined." if @contents.nil?
|
|
93
104
|
|
|
94
105
|
{
|
|
@@ -6,73 +6,128 @@ module Line
|
|
|
6
6
|
module Flex
|
|
7
7
|
# Represents a "button" component in a LINE Flex Message.
|
|
8
8
|
#
|
|
9
|
-
# Buttons are interactive elements that users can tap to trigger an
|
|
9
|
+
# Buttons are interactive elements that users can tap to trigger an action
|
|
10
10
|
# (e.g., open a URL, send a message, or trigger a postback). They have
|
|
11
|
-
# various styling options, including
|
|
12
|
-
#
|
|
11
|
+
# various styling options, including +style+ (primary, secondary, link),
|
|
12
|
+
# +color+ and +height+.
|
|
13
13
|
#
|
|
14
14
|
# An action is mandatory for a button component.
|
|
15
15
|
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
16
|
+
# Buttons have no padding properties of their own; use the padding of the
|
|
17
|
+
# surrounding Box to inset a button.
|
|
18
|
+
#
|
|
19
|
+
# == Example
|
|
20
|
+
#
|
|
21
|
+
# Line::Message::Builder.with do
|
|
22
|
+
# flex alt_text: "Button Example" do
|
|
23
|
+
# bubble do
|
|
24
|
+
# body do
|
|
25
|
+
# button style: :primary, height: :sm do
|
|
26
|
+
# message "Buy Now", label: "Buy" # Action definition
|
|
27
|
+
# end
|
|
28
|
+
# end
|
|
29
|
+
# end
|
|
30
|
+
# end
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# === Example: Tinting a primary button
|
|
34
|
+
#
|
|
35
|
+
# Line::Message::Builder.with do
|
|
36
|
+
# flex alt_text: "Button Example" do
|
|
37
|
+
# bubble do
|
|
38
|
+
# body do
|
|
39
|
+
# button style: :primary, color: "#1DB446" do
|
|
40
|
+
# message "Buy Now", label: "Buy"
|
|
23
41
|
# end
|
|
24
42
|
# end
|
|
25
43
|
# end
|
|
26
44
|
# end
|
|
27
45
|
# end
|
|
28
46
|
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
#
|
|
47
|
+
# See also:
|
|
48
|
+
# - https://developers.line.biz/en/reference/messaging-api/#button
|
|
49
|
+
# - Actionable for defining the button's action (mandatory)
|
|
50
|
+
# - Position::Vertical for +gravity+ property
|
|
51
|
+
# - Position::Margin for +margin+ property
|
|
52
|
+
# - Position::Offset for offset properties
|
|
53
|
+
# - Size::Flex for flex sizing property
|
|
54
|
+
# - Size::AdjustMode for +adjust_mode+ property
|
|
37
55
|
class Button < Line::Message::Builder::Base
|
|
38
56
|
include Actionable # Defines the action performed when the button is tapped.
|
|
39
57
|
include Position::Vertical # Adds `gravity` option for vertical alignment.
|
|
40
|
-
include Position::Padding # Adds padding options.
|
|
41
58
|
include Position::Margin # Adds `margin` option.
|
|
42
59
|
include Position::Offset # Adds offset options.
|
|
43
60
|
include Size::Flex # Adds `flex` option for sizing within a parent box.
|
|
44
61
|
include Size::AdjustMode # Adds `adjust_mode` option.
|
|
45
62
|
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
63
|
+
# :method: style
|
|
64
|
+
# :call-seq:
|
|
65
|
+
# style() -> Symbol
|
|
66
|
+
# style(value) -> Symbol
|
|
67
|
+
#
|
|
68
|
+
# Sets or gets the button style.
|
|
69
|
+
#
|
|
70
|
+
# [value]
|
|
71
|
+
# Button style. Can be +:primary+, +:secondary+, or +:link+ (default).
|
|
72
|
+
# String values should match these keywords.
|
|
52
73
|
option :style, default: :link
|
|
53
74
|
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
75
|
+
# :method: height
|
|
76
|
+
# :call-seq:
|
|
77
|
+
# height() -> Symbol
|
|
78
|
+
# height(value) -> Symbol
|
|
79
|
+
#
|
|
80
|
+
# Sets or gets the button height.
|
|
81
|
+
#
|
|
82
|
+
# [value]
|
|
83
|
+
# Button height. Can be +:sm+ (small) or +:md+ (medium, default).
|
|
59
84
|
option :height, default: :md, validator: Validators::Enum.new(:sm, :md)
|
|
60
85
|
|
|
86
|
+
# :method: color
|
|
87
|
+
# :call-seq:
|
|
88
|
+
# color() -> String or nil
|
|
89
|
+
# color(value) -> String
|
|
90
|
+
#
|
|
91
|
+
# Sets or gets the button color. This is the character color when
|
|
92
|
+
# +style+ is <code>:link</code>, and the background color when +style+
|
|
93
|
+
# is <code>:primary</code> or <code>:secondary</code>.
|
|
94
|
+
#
|
|
95
|
+
# [value]
|
|
96
|
+
# Hexadecimal color code (e.g., <code>"#RRGGBB"</code>)
|
|
97
|
+
option :color, default: nil
|
|
98
|
+
|
|
99
|
+
# :method: scaling
|
|
100
|
+
# :call-seq:
|
|
101
|
+
# scaling() -> Boolean or nil
|
|
102
|
+
# scaling(value) -> Boolean
|
|
103
|
+
#
|
|
104
|
+
# Sets or gets whether the label font size follows the font size setting
|
|
105
|
+
# of the LINE app.
|
|
106
|
+
#
|
|
107
|
+
# [value]
|
|
108
|
+
# +true+ to scale the font size, +false+ (default) to keep it fixed
|
|
109
|
+
option :scaling, default: nil
|
|
110
|
+
|
|
61
111
|
# Initializes a new Flex Message Button component.
|
|
112
|
+
#
|
|
62
113
|
# The provided block is instance-eval'd, primarily used to define the
|
|
63
|
-
# button's action using methods from the
|
|
114
|
+
# button's action using methods from the Actionable module (e.g., +message+).
|
|
64
115
|
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
116
|
+
# [context]
|
|
117
|
+
# An optional context for the builder
|
|
118
|
+
# [options]
|
|
119
|
+
# A hash of options to set instance variables
|
|
120
|
+
# (e.g., +:style+, +:height+, and options from included modules)
|
|
121
|
+
# [block]
|
|
122
|
+
# A block to define the button's action and other properties.
|
|
123
|
+
# This block is where you should call an action method like +message+ or +postback+.
|
|
70
124
|
def initialize(context: nil, **options, &)
|
|
71
125
|
super # Calls Base#initialize, sets options, and evals block (which should define the action)
|
|
72
126
|
end
|
|
73
127
|
|
|
74
128
|
private
|
|
75
129
|
|
|
130
|
+
# :nodoc:
|
|
76
131
|
def to_api # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
77
132
|
raise RequiredError, "action is required for a button" if action.nil?
|
|
78
133
|
|
|
@@ -81,14 +136,10 @@ module Line
|
|
|
81
136
|
action: action.to_h, # From Actionable module
|
|
82
137
|
style: style, # From option
|
|
83
138
|
height: height, # From option
|
|
139
|
+
color: color, # From option
|
|
140
|
+
scaling: scaling, # From option
|
|
84
141
|
# Position::Vertical
|
|
85
142
|
gravity: gravity,
|
|
86
|
-
# Position::Padding
|
|
87
|
-
paddingAll: padding || padding_all,
|
|
88
|
-
paddingTop: padding_top,
|
|
89
|
-
paddingBottom: padding_bottom,
|
|
90
|
-
paddingStart: padding_start,
|
|
91
|
-
paddingEnd: padding_end,
|
|
92
143
|
# Position::Margin
|
|
93
144
|
margin: margin,
|
|
94
145
|
# Position::Offset
|
|
@@ -104,6 +155,7 @@ module Line
|
|
|
104
155
|
}.compact
|
|
105
156
|
end
|
|
106
157
|
|
|
158
|
+
# :nodoc:
|
|
107
159
|
def to_sdkv2 # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
108
160
|
raise RequiredError, "action is required for a button" if action.nil?
|
|
109
161
|
|
|
@@ -112,14 +164,10 @@ module Line
|
|
|
112
164
|
action: action.to_h, # From Actionable module
|
|
113
165
|
style: style, # From option
|
|
114
166
|
height: height, # From option
|
|
167
|
+
color: color, # From option
|
|
168
|
+
scaling: scaling, # From option
|
|
115
169
|
# Position::Vertical
|
|
116
170
|
gravity: gravity,
|
|
117
|
-
# Position::Padding
|
|
118
|
-
padding_all: padding || padding_all,
|
|
119
|
-
padding_top: padding_top,
|
|
120
|
-
padding_bottom: padding_bottom,
|
|
121
|
-
padding_start: padding_start,
|
|
122
|
-
padding_end: padding_end,
|
|
123
171
|
# Position::Margin
|
|
124
172
|
margin: margin,
|
|
125
173
|
# Position::Offset
|