line-message-builder 0.5.0 → 0.6.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/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/line/message/builder/flex/box.rb +12 -2
- data/lib/line/message/builder/flex/builder.rb +4 -0
- data/lib/line/message/builder/flex/button.rb +8 -4
- data/lib/line/message/builder/flex/carousel.rb +32 -0
- data/lib/line/message/builder/flex/image.rb +5 -3
- data/lib/line/message/builder/flex/position.rb +3 -3
- data/lib/line/message/builder/flex/size.rb +52 -0
- data/lib/line/message/builder/flex/text.rb +10 -5
- data/lib/line/message/builder/flex.rb +2 -0
- data/lib/line/message/builder/validators/size.rb +27 -14
- data/lib/line/message/builder/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3ed7258b9de88098b6e78ff9165c4ab4b07b5328a294106f78e3cbed16b0725
|
4
|
+
data.tar.gz: fee080b8a5c4799a9a0859cd12b42bbc32d9797ee7906b07d65a80bc882040ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5016cdac5849c4f6931b5e6810abfcbffec6ef337fecb3461c19a4af507b6bc7fbd4c8cc79ab8770183c9ecaa5403efd52686bbf4525d9c0996cf200d966acb5
|
7
|
+
data.tar.gz: 93da8212a3282dd64587679151f8b2a08d6523f60ecd32e765bb045ccae98b110ca92352402d5217d870a6405e05dd9c167b55707a47ccdef98dde2e604d469c
|
@@ -1 +1 @@
|
|
1
|
-
{".":"0.
|
1
|
+
{".":"0.6.0"}
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.6.0](https://github.com/elct9620/line-message-builder/compare/v0.5.0...v0.6.0) (2025-04-07)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* Add Flex carousel support for Line message builder ([757b16d](https://github.com/elct9620/line-message-builder/commit/757b16d2f71ff14cff39aa1990773851bc78192b))
|
9
|
+
* Add height and max_height options to flex box with validation ([932c743](https://github.com/elct9620/line-message-builder/commit/932c7435ea11a3dec7903ffa19c48a5987231e39))
|
10
|
+
* Add shrink-to-fit adjust mode for flex buttons and texts ([b3ce3a2](https://github.com/elct9620/line-message-builder/commit/b3ce3a29614514b3049d5b6ad718b3dbcd283898))
|
11
|
+
* Add width and max_width options to flex box builder ([3d20c98](https://github.com/elct9620/line-message-builder/commit/3d20c98e670f49fad3f35c93d88364fb7f14afc0))
|
12
|
+
|
3
13
|
## [0.5.0](https://github.com/elct9620/line-message-builder/compare/v0.4.0...v0.5.0) (2025-04-07)
|
4
14
|
|
5
15
|
|
data/README.md
CHANGED
@@ -10,6 +10,7 @@ module Line
|
|
10
10
|
include Position::Padding
|
11
11
|
include Position::Margin
|
12
12
|
include Position::Offset
|
13
|
+
include Size::Flex
|
13
14
|
|
14
15
|
attr_reader :contents
|
15
16
|
|
@@ -22,8 +23,11 @@ module Line
|
|
22
23
|
option :align_items, default: nil, validator: Validators::Enum.new(
|
23
24
|
:flex_start, :center, :flex_end
|
24
25
|
)
|
25
|
-
option :spacing, default: nil, validator: Validators::Size.new
|
26
|
-
option :
|
26
|
+
option :spacing, default: nil, validator: Validators::Size.new(:pixel, :keyword)
|
27
|
+
option :width, default: nil, validator: Validators::Size.new(:pixel, :percentage)
|
28
|
+
option :max_width, default: nil, validator: Validators::Size.new(:pixel, :percentage)
|
29
|
+
option :height, default: nil, validator: Validators::Size.new(:pixel, :percentage)
|
30
|
+
option :max_height, default: nil, validator: Validators::Size.new(:pixel, :percentage)
|
27
31
|
|
28
32
|
def initialize(context: nil, **options, &)
|
29
33
|
@contents = []
|
@@ -71,6 +75,12 @@ module Line
|
|
71
75
|
offsetBottom: offset_bottom,
|
72
76
|
offsetStart: offset_start,
|
73
77
|
offsetEnd: offset_end,
|
78
|
+
# Size
|
79
|
+
width: width,
|
80
|
+
maxWidth: max_width,
|
81
|
+
height: height,
|
82
|
+
maxHeight: max_height,
|
83
|
+
# Size::Flex
|
74
84
|
flex: flex,
|
75
85
|
contents: contents.map(&:to_h),
|
76
86
|
action: action&.to_h
|
@@ -18,6 +18,10 @@ module Line
|
|
18
18
|
@contents = Line::Message::Builder::Flex::Bubble.new(context: context, **options, &)
|
19
19
|
end
|
20
20
|
|
21
|
+
def carousel(**options, &)
|
22
|
+
@contents = Line::Message::Builder::Flex::Carousel.new(context: context, **options, &)
|
23
|
+
end
|
24
|
+
|
21
25
|
def to_h
|
22
26
|
raise Error, "contents should be bubble or carousel" if @contents.nil?
|
23
27
|
|
@@ -11,10 +11,11 @@ module Line
|
|
11
11
|
include Position::Padding
|
12
12
|
include Position::Margin
|
13
13
|
include Position::Offset
|
14
|
+
include Size::Flex
|
15
|
+
include Size::AdjustMode
|
14
16
|
|
15
|
-
option :flex, default: nil
|
16
17
|
option :style, default: :link
|
17
|
-
option :height, default: :md
|
18
|
+
option :height, default: :md, validator: Validators::Enum.new(:sm, :md)
|
18
19
|
|
19
20
|
def to_h # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
20
21
|
raise RequiredError, "action is required" if action.nil?
|
@@ -22,6 +23,7 @@ module Line
|
|
22
23
|
{
|
23
24
|
type: "button",
|
24
25
|
action: action.to_h,
|
26
|
+
height: height,
|
25
27
|
# Position
|
26
28
|
grivity: gravity,
|
27
29
|
# Position::Padding
|
@@ -38,9 +40,11 @@ module Line
|
|
38
40
|
offsetBottom: offset_bottom,
|
39
41
|
offsetStart: offset_start,
|
40
42
|
offsetEnd: offset_end,
|
43
|
+
# Size::Flex
|
41
44
|
flex: flex,
|
42
|
-
|
43
|
-
|
45
|
+
# Size::AdjustMode
|
46
|
+
adjustMode: adjust_mode,
|
47
|
+
style: style
|
44
48
|
}.compact
|
45
49
|
end
|
46
50
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Line
|
4
|
+
module Message
|
5
|
+
module Builder
|
6
|
+
module Flex
|
7
|
+
# The carousel is multiple bubbles in a single Flex message.
|
8
|
+
class Carousel < Line::Message::Builder::Base
|
9
|
+
def initialize(context: nil, **options, &)
|
10
|
+
@contents = []
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def bubble(**options, &)
|
16
|
+
@contents << Line::Message::Builder::Flex::Bubble.new(context: context, **options, &)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
raise RequiredError, "contents should have at least 1 bubble" if @contents.empty?
|
21
|
+
raise ValidationError, "contents should have at most 12 bubbles" if @contents.size > 12
|
22
|
+
|
23
|
+
{
|
24
|
+
type: "carousel",
|
25
|
+
contents: @contents.map(&:to_h)
|
26
|
+
}.compact
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -11,13 +11,13 @@ module Line
|
|
11
11
|
include Position::Vertical
|
12
12
|
include Position::Margin
|
13
13
|
include Position::Offset
|
14
|
+
include Size::Flex
|
15
|
+
include Size::Image
|
14
16
|
|
15
17
|
attr_reader :url
|
16
18
|
|
17
|
-
option :size, default: nil
|
18
19
|
option :aspect_ratio, default: nil
|
19
20
|
option :aspect_mode, default: nil
|
20
|
-
option :flex, default: nil
|
21
21
|
|
22
22
|
def initialize(url, context: nil, **options, &)
|
23
23
|
@url = url
|
@@ -42,8 +42,10 @@ module Line
|
|
42
42
|
offsetBottom: offset_bottom,
|
43
43
|
offsetStart: offset_start,
|
44
44
|
offsetEnd: offset_end,
|
45
|
-
|
45
|
+
# Size::Flex
|
46
46
|
flex: flex,
|
47
|
+
# Size::Image
|
48
|
+
size: size,
|
47
49
|
aspectRatio: aspect_ratio,
|
48
50
|
aspectMode: aspect_mode,
|
49
51
|
action: action&.to_h
|
@@ -33,7 +33,7 @@ module Line
|
|
33
33
|
%i[padding padding_top padding_bottom padding_start padding_end].each do |option|
|
34
34
|
base.option option,
|
35
35
|
default: :nil,
|
36
|
-
validator: Validators::
|
36
|
+
validator: Validators::Size.new(:pixel, :keyword, :percentage)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -43,7 +43,7 @@ module Line
|
|
43
43
|
def self.included(base)
|
44
44
|
base.option :margin,
|
45
45
|
default: :nil,
|
46
|
-
validator: Validators::Size.new
|
46
|
+
validator: Validators::Size.new(:pixel, :keyword)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -57,7 +57,7 @@ module Line
|
|
57
57
|
%i[offset_top offset_bottom offset_start offset_end].each do |option|
|
58
58
|
base.option option,
|
59
59
|
default: :nil,
|
60
|
-
validator: Validators::Size.new
|
60
|
+
validator: Validators::Size.new(:pixel, :keyword)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Line
|
4
|
+
module Message
|
5
|
+
module Builder
|
6
|
+
module Flex
|
7
|
+
module Size
|
8
|
+
# The flex size provides "flex" options for flex components.
|
9
|
+
module Flex
|
10
|
+
def self.included(base)
|
11
|
+
base.option :flex,
|
12
|
+
default: :nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# The image provides "size" options for flex image component.
|
17
|
+
module Image
|
18
|
+
def self.included(base)
|
19
|
+
base.option :size,
|
20
|
+
default: :nil,
|
21
|
+
validator: Validators::Size.new(:pixel, :image, :percentage)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# The shared provides "size" options for flex components which is icon, text and span.
|
26
|
+
module Shared
|
27
|
+
def self.included(base)
|
28
|
+
base.option :size,
|
29
|
+
default: :nil,
|
30
|
+
validator: Validators::Size.new(:pixel, :keyword)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# The adjust mode provides "adjust mode" options for flex components.
|
35
|
+
module AdjustMode
|
36
|
+
def self.included(base)
|
37
|
+
base.option :adjust_mode,
|
38
|
+
default: :nil,
|
39
|
+
validator: Validators::Enum.new(
|
40
|
+
:"shrink-to-fit"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
def shrink_to_fit!
|
45
|
+
@adjust_mode = :"shrink-to-fit"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -11,14 +11,15 @@ module Line
|
|
11
11
|
include Position::Vertical
|
12
12
|
include Position::Margin
|
13
13
|
include Position::Offset
|
14
|
+
include Size::Flex
|
15
|
+
include Size::Shared
|
16
|
+
include Size::AdjustMode
|
14
17
|
|
15
18
|
attr_reader :text
|
16
19
|
|
17
|
-
option :size, default: nil
|
18
20
|
option :wrap, default: false
|
19
21
|
option :line_spacing, default: nil
|
20
22
|
option :color, default: nil
|
21
|
-
option :flex, default: nil
|
22
23
|
|
23
24
|
def initialize(text, context: nil, **options, &)
|
24
25
|
@text = text
|
@@ -36,6 +37,7 @@ module Line
|
|
36
37
|
{
|
37
38
|
type: "text",
|
38
39
|
text: text,
|
40
|
+
wrap: wrap,
|
39
41
|
# Position
|
40
42
|
align: align,
|
41
43
|
gravity: gravity,
|
@@ -47,11 +49,14 @@ module Line
|
|
47
49
|
offsetBottom: offset_bottom,
|
48
50
|
offsetStart: offset_start,
|
49
51
|
offsetEnd: offset_end,
|
50
|
-
|
52
|
+
# Size::Flex
|
53
|
+
flex: flex,
|
54
|
+
# Size::Shared
|
55
|
+
size: size,
|
56
|
+
# Size::AdjustMode
|
57
|
+
adjustMode: adjust_mode,
|
51
58
|
lineSpacing: line_spacing,
|
52
59
|
color: color,
|
53
|
-
size: size,
|
54
|
-
flex: flex,
|
55
60
|
action: action&.to_h
|
56
61
|
}.compact
|
57
62
|
end
|
@@ -8,9 +8,11 @@ module Line
|
|
8
8
|
require_relative "flex/builder"
|
9
9
|
require_relative "flex/actionable"
|
10
10
|
require_relative "flex/position"
|
11
|
+
require_relative "flex/size"
|
11
12
|
|
12
13
|
# Container
|
13
14
|
require_relative "flex/bubble"
|
15
|
+
require_relative "flex/carousel"
|
14
16
|
|
15
17
|
# Components
|
16
18
|
require_relative "flex/box"
|
@@ -6,31 +6,44 @@ module Line
|
|
6
6
|
module Validators
|
7
7
|
# Validate size values for LINE messages.
|
8
8
|
class Size
|
9
|
+
VARIANTS = %i[pixel keyword image percentage].freeze
|
9
10
|
KEYWORDS = %i[none xs sm md lg xl xxl].freeze
|
11
|
+
IMAGE_KEYWORDS = %i[xxs xs sm md lg xl xxl 3xl 4xl 5xl full].freeze
|
12
|
+
PIXEL_REGEX = /^\d+px$/
|
13
|
+
PERCENTAGE_REGEX = /^\f+%$/
|
14
|
+
|
15
|
+
def initialize(*variants)
|
16
|
+
@variants = variants & VARIANTS
|
17
|
+
end
|
10
18
|
|
11
19
|
def valid?(value)
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
@variants.any? do |variant|
|
21
|
+
send("#{variant}?", value)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
|
-
def
|
18
|
-
|
25
|
+
def pixel?(value)
|
26
|
+
value.to_s.match?(PIXEL_REGEX)
|
27
|
+
end
|
19
28
|
|
20
|
-
|
21
|
-
|
29
|
+
def keyword?(value)
|
30
|
+
KEYWORDS.include?(value.to_sym)
|
31
|
+
end
|
32
|
+
|
33
|
+
def image?(value)
|
34
|
+
IMAGE_KEYWORDS.include?(value.to_sym)
|
35
|
+
end
|
36
|
+
|
37
|
+
def percentage?(value)
|
38
|
+
value.to_s.match?(PERCENTAGE_REGEX)
|
22
39
|
end
|
23
|
-
end
|
24
40
|
|
25
|
-
# Validate size values with percentage.
|
26
|
-
class PercentageSize < Size
|
27
41
|
def valid!(value)
|
28
|
-
|
29
|
-
return if is_percentage || valid?(value)
|
42
|
+
return if valid?(value)
|
30
43
|
|
31
44
|
raise ValidationError,
|
32
|
-
"Invalid value: #{value}.
|
33
|
-
"
|
45
|
+
"Invalid value: #{value}. " \
|
46
|
+
"Expected one of: #{VARIANTS.join(", ")}"
|
34
47
|
end
|
35
48
|
end
|
36
49
|
end
|
metadata
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: line-message-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aotokitsuruya
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
10
|
date: 2025-04-07 00:00:00.000000000 Z
|
@@ -37,8 +36,10 @@ files:
|
|
37
36
|
- lib/line/message/builder/flex/bubble.rb
|
38
37
|
- lib/line/message/builder/flex/builder.rb
|
39
38
|
- lib/line/message/builder/flex/button.rb
|
39
|
+
- lib/line/message/builder/flex/carousel.rb
|
40
40
|
- lib/line/message/builder/flex/image.rb
|
41
41
|
- lib/line/message/builder/flex/position.rb
|
42
|
+
- lib/line/message/builder/flex/size.rb
|
42
43
|
- lib/line/message/builder/flex/text.rb
|
43
44
|
- lib/line/message/builder/quick_reply.rb
|
44
45
|
- lib/line/message/builder/text.rb
|
@@ -64,7 +65,6 @@ metadata:
|
|
64
65
|
source_code_uri: https://github.com/elct9620/line-message-builder/tree/main
|
65
66
|
changelog_uri: https://github.com/elct9620/line-message-builder/blob/main/CHANGELOG.md
|
66
67
|
rubygems_mfa_required: 'true'
|
67
|
-
post_install_message:
|
68
68
|
rdoc_options: []
|
69
69
|
require_paths:
|
70
70
|
- lib
|
@@ -79,8 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
82
|
+
rubygems_version: 3.6.2
|
84
83
|
specification_version: 4
|
85
84
|
summary: The LINE Messaging API message builder.
|
86
85
|
test_files: []
|