kamiflex 0.12.2 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abe7d79a2da6e406553d0ac0affcf3d68e8bfc11eeb708b0491b76da8181a29a
4
- data.tar.gz: 4f17979f04de0cbf1ac0239800c16a12b6ec40280c4d923a78e4fe1de4ecd99b
3
+ metadata.gz: 52be862e9467732b9b74fed2b580fb416a2c406e18c8a95630910d15b9695a05
4
+ data.tar.gz: 8643628033a35ba62060bc5e2483cf62082776b4fd5460d53c5aa953bee11f6d
5
5
  SHA512:
6
- metadata.gz: a7d6689a1430d5f072cd4cf98ce57b94a6ce08f0f67e95e053328ca8c4f1a885ee17393a20d457f80a803d002cdde8aacc39419198a0928a83f6767f5849c656
7
- data.tar.gz: b6ba2c19320da472a198382773329254d10a1900b7e281d8f848776dc818a04e4cab47eb4213afbc0f41031d2884c250db194ddf56e11be5130f639399e5d5e0
6
+ metadata.gz: c1b67b01143a046c2b89c428f259ca4bae19ac29318d2d011c397eef710e7efc0ef3f458ff2fa7a9db7aa53b24c3936cbc425db200c54ad98cdfb6a8c6662854
7
+ data.tar.gz: 61a139760d665f13cd1ee925055383957a939883ca911efc1573977f674c918d2172030a8f0e538b00183e9679eb576c04d40fc5179dbfec978187f1c710da24
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
- @todos = [
11
+ @products = [
10
12
  {
11
- id: 1,
12
- name: "ruby"
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
- id: 2,
16
- name: "rails"
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
- id: 3,
20
- name: "kamiflex"
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
- bubble do
26
- body do
27
- horizontal_box do
28
- text "🍔", flex: 0, action: message_action("/")
29
- text "Todos"
30
- text "🆕", align: "end", action: uri_action(new_todo_path))
31
- end
32
- separator
33
- if @todos.present?
34
- vertical_box margin: "lg" do
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
- else
41
- text "no contents yet", margin: "lg"
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
- The render result looks like this:
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(Kamiflex.build(self) do
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.to_hash(parent)
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
- yield
18
+ parent.instance_exec(&block)
19
19
  end
20
20
  end
21
21
  end
22
22
 
23
- def self.build(parent)
24
- parent.class.include Kamiflex::Core
25
- parent.class.include Kamiflex::BasicElements
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
- hash = parent.instance_exec do
31
- flex do
32
- yield
33
- end
34
- end
35
- JSON.pretty_generate hash
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
 
@@ -4,7 +4,7 @@ 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
 
@@ -1,3 +1,3 @@
1
1
  module Kamiflex
2
- VERSION = '0.12.2'
2
+ VERSION = '0.13.0'
3
3
  end
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.12.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - etrex kuo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-27 00:00:00.000000000 Z
11
+ date: 2021-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json