ruport-wiki-table-formatter 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +1 -0
- data/lib/ruport/wiki_table_formatter/markdown.rb +27 -15
- data/lib/ruport/wiki_table_formatter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ebff419b49dce91bb0b69182a864d7dc8e67b9a32b27a8732a9d8540cc23149
|
4
|
+
data.tar.gz: 8e713cf0ff944391ad834347cba312ec6e78a1f770f24e5084fcc3e3eeddc562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4b7225c682f36b26afdfffd850435231ce0783f31bac0bc6136beb3695d1f24f7ade01e89ca0296f98e54ba1029faeea7578f3f01ce373dcff73b5cd949eae
|
7
|
+
data.tar.gz: 3450aa4d3651cf3c498cb38a60e58eb3ea328ce7f51a941d88b1926b2abf72ad17626c2ff20e9c917a2f928552d5ef50973a1923b6c0b971b56b0b723d73e020
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[](https://badge.fury.io/rb/ruport-wiki-table-formatter)
|
1
2
|
[](https://travis-ci.org/taichi-ishitani/ruport-wiki-table-formatter)
|
2
3
|
[](https://codeclimate.com/github/taichi-ishitani/ruport-wiki-table-formatter/maintainability)
|
3
4
|
[](https://codecov.io/gh/taichi-ishitani/ruport-wiki-table-formatter)
|
@@ -9,7 +9,8 @@ module Ruport
|
|
9
9
|
# Allowed values are :left, :center and :right. Default is :left.
|
10
10
|
#
|
11
11
|
# <tt>:column_alignments:</tt> Alignments for specific columns.
|
12
|
-
# You can configure alignments by using
|
12
|
+
# You can configure alignments by using
|
13
|
+
# Hash (key: column name, value: alignment)
|
13
14
|
class Markdown < Ruport::Formatter
|
14
15
|
renders :markdown, for: [Controller::Table]
|
15
16
|
|
@@ -18,30 +19,41 @@ module Ruport
|
|
18
19
|
apply_table_format_template(template.table)
|
19
20
|
end
|
20
21
|
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
raise Ruport::FormatterError.new(message)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Uses the column names from the given Data::Table to generate a table header.
|
22
|
+
# Uses the column names from the given Data::Table to generate
|
23
|
+
# a table header.
|
24
|
+
# If no column names are given, first row will be
|
25
|
+
# treated as table header.
|
30
26
|
def build_table_header
|
31
|
-
|
32
|
-
build_md_row(output,
|
27
|
+
names = column_names(data)
|
28
|
+
build_md_row(output, names)
|
29
|
+
build_md_row(output, alignment_strings(names))
|
33
30
|
end
|
34
31
|
|
35
32
|
# Generates body of Markdown table data.
|
36
33
|
# Following characters will be replaced as escape.
|
37
|
-
#
|
38
|
-
#
|
34
|
+
#
|
35
|
+
# * | -> |
|
36
|
+
# * newline code(\\n) -> \<br>
|
39
37
|
def build_table_body
|
40
|
-
|
38
|
+
body =
|
39
|
+
if data.column_names && !data.column_names.empty?
|
40
|
+
data
|
41
|
+
else
|
42
|
+
data[1..-1]
|
43
|
+
end
|
44
|
+
body.each { |row| build_md_row(output, row) }
|
41
45
|
end
|
42
46
|
|
43
47
|
private
|
44
48
|
|
49
|
+
def column_names(data)
|
50
|
+
if data.column_names && !data.column_names.empty?
|
51
|
+
data.column_names
|
52
|
+
else
|
53
|
+
data[0]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
45
57
|
def build_md_row(output, row)
|
46
58
|
output << '|'
|
47
59
|
output << row.to_a.map { |cell| escape(+cell.to_s) }.join('|')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruport-wiki-table-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruport
|