ruport-wiki-table-formatter 0.1.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 +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/lib/ruport/wiki_table_formatter.rb +39 -0
- data/lib/ruport/wiki_table_formatter/markdown.rb +95 -0
- data/lib/ruport/wiki_table_formatter/version.rb +8 -0
- data/sample/sample.md +6 -0
- data/sample/sample.rb +13 -0
- metadata +88 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: cbb609c0de7f3ecc62cbfcccc448a63ca295f0913aee64f45860fbfee72e4dc9
|
|
4
|
+
data.tar.gz: f913326247bff8d30c6d0aadd125a9b371b738290d2a4afbcf0d29cf6da2a172
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bcea9f3935328cf7f6ca79b682d0e0098a634b3442339de1bbee60f70aef5219e29b67f7eda40422add6d8204f043195b5b62d32254177571b29c006ecfcb643
|
|
7
|
+
data.tar.gz: e14c4c149c2e9b1bb00f6749a8aa57973a9994e1a7e90014b56a7d61c9ce17c52b820131c45db75536bb3a754f2671efc009516ed282440177da3ea3d54af446
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at taichi730@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Taichi Ishitani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[](https://travis-ci.org/taichi-ishitani/ruport-wiki-table-formatter)
|
|
2
|
+
[](https://codeclimate.com/github/taichi-ishitani/ruport-wiki-table-formatter/maintainability)
|
|
3
|
+
[](https://codecov.io/gh/taichi-ishitani/ruport-wiki-table-formatter)
|
|
4
|
+
|
|
5
|
+
# Ruport::WikiTableFormatter
|
|
6
|
+
|
|
7
|
+
Ruport::WikiTableFormatter is an extention for [Ruport](https://github.com/ruport/ruport) to format `Ruport::Table` data into wiki table format.
|
|
8
|
+
|
|
9
|
+
Currently, Ruport::WikiTableFormatter supports following wiki formats:
|
|
10
|
+
|
|
11
|
+
* Markdown
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To install Ruport::WikiTableFormatter, hit command below:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
$ gem install ruport-wiki-table-formatter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or add this line to your Gemfile:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
gem 'ruport-wiki-table-formatter'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
To format `Ruport::Table` data into wiki table format, you only have to call following methods:
|
|
30
|
+
|
|
31
|
+
* Markdown: #to_markdown
|
|
32
|
+
|
|
33
|
+
Here is an sample code:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
require 'ruport'
|
|
37
|
+
require 'ruport/wiki_table_formatter'
|
|
38
|
+
|
|
39
|
+
table = Ruport.Table('Airport', 'IATA code', 'Opend')
|
|
40
|
+
table << ['Kansai' , 'KIX', 1994]
|
|
41
|
+
table << ['Haneda' , 'HND', 1931]
|
|
42
|
+
table << ['Narita' , 'NRT', 1978]
|
|
43
|
+
table << ['New Chitose', 'CTS', 1988]
|
|
44
|
+
|
|
45
|
+
md = table.to_markdown
|
|
46
|
+
File.binwrite('sample.md', md)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Execute above sample code, Markdown table format below will be output:
|
|
50
|
+
|
|
51
|
+
|Airport|IATA code|Opend|
|
|
52
|
+
|:--|:--|:--|
|
|
53
|
+
|Kansai|KIX|1994|
|
|
54
|
+
|Haneda|HND|1931|
|
|
55
|
+
|Narita|NRT|1978|
|
|
56
|
+
|New Chitose|CTS|1988|
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/taichi-ishitani/ruport-wiki-table-formatter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
61
|
+
|
|
62
|
+
## Copyright & License
|
|
63
|
+
|
|
64
|
+
Copyrigh (c) 2019 Taichi Ishitani.
|
|
65
|
+
|
|
66
|
+
Licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE.txt](LICENSE.txt) for further details.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruport'
|
|
4
|
+
require_relative 'wiki_table_formatter/version'
|
|
5
|
+
require_relative 'wiki_table_formatter/markdown'
|
|
6
|
+
|
|
7
|
+
module Ruport
|
|
8
|
+
# Ruport::WikiTableFormatter is an extention for {Ruport}[https://github.com/ruport/ruport]
|
|
9
|
+
# to format Ruport::Table data into wiki table format.
|
|
10
|
+
#
|
|
11
|
+
# Currently, following formats are supported:
|
|
12
|
+
#
|
|
13
|
+
# * Markdown: Ruport::WikiTableFormatter::Markdown
|
|
14
|
+
#
|
|
15
|
+
# To get wiki table format from Ruport::Table data,
|
|
16
|
+
# you only have to call following methods:
|
|
17
|
+
#
|
|
18
|
+
# * Markdown: #to_markdown
|
|
19
|
+
#
|
|
20
|
+
# Example:
|
|
21
|
+
#
|
|
22
|
+
# table = Ruport.Table('Airport', 'IATA code', 'Opend')
|
|
23
|
+
# table << ['Kansai' , 'KIX', 1994]
|
|
24
|
+
# table << ['Haneda' , 'HND', 1931]
|
|
25
|
+
# table << ['Narita' , 'NRT', 1978]
|
|
26
|
+
# table << ['New Chitose', 'CTS', 1988]
|
|
27
|
+
# md = table.to_markdown
|
|
28
|
+
#
|
|
29
|
+
# Output
|
|
30
|
+
#
|
|
31
|
+
# |Airport|IATA code|Opend|
|
|
32
|
+
# |:--|:--|:--|
|
|
33
|
+
# |Kansai|KIX|1994|
|
|
34
|
+
# |Haneda|HND|1931|
|
|
35
|
+
# |Narita|NRT|1978|
|
|
36
|
+
# |New Chitose|CTS|1988|
|
|
37
|
+
module WikiTableFormatter
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ruport
|
|
4
|
+
module WikiTableFormatter
|
|
5
|
+
# This class produces Markdown table output from Ruport::Table data.
|
|
6
|
+
#
|
|
7
|
+
# === Rendering Options
|
|
8
|
+
# <tt>:alignment:</tt> Default alignment for all columns.
|
|
9
|
+
# Allowed values are :left, :center and :right. Default is :left.
|
|
10
|
+
#
|
|
11
|
+
# <tt>:column_alignments:</tt> Alignments for specific columns.
|
|
12
|
+
# You can configure alignments by using Hash (key: column name, value: alignment)
|
|
13
|
+
class Markdown < Ruport::Formatter
|
|
14
|
+
renders :markdown, for: [Controller::Table]
|
|
15
|
+
|
|
16
|
+
# Hook for setting available options using a template.
|
|
17
|
+
def apply_template
|
|
18
|
+
apply_table_format_template(template.table)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Checks to ensure the table has non empty column_names.
|
|
22
|
+
def prepare_table
|
|
23
|
+
if data.column_names.empty?
|
|
24
|
+
message = 'Can\'t output table without column names.'
|
|
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.
|
|
30
|
+
def build_table_header
|
|
31
|
+
build_md_row(output, data.column_names)
|
|
32
|
+
build_md_row(output, alignment_strings(data.column_names))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Generates body of Markdown table data.
|
|
36
|
+
# Following characters will be replaced as escape.
|
|
37
|
+
# | -> |
|
|
38
|
+
# newline code(\n) -> <br>
|
|
39
|
+
def build_table_body
|
|
40
|
+
data.each { |row| build_md_row(output, row) }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def build_md_row(output, row)
|
|
46
|
+
output << '|'
|
|
47
|
+
output << row.to_a.map { |cell| escape(+cell.to_s) }.join('|')
|
|
48
|
+
output << "|\n"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def escape(cell)
|
|
52
|
+
cell.gsub!('|', '|')
|
|
53
|
+
cell.gsub!("\n", '<br>')
|
|
54
|
+
cell
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def alignment_strings(column_names)
|
|
58
|
+
column_names.map(&method(:alignment_string))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def alignment_string(column_name)
|
|
62
|
+
case column_alignment(column_name)
|
|
63
|
+
when :right
|
|
64
|
+
'--:'
|
|
65
|
+
when :center
|
|
66
|
+
':-:'
|
|
67
|
+
else
|
|
68
|
+
':--'
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def column_alignment(column_name)
|
|
73
|
+
if options.column_alignments&.key?(column_name)
|
|
74
|
+
options.column_alignments[column_name]
|
|
75
|
+
elsif options.alignment
|
|
76
|
+
options.alignment
|
|
77
|
+
else
|
|
78
|
+
:left
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def apply_table_format_template(template)
|
|
83
|
+
template = (template || {}).merge(options.table_format || {})
|
|
84
|
+
options.alignment ||= template[:alignment]
|
|
85
|
+
options.column_alignments =
|
|
86
|
+
merget_column_alignments(options, template)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def merget_column_alignments(options, template)
|
|
90
|
+
(template[:column_alignments] || {})
|
|
91
|
+
.merge(options.column_alignments || {})
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
data/sample/sample.md
ADDED
data/sample/sample.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruport'
|
|
4
|
+
require 'ruport/wiki_table_formatter'
|
|
5
|
+
|
|
6
|
+
table = Ruport.Table('Airport', 'IATA code', 'Opend')
|
|
7
|
+
table << ['Kansai' , 'KIX', 1994]
|
|
8
|
+
table << ['Haneda' , 'HND', 1931]
|
|
9
|
+
table << ['Narita' , 'NRT', 1978]
|
|
10
|
+
table << ['New Chitose', 'CTS', 1988]
|
|
11
|
+
|
|
12
|
+
md = table.to_markdown
|
|
13
|
+
File.binwrite('sample.md', md)
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruport-wiki-table-formatter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Taichi Ishitani
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: ruport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.0'
|
|
41
|
+
description: |
|
|
42
|
+
Ruport::WikiTableFormatter is an extension for Ruport to format Ruport::Table data
|
|
43
|
+
into wiki table format.
|
|
44
|
+
email:
|
|
45
|
+
- taichi730@gmail.com
|
|
46
|
+
executables: []
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files:
|
|
49
|
+
- README.md
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
files:
|
|
52
|
+
- CODE_OF_CONDUCT.md
|
|
53
|
+
- LICENSE.txt
|
|
54
|
+
- README.md
|
|
55
|
+
- lib/ruport/wiki_table_formatter.rb
|
|
56
|
+
- lib/ruport/wiki_table_formatter/markdown.rb
|
|
57
|
+
- lib/ruport/wiki_table_formatter/version.rb
|
|
58
|
+
- sample/sample.md
|
|
59
|
+
- sample/sample.rb
|
|
60
|
+
homepage: https://github.com/taichi-ishitani/ruport-wiki-table-formatter
|
|
61
|
+
licenses:
|
|
62
|
+
- MIT
|
|
63
|
+
metadata: {}
|
|
64
|
+
post_install_message:
|
|
65
|
+
rdoc_options:
|
|
66
|
+
- "--tile"
|
|
67
|
+
- Ruport::WikiTableFormatter
|
|
68
|
+
- "--main"
|
|
69
|
+
- README.md
|
|
70
|
+
- "--q"
|
|
71
|
+
require_paths:
|
|
72
|
+
- lib
|
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - ">="
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '2.3'
|
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
requirements: []
|
|
84
|
+
rubygems_version: 3.0.3
|
|
85
|
+
signing_key:
|
|
86
|
+
specification_version: 4
|
|
87
|
+
summary: Wiki table formatter for Ruport
|
|
88
|
+
test_files: []
|