jekyll-csvy 0.2 → 0.3

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
- ZTkyYWRiZDU1NTg0YzRmYzM3N2E4ZWM1ZThiZDViZWQ0OTE2YmJhYg==
4
+ ZmEzMTliZTllMjMwYmQ5ZmU3MTQ4NTIzMjNhMDk0ZWUzYzMzMjJmYg==
5
5
  data.tar.gz: !binary |-
6
- ZWVkMWNjODA0ZGZkZWJhZDJjMzE4MmI2ZjI2Yjc3ZDY4ODcyNTE3ZA==
6
+ NDg5ZmE0NzVlM2Y5ZWFkMDk5OTE2MmE0NTk4MmJkYmJjNGNiOWY4Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDI0ZTlhYzBjOWE2ZDBiNjAwNzhiZTNmMGJkNmM3ZmFhM2JiZWViMTE4OTE2
10
- MTUyOTFiNjIwMzIwZTU2YmJiNzk2Yjc5OTEwZTUzNWU1YmM2NmZjMGYxNDE0
11
- ZjZmOTQ3Y2FhYTk4OTRkMzYyYWE5ZmJlZThiNzVmY2QyZmIyNTg=
9
+ OTExNDYyN2M0MmM4ZDcxZTAwMTc2OTE3MDAwNWM3NDIwOTllNWViZTE1ZGJk
10
+ MmEyZDBhNjhiZjk4MDc4NDA5MGIzNDgwODJhOWZmNzU1ZTBiODVlYTYxZmRm
11
+ NjZjODBhZWM4MWI4ODNkNjYyOTk5MGJkMDY0MTRjMDhlYjJlYzM=
12
12
  data.tar.gz: !binary |-
13
- OWYxMGI0MDdkMGNmNjJkNjYyMmUwZTQzZTQxN2JmY2I1YjhjZWQ4NGQwMTlm
14
- YmU1OWNjOTRmMGY0ZGZjYTljMGQwNjk2YmVkZDU3NGIzY2YxZTZmYTlhMWNk
15
- MGE4ODEwMTZhYmEzMzRjZDdjMDg3N2IxYzZhNGM1YzQ0MDcwYjg=
13
+ ZWUxZDVkMTM1Njc4ZTNhN2IyZjA2ZjdjMTE0NDgzNjk2MjA2YjVmMzE0ODhj
14
+ ODA3NmFhNTBjYjlmZWY4MmQyMDM3YTU0NjRjYTA0ZGE3NGRkZDBkNzA3OTAz
15
+ OWExODRhNmQ1NmNiNTlmZGVkMGUzNjJkMDNjMDdjYzE3NGE5MWM=
@@ -1,66 +1,72 @@
1
1
  require 'csv'
2
2
 
3
3
  module Jekyll
4
- module Converters
5
- class Csvy
6
- def initialize(config)
7
- Jekyll::External.require_with_graceful_fail "jekyll-pandoc"
4
+ class Csvy < Converter
5
+ safe true
6
+ priority :low
8
7
 
9
- @config = config
10
- end
8
+ def initialize(config)
9
+ Jekyll::External.require_with_graceful_fail "jekyll-pandoc"
11
10
 
12
- def matches(ext)
13
- ext =~ /^\.csvy$/i
11
+ # requires the Pandoc markdown converter
12
+ # install jekyll-pandoc gem and set "markdown: Pandoc" in _config.yml
13
+ unless config["markdown"] == "Pandoc"
14
+ raise Jekyll::Errors::FatalException, "Pandoc markdown converter required"
14
15
  end
15
16
 
16
- def output_ext(ext)
17
- ".html"
18
- end
17
+ @config = config
18
+ end
19
19
 
20
- def convert(content)
21
- # convert csv content into markdown table using grid table format
22
- content = convert_csv(content)
20
+ def matches(ext)
21
+ ext =~ /^\.csvy$/i
22
+ end
23
23
 
24
- # convert markdown into HTML table
25
- # uses pandoc with the grid_tables extension
26
- site = Jekyll::Site.new(@config)
27
- mkconverter = site.find_converter_instance(::Jekyll::Converters::Markdown)
28
- mkconverter.convert(content)
29
- end
24
+ def output_ext(ext)
25
+ ".html"
26
+ end
30
27
 
31
- def convert_csv(content)
32
- rows = ::CSV.parse(content)
28
+ def convert(content)
29
+ # convert csv content into markdown table using grid table format
30
+ content = convert_csv(content)
33
31
 
34
- # calculate max width of each column
35
- columns = rows.transpose
36
- max_widths = columns.map { |c| c.max_by { |x| x.length }}.map { |c| c.length }
32
+ # convert grid_tables markdown into HTML table using pandoc
33
+ site = Jekyll::Site.new(@config)
34
+ markdown_converter = site.find_converter_instance(Jekyll::Converters::Markdown)
35
+ markdown_converter.convert(content)
36
+ end
37
37
 
38
- # header
39
- table = []
40
- table << separator_row(rows.first, max_widths)
38
+ def convert_csv(content)
39
+ rows = ::CSV.parse(content)
41
40
 
42
- # header row
43
- table << content_row(rows.first, max_widths)
44
- table << separator_row(rows.first, max_widths, delimiter = "=")
41
+ # calculate max width of each column
42
+ columns = rows.transpose
43
+ max_widths = columns.map { |c| c.max_by { |x| x.length }}.map { |c| c.length }
45
44
 
46
- # body rows
47
- rows[1..-1].each do |row|
48
- table << content_row(row, max_widths)
49
- table << separator_row(row, max_widths)
50
- end
45
+ # header
46
+ table = []
47
+ table << separator_row(rows.first, max_widths)
51
48
 
52
- table.join("\n") + "\n"
53
- rescue => e
54
- raise Jekyll::Errors::FatalException, "Conversion failed with error: #{e.message}"
55
- end
49
+ # header row
50
+ table << content_row(rows.first, max_widths)
51
+ table << separator_row(rows.first, max_widths, delimiter = "=")
56
52
 
57
- def content_row(row, max_widths)
58
- row.each_with_index.reduce("|") { |sum, (x,i)| sum + ' ' + x + ' ' * (max_widths[i] - x.length) + " |" }
53
+ # body rows
54
+ rows[1..-1].each do |row|
55
+ table << content_row(row, max_widths)
56
+ table << separator_row(row, max_widths)
59
57
  end
60
58
 
61
- def separator_row(row, max_widths, delimiter = "-")
62
- row.each_with_index.reduce("+") { |sum, (x,i)| sum + delimiter * (max_widths[i] + 2) + "+" }
63
- end
59
+ table.join("\n") + "\n"
60
+ rescue => e
61
+ raise Jekyll::Errors::FatalException, "Conversion failed with error: #{e.message}"
62
+ end
63
+
64
+ def content_row(row, max_widths)
65
+ row.each_with_index.reduce("|") { |sum, (x,i)| sum + ' ' + x + ' ' * (max_widths[i] - x.length) + " |" }
66
+ end
67
+
68
+ def separator_row(row, max_widths, delimiter = "-")
69
+ row.each_with_index.reduce("+") { |sum, (x,i)| sum + delimiter * (max_widths[i] + 2) + "+" }
64
70
  end
65
71
  end
66
72
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllCsvy
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-csvy
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner