kamiflex 0.11.7 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -32
- data/lib/kamiflex.rb +15 -14
- data/lib/kamiflex/actions.rb +11 -6
- data/lib/kamiflex/basic_elements.rb +15 -6
- data/lib/kamiflex/core.rb +10 -6
- data/lib/kamiflex/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f3a0c28faa7246ac46c30d299399e4a052238fd65ffbcf3876f3d212b5f8c7a
|
4
|
+
data.tar.gz: 23cff523a92f3eaa2519a295a4c29f31c2306a45016e3fa7e6cd9b5017637ffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb297062b3e7037e25079f35597a616021a51d13244d6d157a1f71d2d04d38ec6af4cff3e6ed9c8ae3dba608c6fc360bd9878b7f62e0162f3678f292724ccd5c
|
7
|
+
data.tar.gz: 73de7d71fad0c304d603e8f1899f699abcf050e6f82ec9e0e72ab1d877bb0690eac743898c54c34a58fc79988fa88b1940ca47651da1f444f703d615fed80202
|
data/README.md
CHANGED
@@ -2,43 +2,75 @@
|
|
2
2
|
Kamiflex provide a pretty DSL to build your [flex message of line messaging api](https://developers.line.biz/en/docs/messaging-api/using-flex-messages/) like this:
|
3
3
|
|
4
4
|
#### in pure ruby
|
5
|
+
|
6
|
+
# [example/show_cases/cards.rb](example/show_cases/cards.rb)
|
7
|
+
|
5
8
|
``` ruby
|
6
|
-
# example/todos_index.rb
|
7
9
|
require 'kamiflex'
|
8
10
|
|
9
|
-
@
|
11
|
+
@products = [
|
10
12
|
{
|
11
|
-
|
12
|
-
|
13
|
+
name: "kamigo",
|
14
|
+
star: 4,
|
15
|
+
place: "https://github.com/etrex/kamigo",
|
16
|
+
time: "10:00 - 23:00",
|
17
|
+
contact_url: "https://github.com/etrex/kamigo",
|
18
|
+
product_url: "https://github.com/etrex/kamigo"
|
13
19
|
},
|
14
20
|
{
|
15
|
-
|
16
|
-
|
21
|
+
name: "kamiliff",
|
22
|
+
star: 3,
|
23
|
+
place: "https://github.com/etrex/kamiliff",
|
24
|
+
time: "11:00 - 23:00",
|
25
|
+
contact_url: "https://github.com/etrex/kamiliff",
|
26
|
+
product_url: "https://github.com/etrex/kamiliff"
|
17
27
|
},
|
18
28
|
{
|
19
|
-
|
20
|
-
|
21
|
-
|
29
|
+
name: "kamiflex",
|
30
|
+
star: 5,
|
31
|
+
place: "https://github.com/etrex/kamiflex",
|
32
|
+
time: "09:00 - 23:00",
|
33
|
+
contact_url: "https://github.com/etrex/kamiflex",
|
34
|
+
product_url: "https://github.com/etrex/kamiflex"
|
35
|
+
},
|
22
36
|
]
|
23
37
|
|
38
|
+
def star(num)
|
39
|
+
baseline_box margin: :md do
|
40
|
+
(0...num).each do
|
41
|
+
icon "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", size: :sm
|
42
|
+
end
|
43
|
+
(num...5).each do
|
44
|
+
icon "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png", size: :sm
|
45
|
+
end
|
46
|
+
text "#{num}.0", size: :sm, color: "#999999", margin: :md, flex: 0
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def field(key, value)
|
51
|
+
baseline_box spacing: :sm do
|
52
|
+
text key, "color":"#aaaaaa","size":"sm","flex":1
|
53
|
+
text value, "wrap":true,"color":"#666666","size":"sm","flex":5
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
24
57
|
json = Kamiflex.build(self) do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
text
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
horizontal_box @todos, margin: "lg" do |todo|
|
36
|
-
text todo[:name], action: message_action("/todos/#{todo[:id]}")
|
37
|
-
text "❌", align: "end", action: message_action("DELETE /todos/#{todo[:id]}")
|
38
|
-
end
|
58
|
+
carousel do
|
59
|
+
bubbles @products do |product|
|
60
|
+
hero "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png",
|
61
|
+
size: :full, aspectRatio: "20:13", aspectMode: :cover, action: uri_action("http://linecorp.com/")
|
62
|
+
body do
|
63
|
+
text product[:name], weight: :bold, size: :xl
|
64
|
+
star(product[:star])
|
65
|
+
vertical_box margin: :lg, spacing: :sm do
|
66
|
+
field "Place", product[:place]
|
67
|
+
field "Time", product[:time]
|
39
68
|
end
|
40
|
-
|
41
|
-
|
69
|
+
end
|
70
|
+
footer spacing: :sm, flex: 0 do
|
71
|
+
url_button "CALL", product[:contact_url], style: :link, height: :sm
|
72
|
+
url_button "WEBSITE", product[:product_url], style: :link, height: :sm
|
73
|
+
spacer size: :sm
|
42
74
|
end
|
43
75
|
end
|
44
76
|
end
|
@@ -47,20 +79,18 @@ end
|
|
47
79
|
puts json
|
48
80
|
```
|
49
81
|
|
50
|
-
|
51
|
-
|
52
|
-
![](image/todos_index.png)
|
82
|
+
![](image/show_cases/cards.png)
|
53
83
|
|
54
84
|
#### in rails
|
55
85
|
``` ruby
|
56
86
|
# todos/index.line.erb
|
57
|
-
<%= raw
|
87
|
+
<%= raw Kamiflex.build(self) do
|
58
88
|
bubble do
|
59
89
|
body do
|
60
90
|
horizontal_box do
|
61
91
|
text "🍔", flex: 0, action: message_action("/")
|
62
92
|
text "Todos"
|
63
|
-
text "🆕", align: "end", action: uri_action(new_todo_path)
|
93
|
+
text "🆕", align: "end", action: uri_action(new_todo_path)
|
64
94
|
end
|
65
95
|
separator
|
66
96
|
if @todos.present?
|
@@ -75,7 +105,7 @@ The render result looks like this:
|
|
75
105
|
end
|
76
106
|
end
|
77
107
|
end
|
78
|
-
end
|
108
|
+
end %>
|
79
109
|
```
|
80
110
|
|
81
111
|
I will make a template name `flex` for rails in the future.
|
@@ -89,7 +119,7 @@ bubble do
|
|
89
119
|
horizontal_box do
|
90
120
|
text "🍔", flex: 0, action: message_action("/")
|
91
121
|
text "Todos"
|
92
|
-
text "🆕", align: "end", action: uri_action(new_todo_path)
|
122
|
+
text "🆕", align: "end", action: uri_action(new_todo_path)
|
93
123
|
end
|
94
124
|
separator
|
95
125
|
if @todos.present?
|
data/lib/kamiflex.rb
CHANGED
@@ -6,7 +6,7 @@ require_relative "./kamiflex/quick_reply"
|
|
6
6
|
require_relative "./kamiflex/custom"
|
7
7
|
|
8
8
|
module Kamiflex
|
9
|
-
def self.
|
9
|
+
def self.hash(parent, &block)
|
10
10
|
parent.class.include Kamiflex::Core
|
11
11
|
parent.class.include Kamiflex::BasicElements
|
12
12
|
parent.class.include Kamiflex::Actions
|
@@ -15,24 +15,25 @@ module Kamiflex
|
|
15
15
|
|
16
16
|
parent.instance_exec do
|
17
17
|
flex do
|
18
|
-
|
18
|
+
parent.instance_exec(&block)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.
|
24
|
-
parent
|
25
|
-
|
26
|
-
parent.class.include Kamiflex::Actions
|
27
|
-
parent.class.include Kamiflex::QuickReply
|
28
|
-
parent.class.include Kamiflex::Custom
|
23
|
+
def self.to_hash(parent, &block)
|
24
|
+
self.hash(parent, &block)
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def self.build(parent, &block)
|
28
|
+
JSON.pretty_generate self.hash(parent, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.json(parent, &block)
|
32
|
+
self.build(parent, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.compact_json(parent, &block)
|
36
|
+
self.to_hash(parent, &block).to_json
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
data/lib/kamiflex/actions.rb
CHANGED
@@ -4,19 +4,24 @@ module Kamiflex
|
|
4
4
|
{
|
5
5
|
type: "message",
|
6
6
|
label: label,
|
7
|
-
text: label
|
7
|
+
text: params[:text] || label
|
8
8
|
}.merge(params)
|
9
9
|
end
|
10
10
|
|
11
11
|
def uri_action(uri, **params)
|
12
|
-
{
|
12
|
+
action = {
|
13
13
|
type: "uri",
|
14
14
|
label: uri[0...40],
|
15
|
-
uri: uri
|
16
|
-
# altUri: {
|
17
|
-
# desktop: uri
|
18
|
-
# }
|
15
|
+
uri: uri
|
19
16
|
}
|
17
|
+
|
18
|
+
if params[:desktop].present?
|
19
|
+
action[:altUri] = {
|
20
|
+
desktop: params[:desktop]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
action
|
20
25
|
end
|
21
26
|
|
22
27
|
def postback_action(data, **params)
|
@@ -43,13 +43,22 @@ module Kamiflex
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def url_button(label, url, **params)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
action = {
|
47
|
+
type: "uri",
|
48
|
+
label: label,
|
49
|
+
uri: url,
|
50
|
+
}
|
51
|
+
|
52
|
+
if params[:desktop].present?
|
53
|
+
action[:altUri] = {
|
54
|
+
desktop: params[:desktop]
|
52
55
|
}
|
56
|
+
params = params.reject {|key, value| key == :desktop }
|
57
|
+
end
|
58
|
+
|
59
|
+
@flex_contents << {
|
60
|
+
type: "button",
|
61
|
+
action: action
|
53
62
|
}.merge(params)
|
54
63
|
end
|
55
64
|
|
data/lib/kamiflex/core.rb
CHANGED
@@ -6,7 +6,7 @@ module Kamiflex
|
|
6
6
|
type: "flex",
|
7
7
|
altText: "this is a flex message",
|
8
8
|
contents: _contents.first
|
9
|
-
}.merge(attributes.slice(:quickReply))
|
9
|
+
}.merge(attributes.slice(:quickReply, :altText))
|
10
10
|
end
|
11
11
|
|
12
12
|
def bubble(**params)
|
@@ -70,6 +70,15 @@ module Kamiflex
|
|
70
70
|
}.merge(params)
|
71
71
|
end
|
72
72
|
|
73
|
+
# style
|
74
|
+
def styles(params)
|
75
|
+
@flex_attributes[:styles] = params
|
76
|
+
end
|
77
|
+
|
78
|
+
def alt_text(text)
|
79
|
+
@flex_attributes[:altText] = text
|
80
|
+
end
|
81
|
+
|
73
82
|
# container
|
74
83
|
def horizontal_box(resources = [nil], **params)
|
75
84
|
resources.each_with_index do |resource, index|
|
@@ -82,11 +91,6 @@ module Kamiflex
|
|
82
91
|
end
|
83
92
|
end
|
84
93
|
|
85
|
-
# style
|
86
|
-
def styles(params)
|
87
|
-
@flex_attributes[:styles] = params
|
88
|
-
end
|
89
|
-
|
90
94
|
def vertical_box(resources = [nil], **params, &block)
|
91
95
|
horizontal_box(resources, layout: "vertical", **params, &block)
|
92
96
|
end
|
data/lib/kamiflex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kamiflex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- etrex kuo
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -49,7 +49,7 @@ licenses:
|
|
49
49
|
- MIT
|
50
50
|
metadata:
|
51
51
|
allowed_push_host: https://rubygems.org
|
52
|
-
post_install_message:
|
52
|
+
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
@@ -64,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
67
|
+
rubygems_version: 3.1.2
|
68
|
+
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: 'Kamiflex: generate JSON objects for Line flex message with a Builder-style
|
71
71
|
DSL'
|