jekyll-csvy 0.3 → 0.4
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 +8 -8
- data/lib/jekyll-csvy.rb +19 -10
- data/lib/jekyll-csvy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Nzg1YTQ4NzlkYTZjMGU1MmE0OWEwODNlYTBkNjQwZGMzMmIwN2Y5OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2RmYjYyYzg5MGQwNjdmNWZmYTk0YzllMzMyZTIzZTMwZjhkMDZkNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWEyMjhlZWY0NTM0Nzk1NDAxZDM2MTlkODJjMDBjZTI3ODRhMzNiODk2NTI3
|
10
|
+
ZmRlZTc3MWNiYWYzMzVlZGNmYmQwZGFhNjc4MGM0NjgzYzI3N2ZmZDk4ZDIw
|
11
|
+
ODg4ODNiMjlhZjVmYjIxYTQyNTMyNDJiNzI4N2Q4MTVmODU2N2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTJmYWUwNDYzZjJmMWY1ZTczNjQ2N2YwNmJlNWNhYjQwMWEwZDIwNWY0Mjk5
|
14
|
+
NzI3MzA2NGU5NzA4MmRiZDc1NDM5ZDQ0ZjBiZGYxNjg1NTljZjIyYjA2OWM3
|
15
|
+
M2E3MDk1ZTY4ZmQzOWE3YTYyZGZkNjY3NTIzODgyYzE5MWFlNjA=
|
data/lib/jekyll-csvy.rb
CHANGED
@@ -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
|
-
#
|
50
|
-
|
51
|
-
|
52
|
+
# rows
|
53
|
+
rows.each_with_index do |row,i|
|
54
|
+
delimiter = i == 0 ? "=" : "-"
|
52
55
|
|
53
|
-
|
54
|
-
|
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
|
65
|
-
|
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("+")
|
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
|
data/lib/jekyll-csvy/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|