slacken 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 25a6903ad8c0859f0fd8140f05528957baf272aa
4
- data.tar.gz: e251a3b49123a5fc4b04d20e07067bdacca79feb
3
+ metadata.gz: 748574f85629230126187b4628430c5d8831f491
4
+ data.tar.gz: 8dfea56b37ed82aac7597ce7fd33fe3ed87b98dc
5
5
  SHA512:
6
- metadata.gz: f603ab28cf2342146a68b18c0b154a8d776036494ff4cbb687ea52fce82745f8eb1091acb1bdb933f73be31d785ca4d30a5c855d5ff285a1ec77a1e50b41457e
7
- data.tar.gz: 188a11057e56f4afb82720fb281e14948449da79a86ae948eb00a1faf7641126505274ab6595e516baa5c80a8b5a47f1aa776ea58919b37f6e97436ce0ac2135
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
- thead, tbody = children.slice(0, 2)
8
- @header = thead.child # tr tag
9
- @columns = tbody.children # tr tags
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
- head = header.children.map(&:to_s)
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
@@ -1,3 +1,3 @@
1
1
  module Slacken
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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' }
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomoya Chiba