jekyll-csvy 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmEzMTliZTllMjMwYmQ5ZmU3MTQ4NTIzMjNhMDk0ZWUzYzMzMjJmYg==
4
+ Nzg1YTQ4NzlkYTZjMGU1MmE0OWEwODNlYTBkNjQwZGMzMmIwN2Y5OA==
5
5
  data.tar.gz: !binary |-
6
- NDg5ZmE0NzVlM2Y5ZWFkMDk5OTE2MmE0NTk4MmJkYmJjNGNiOWY4Zg==
6
+ Y2RmYjYyYzg5MGQwNjdmNWZmYTk0YzllMzMyZTIzZTMwZjhkMDZkNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTExNDYyN2M0MmM4ZDcxZTAwMTc2OTE3MDAwNWM3NDIwOTllNWViZTE1ZGJk
10
- MmEyZDBhNjhiZjk4MDc4NDA5MGIzNDgwODJhOWZmNzU1ZTBiODVlYTYxZmRm
11
- NjZjODBhZWM4MWI4ODNkNjYyOTk5MGJkMDY0MTRjMDhlYjJlYzM=
9
+ ZWEyMjhlZWY0NTM0Nzk1NDAxZDM2MTlkODJjMDBjZTI3ODRhMzNiODk2NTI3
10
+ ZmRlZTc3MWNiYWYzMzVlZGNmYmQwZGFhNjc4MGM0NjgzYzI3N2ZmZDk4ZDIw
11
+ ODg4ODNiMjlhZjVmYjIxYTQyNTMyNDJiNzI4N2Q4MTVmODU2N2U=
12
12
  data.tar.gz: !binary |-
13
- ZWUxZDVkMTM1Njc4ZTNhN2IyZjA2ZjdjMTE0NDgzNjk2MjA2YjVmMzE0ODhj
14
- ODA3NmFhNTBjYjlmZWY4MmQyMDM3YTU0NjRjYTA0ZGE3NGRkZDBkNzA3OTAz
15
- OWExODRhNmQ1NmNiNTlmZGVkMGUzNjJkMDNjMDdjYzE3NGE5MWM=
13
+ YTJmYWUwNDYzZjJmMWY1ZTczNjQ2N2YwNmJlNWNhYjQwMWEwZDIwNWY0Mjk5
14
+ NzI3MzA2NGU5NzA4MmRiZDc1NDM5ZDQ0ZjBiZGYxNjg1NTljZjIyYjA2OWM3
15
+ M2E3MDk1ZTY4ZmQzOWE3YTYyZGZkNjY3NTIzODgyYzE5MWFlNjA=
@@ -38,6 +38,9 @@ module Jekyll
38
38
  def convert_csv(content)
39
39
  rows = ::CSV.parse(content)
40
40
 
41
+ # calculate max height of each row
42
+ max_heights = rows.map { |r| r.max_by { |x| x.lines.count }}.map { |r| r.lines.count }
43
+
41
44
  # calculate max width of each column
42
45
  columns = rows.transpose
43
46
  max_widths = columns.map { |c| c.max_by { |x| x.length }}.map { |c| c.length }
@@ -46,14 +49,12 @@ module Jekyll
46
49
  table = []
47
50
  table << separator_row(rows.first, max_widths)
48
51
 
49
- # header row
50
- table << content_row(rows.first, max_widths)
51
- table << separator_row(rows.first, max_widths, delimiter = "=")
52
+ # rows
53
+ rows.each_with_index do |row,i|
54
+ delimiter = i == 0 ? "=" : "-"
52
55
 
53
- # body rows
54
- rows[1..-1].each do |row|
55
- table << content_row(row, max_widths)
56
- table << separator_row(row, max_widths)
56
+ table += content_rows(row, max_widths, max_heights[i])
57
+ table << separator_row(row, max_widths, delimiter)
57
58
  end
58
59
 
59
60
  table.join("\n") + "\n"
@@ -61,12 +62,20 @@ module Jekyll
61
62
  raise Jekyll::Errors::FatalException, "Conversion failed with error: #{e.message}"
62
63
  end
63
64
 
64
- def content_row(row, max_widths)
65
- row.each_with_index.reduce("|") { |sum, (x,i)| sum + ' ' + x + ' ' * (max_widths[i] - x.length) + " |" }
65
+ def content_rows(row, max_widths, max_height)
66
+ content_row = []
67
+ 0.upto(max_height - 1) do |j|
68
+ content_row << row.each_with_index.reduce("|") do |sum, (x,i)|
69
+ sum + ' ' + x.lines[j].to_s.chomp + ' ' * (max_widths[i] - x.lines[j].to_s.chomp.length) + " |"
70
+ end
71
+ end
72
+ content_row
66
73
  end
67
74
 
68
75
  def separator_row(row, max_widths, delimiter = "-")
69
- row.each_with_index.reduce("+") { |sum, (x,i)| sum + delimiter * (max_widths[i] + 2) + "+" }
76
+ row.each_with_index.reduce("+") do |sum, (x,i)|
77
+ sum + delimiter * (max_widths[i] + 2) + "+"
78
+ end
70
79
  end
71
80
  end
72
81
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllCsvy
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-csvy
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll