slacken 0.1.2 → 0.1.3
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 +19 -8
- data/lib/slacken/version.rb +1 -1
- data/spec/slacken_spec.rb +30 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 748574f85629230126187b4628430c5d8831f491
|
4
|
+
data.tar.gz: 8dfea56b37ed82aac7597ce7fd33fe3ed87b98dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fbccd9ac94194719631dff4cef4d5ed07fecad897b6b55169162a0bb828c5d3b3ab1947595eb223f74d0c8283f4ed91f36ec9f1cca2a42dd7b6b489b9059f60
|
7
|
+
data.tar.gz: c5f1cf5dca2d0c5fb4cc24055a02a94101e3b46d8ed76652ab0c9605594a0ae1cccf1d95041cef1cc74bc5175291e209ef23bfd4c3dd28716442aa5edec0ad3f
|
@@ -2,22 +2,33 @@ require 'kosi'
|
|
2
2
|
|
3
3
|
module Slacken
|
4
4
|
class TableElement
|
5
|
-
attr_reader :header, :columns
|
6
5
|
def initialize(children)
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if children.first.type.name == :thead
|
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
|
10
14
|
end
|
11
15
|
|
12
16
|
def render
|
13
|
-
|
14
|
-
body = columns.map { |cl| cl.children.map(&:to_s) }
|
15
|
-
table = Kosi::Table.new(header: head).render(body)
|
16
|
-
table.to_s.chomp
|
17
|
+
Kosi::Table.new(table_head).render(table_body).to_s.chomp
|
17
18
|
end
|
18
19
|
|
19
20
|
def to_s
|
20
21
|
render
|
21
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def table_head
|
27
|
+
@header ? { header: @header.children.map(&:to_s) } : {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def table_body
|
31
|
+
@columns.map { |column| column.children.map(&:to_s) }
|
32
|
+
end
|
22
33
|
end
|
23
34
|
end
|
data/lib/slacken/version.rb
CHANGED
data/spec/slacken_spec.rb
CHANGED
@@ -269,6 +269,36 @@ describe Slacken do
|
|
269
269
|
end
|
270
270
|
end
|
271
271
|
|
272
|
+
context 'when table without thead is given' do
|
273
|
+
let(:source) do
|
274
|
+
<<-EOS.unindent
|
275
|
+
<table>
|
276
|
+
<tr>
|
277
|
+
<td>Without</td>
|
278
|
+
</tr>
|
279
|
+
<tr>
|
280
|
+
<td>thead</td>
|
281
|
+
</tr>
|
282
|
+
</table>
|
283
|
+
EOS
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'converts html to table notation' do
|
287
|
+
should eq <<-EOS.unindent.chomp
|
288
|
+
+-------+
|
289
|
+
|Without|
|
290
|
+
|thead |
|
291
|
+
+-------+
|
292
|
+
EOS
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context 'when empty table is given' do
|
297
|
+
let(:source) { '<table></table>' }
|
298
|
+
|
299
|
+
it { should eq '' }
|
300
|
+
end
|
301
|
+
|
272
302
|
context 'when img is given' do
|
273
303
|
let(:source) { "<p><img src='#{src}' alt='#{alt}'></p>" }
|
274
304
|
let(:src) { 'http://cdn.qiita.com/logo.png' }
|