slacken 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slacken/table_element.rb +27 -10
- data/lib/slacken/version.rb +1 -1
- data/spec/slacken_spec.rb +24 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8fc3d24b062a5e3aba15a9db41a869fc831631b
|
4
|
+
data.tar.gz: 0b20ca1fd0b5a57693be55d43a5b1cd7ae46dcfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523fb090a808213aafbd64900dd83f4c7cf13050030fa2de77b0f27e6e0f109199d6b2bd7cb1793992351ae43c0ed8761a6312968b69e154b5cc4015ff8b1ffe
|
7
|
+
data.tar.gz: 182d9d64e2dc63da8b0eeb2a6aa92fe56c18b3db222fe3ec5a4fdcca423d7a8ccde6964f5986f433bd29da46a7282b39575669bb14a8b6feeac80270b46bb1cc
|
@@ -2,15 +2,10 @@ require 'kosi'
|
|
2
2
|
|
3
3
|
module Slacken
|
4
4
|
class TableElement
|
5
|
+
attr_reader :children
|
6
|
+
|
5
7
|
def initialize(children)
|
6
|
-
|
7
|
-
thead, tbody = children.slice(0, 2)
|
8
|
-
@header = thead.child # tr tag
|
9
|
-
@columns = tbody.children # tr tags
|
10
|
-
else
|
11
|
-
@header = nil
|
12
|
-
@columns = children
|
13
|
-
end
|
8
|
+
@children = children
|
14
9
|
end
|
15
10
|
|
16
11
|
def render
|
@@ -24,11 +19,33 @@ module Slacken
|
|
24
19
|
private
|
25
20
|
|
26
21
|
def table_head
|
27
|
-
|
22
|
+
header ? { header: header.children.map(&:to_s) } : {}
|
28
23
|
end
|
29
24
|
|
30
25
|
def table_body
|
31
|
-
|
26
|
+
columns.map { |column| column.children.map(&:to_s) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def header
|
30
|
+
first_child = children.first
|
31
|
+
if first_child.type.name == :thead
|
32
|
+
first_child.child
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def columns
|
39
|
+
if header
|
40
|
+
tbody = children[1]
|
41
|
+
if tbody
|
42
|
+
tbody.children
|
43
|
+
else
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
else
|
47
|
+
children
|
48
|
+
end
|
32
49
|
end
|
33
50
|
end
|
34
51
|
end
|
data/lib/slacken/version.rb
CHANGED
data/spec/slacken_spec.rb
CHANGED
@@ -293,6 +293,30 @@ describe Slacken do
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
+
context 'when table with thead but without tbody is given' do
|
297
|
+
let(:source) do
|
298
|
+
<<-EOS.unindent
|
299
|
+
<table>
|
300
|
+
<thead>
|
301
|
+
<tr>
|
302
|
+
<th>Header1</th>
|
303
|
+
<th>Header2</th>
|
304
|
+
</tr>
|
305
|
+
</thead>
|
306
|
+
</table>
|
307
|
+
EOS
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'converts html to table notation' do
|
311
|
+
should eq <<-EOS.unindent.chomp
|
312
|
+
+-------+-------+
|
313
|
+
|Header1|Header2|
|
314
|
+
+-------+-------+
|
315
|
+
+-------+-------+
|
316
|
+
EOS
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
296
320
|
context 'when empty table is given' do
|
297
321
|
let(:source) { '<table></table>' }
|
298
322
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slacken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomoya Chiba
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
202
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.
|
203
|
+
rubygems_version: 2.5.1
|
204
204
|
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: Translate HTML sources to markup texts for slack
|