htot_conv 0.0.1 → 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 +4 -4
- data/.travis.yml +3 -1
- data/README.md +4 -14
- data/exe/htot_conv +4 -107
- data/lib/htot_conv/cli.rb +129 -0
- data/lib/htot_conv/generator/base.rb +1 -0
- data/lib/htot_conv/generator/xlsx_type0.rb +1 -0
- data/lib/htot_conv/generator/xlsx_type1.rb +1 -0
- data/lib/htot_conv/generator/xlsx_type2.rb +30 -0
- data/lib/htot_conv/generator/xlsx_type4.rb +33 -2
- data/lib/htot_conv/generator/xlsx_type5.rb +18 -1
- data/lib/htot_conv/generator.rb +1 -0
- data/lib/htot_conv/outline.rb +16 -18
- data/lib/htot_conv/parser/base.rb +1 -0
- data/lib/htot_conv/parser/html_list.rb +1 -0
- data/lib/htot_conv/parser/simple_text.rb +15 -2
- data/lib/htot_conv/parser.rb +1 -0
- data/lib/htot_conv/util.rb +1 -0
- data/lib/htot_conv/version.rb +2 -1
- data/lib/htot_conv.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aec83d272692c2e5e421fa83871202a6658f6f0
|
4
|
+
data.tar.gz: 2e36a66a3309075cb170a1e587e18d83fc3a1c97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aea65eb03fa27f1d475448e8bf560a387e36c564d8af92b6e68e99701569d10544496841458c840eff89e815ba2e3857140d0d7e1b43e932f6c5a3c616be53b9
|
7
|
+
data.tar.gz: fefabfb0d96991003bb55d53590fc26bbbc1c2a1947d5ba92a7188852ad8491408ff7f5b4399d3f179bbd8fb8b4e586139cc55a8576e8cdb9d3d538b270ce31e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Convert from a simple hierarchical-tree outline text into ugly xlsx file
|
4
4
|
|
5
|
+
[](https://badge.fury.io/rb/htot_conv)
|
6
|
+
[](https://travis-ci.org/cat-in-136/htot_conv)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Install `htot_conv` via RubyGems. Simply run the following command to install:
|
@@ -83,10 +86,6 @@ Not implemented (TODO):
|
|
83
86
|
| | 1.2 | | 1.2(1) | 1.2(2) |
|
84
87
|
| | | 1.2.1 | 1.2.1(1) | 1.2.1(2) |
|
85
88
|
|
86
|
-
Not implemented (TODO):
|
87
|
-
|
88
|
-
* Cell integration over row.
|
89
|
-
|
90
89
|
#### `xlsx_type3`
|
91
90
|
|
92
91
|
Not supported (implemented) as of now.
|
@@ -98,7 +97,7 @@ Not supported (implemented) as of now.
|
|
98
97
|
| | 1.2 | 1.2(1) | | 1.2(2) |
|
99
98
|
| | | 1.2.1 | 1.2.1(1) | 1.2.1(2) |
|
100
99
|
|
101
|
-
TODO: Github Flavored Markdown does not support for
|
100
|
+
TODO: Github Flavored Markdown does not support for row span.
|
102
101
|
So, this document does not correctly represent type-3 xlsx spread sheet.
|
103
102
|
|
104
103
|
#### `xlsx_type4`
|
@@ -108,10 +107,6 @@ So, this document does not correctly represent type-3 xlsx spread sheet.
|
|
108
107
|
| 1 | 1.1 | | 1.1(1) | 1.1(2) |
|
109
108
|
| | 1.2 | 1.2.1 | 1.2.1(1) | 1.2.1(2) |
|
110
109
|
|
111
|
-
Not implemented (TODO):
|
112
|
-
|
113
|
-
* Cell integration over column.
|
114
|
-
|
115
110
|
#### `xlsx_type5`
|
116
111
|
|
117
112
|
| H1 | H2 | H3 | H(1) | H(2) |
|
@@ -119,11 +114,6 @@ Not implemented (TODO):
|
|
119
114
|
| 1 | 1.1 | | 1.1(1) | 1.1(2) |
|
120
115
|
| 1 | 1.2 | 1.2.1 | 1.2.1(1) | 1.2.1(2) |
|
121
116
|
|
122
|
-
Not implemented (TODO):
|
123
|
-
|
124
|
-
* Cell integration over column.
|
125
|
-
* Apply auto filter to the first (header) row.
|
126
|
-
|
127
117
|
## Development
|
128
118
|
|
129
119
|
$ bundle install --path=vendor/bundle --with development test
|
data/exe/htot_conv
CHANGED
@@ -1,111 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
4
|
require 'rubygems'
|
5
|
-
require 'rinne'
|
6
5
|
require 'htot_conv'
|
6
|
+
require 'htot_conv/cli'
|
7
7
|
|
8
|
-
|
9
|
-
module CLI
|
10
|
-
class ScriptOptions
|
11
|
-
def initialize
|
12
|
-
@options = {
|
13
|
-
:from_type => :simple_text,
|
14
|
-
:to_type => :xlsx_type2,
|
15
|
-
}
|
16
|
-
@from_options = {}
|
17
|
-
@to_options = {}
|
18
|
-
end
|
19
|
-
attr_accessor :options, :from_options, :to_options
|
20
|
-
|
21
|
-
def define_options(opts)
|
22
|
-
opts.banner = %q{Hierarchical-Tree Outline Text Converter}
|
23
|
-
opts.define_head %q{Usage: htot_conv [options] [input] [output]}
|
24
|
-
opts.separator %q{}
|
25
|
-
opts.separator %q{Options:}
|
26
|
-
|
27
|
-
from_types = HTOTConv::Parser.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten
|
28
|
-
to_types = HTOTConv::Generator.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten
|
29
|
-
|
30
|
-
opts.on("-f", "--from-type=TYPE", from_types, "type of input (default: #{options[:from_type]})") do |v|
|
31
|
-
options[:from_type] = v.to_s.tr("-", "_")
|
32
|
-
end
|
33
|
-
opts.on("-t", "--to-type=TYPE", to_types, "type of output (default: #{options[:to_type]})") do |v|
|
34
|
-
options[:to_type] = v.to_s.tr("-", "_")
|
35
|
-
end
|
36
|
-
opts.on("-l", "--list-type", "list input/output type") do
|
37
|
-
$stdout << "type of input:\n"
|
38
|
-
$stdout << HTOTConv::Parser.types.join(" ") << "\n"
|
39
|
-
$stdout << "\n"
|
40
|
-
$stdout << "type of output:\n"
|
41
|
-
$stdout << HTOTConv::Generator.types.join(" ") << "\n"
|
42
|
-
$stdout << "\n"
|
43
|
-
exit
|
44
|
-
end
|
45
|
-
|
46
|
-
opts.separator ""
|
47
|
-
opts.on("-h", "-?", "--help", "Show this message") do
|
48
|
-
puts opts
|
49
|
-
exit
|
50
|
-
end
|
51
|
-
opts.on("--version", "Show version") do
|
52
|
-
$stdout << "htot_conv #{HTOTConv::VERSION}\n"
|
53
|
-
exit
|
54
|
-
end
|
55
|
-
|
56
|
-
opts.separator ""
|
57
|
-
opts.separator "I/O Options:"
|
58
|
-
define_sub_options(opts, HTOTConv::Parser, "from") do |key, v|
|
59
|
-
@from_options[key] = v
|
60
|
-
end
|
61
|
-
define_sub_options(opts, HTOTConv::Generator, "to") do |key, v|
|
62
|
-
@to_options[key] = v
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
def define_sub_options(opts, klass, prefix) # :yields: key, v
|
68
|
-
klass.types.each do |type|
|
69
|
-
type_klass = klass.const_get(Rinne.camelize(type.to_s))
|
70
|
-
type_klass.option_help.each do |key,v|
|
71
|
-
long_option = "--#{prefix}-#{key.to_s.tr('_','-')}=VAL"
|
72
|
-
cmd_switch = opts.top.list.find { |v| v.kind_of?(OptionParser::Switch) && v.long.include?(long_option) }
|
73
|
-
if cmd_switch
|
74
|
-
cmd_switch.desc << "For #{type}, #{v[:desc]}"
|
75
|
-
else
|
76
|
-
opts.on(long_option, v[:pat], "For #{type}, #{v[:desc]}") do |v|
|
77
|
-
yield key, v
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def optparse(args)
|
86
|
-
script_opts = ScriptOptions.new
|
87
|
-
OptionParser.new do |opts|
|
88
|
-
script_opts.define_options(opts)
|
89
|
-
|
90
|
-
begin
|
91
|
-
opts.parse!(args)
|
92
|
-
rescue OptionParser::ParseError => ex
|
93
|
-
$stderr << ex.message << "\n"
|
94
|
-
exit 1
|
95
|
-
end
|
96
|
-
end
|
97
|
-
script_opts
|
98
|
-
end
|
99
|
-
module_function :optparse
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
script_opts = HTOTConv::CLI.optparse(ARGV)
|
104
|
-
options = script_opts.options
|
105
|
-
from_options = script_opts.from_options
|
106
|
-
to_options = script_opts.to_options
|
107
|
-
|
108
|
-
inio = ((ARGV.length > 0) && (ARGV[0] != "-"))? File.open(ARGV[0], "rb") : $stdin
|
109
|
-
outio = ((ARGV.length > 1) && (ARGV[1] != "-"))? File.open(ARGV[1], "wb") : $stdout
|
110
|
-
|
111
|
-
HTOTConv.convert(inio, options[:from_type], outio, options[:to_type], from_options, to_options)
|
8
|
+
HTOTConv::CLI.main(ARGV)
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
require 'rinne'
|
5
|
+
|
6
|
+
module HTOTConv
|
7
|
+
module CLI
|
8
|
+
class ScriptOptions
|
9
|
+
def initialize
|
10
|
+
@options = {
|
11
|
+
:from_type => :simple_text,
|
12
|
+
:to_type => :xlsx_type2,
|
13
|
+
}
|
14
|
+
@from_options = {}
|
15
|
+
@to_options = {}
|
16
|
+
end
|
17
|
+
attr_accessor :options, :from_options, :to_options
|
18
|
+
|
19
|
+
def define_options(opts)
|
20
|
+
opts.banner = %q{Hierarchical-Tree Outline Text Converter}
|
21
|
+
opts.define_head %q{Usage: htot_conv [options] [input] [output]}
|
22
|
+
opts.separator %q{}
|
23
|
+
opts.separator %q{Options:}
|
24
|
+
|
25
|
+
from_types = HTOTConv::Parser.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten
|
26
|
+
to_types = HTOTConv::Generator.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten
|
27
|
+
|
28
|
+
opts.on("-f", "--from-type=TYPE", from_types, "type of input (default: #{options[:from_type]})") do |v|
|
29
|
+
options[:from_type] = v.to_s.tr("-", "_")
|
30
|
+
end
|
31
|
+
opts.on("-t", "--to-type=TYPE", to_types, "type of output (default: #{options[:to_type]})") do |v|
|
32
|
+
options[:to_type] = v.to_s.tr("-", "_")
|
33
|
+
end
|
34
|
+
opts.on("-l", "--list-type", "list input/output type") do
|
35
|
+
$stdout << "type of input:\n"
|
36
|
+
$stdout << HTOTConv::Parser.types.join(" ") << "\n"
|
37
|
+
$stdout << "\n"
|
38
|
+
$stdout << "type of output:\n"
|
39
|
+
$stdout << HTOTConv::Generator.types.join(" ") << "\n"
|
40
|
+
$stdout << "\n"
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.separator ""
|
45
|
+
opts.on("-h", "-?", "--help", "Show this message") do
|
46
|
+
puts opts
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
opts.on("--version", "Show version") do
|
50
|
+
$stdout << "htot_conv #{HTOTConv::VERSION}\n"
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.separator ""
|
55
|
+
opts.separator "I/O Options:"
|
56
|
+
define_sub_options(opts, HTOTConv::Parser, "from") do |key, v|
|
57
|
+
@from_options[key] = v
|
58
|
+
end
|
59
|
+
define_sub_options(opts, HTOTConv::Generator, "to") do |key, v|
|
60
|
+
@to_options[key] = v
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def define_sub_options(opts, klass, prefix) # :yields: key, v
|
66
|
+
options = {}
|
67
|
+
|
68
|
+
klass.types.each do |type|
|
69
|
+
type_klass = klass.const_get(Rinne.camelize(type.to_s))
|
70
|
+
type_klass.option_help.each do |key,v|
|
71
|
+
long_option = "--#{prefix}-#{key.to_s.tr('_','-')}"
|
72
|
+
|
73
|
+
if options.include?(long_option)
|
74
|
+
options[long_option][:desc] << "For #{type}, #{v[:desc]}"
|
75
|
+
unless options[long_option][:pattern] == v[:pat]
|
76
|
+
if (options[long_option][:pattern].kind_of?(Array) && v[:pat].kind_of?(Array))
|
77
|
+
options[long_option][:pattern] = options[long_option][:pattern].concat(v[:pat]).uniq
|
78
|
+
else
|
79
|
+
raise "pattern registration mismatch around #{long_option}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
options[long_option] = {
|
84
|
+
:key => key,
|
85
|
+
:pattern => v[:pat],
|
86
|
+
:desc => ["For #{type}, #{v[:desc]}"],
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
options.each do |long_option, value|
|
93
|
+
opts.on("#{long_option}=VAL", value[:pattern], *value[:desc]) do |v|
|
94
|
+
yield value[:key], v
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def optparse(args)
|
101
|
+
script_opts = ScriptOptions.new
|
102
|
+
OptionParser.new do |opts|
|
103
|
+
script_opts.define_options(opts)
|
104
|
+
|
105
|
+
begin
|
106
|
+
opts.parse!(args)
|
107
|
+
rescue OptionParser::ParseError => ex
|
108
|
+
$stderr << ex.message << "\n"
|
109
|
+
exit 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
script_opts
|
113
|
+
end
|
114
|
+
module_function :optparse
|
115
|
+
|
116
|
+
def main(args=ARGV)
|
117
|
+
script_opts = HTOTConv::CLI.optparse(args)
|
118
|
+
options = script_opts.options
|
119
|
+
from_options = script_opts.from_options
|
120
|
+
to_options = script_opts.to_options
|
121
|
+
|
122
|
+
inio = ((args.length > 0) && (args[0] != "-"))? File.open(args[0], "rb") : $stdin
|
123
|
+
outio = ((args.length > 1) && (args[1] != "-"))? File.open(args[1], "wb") : $stdout
|
124
|
+
|
125
|
+
HTOTConv.convert(inio, options[:from_type], outio, options[:to_type], from_options, to_options)
|
126
|
+
end
|
127
|
+
module_function :main
|
128
|
+
end
|
129
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'axlsx'
|
2
3
|
|
3
4
|
require 'htot_conv/generator/base'
|
@@ -5,6 +6,16 @@ require 'htot_conv/generator/base'
|
|
5
6
|
module HTOTConv
|
6
7
|
module Generator
|
7
8
|
class XlsxType2 < XlsxBase
|
9
|
+
def self.option_help
|
10
|
+
{
|
11
|
+
:integrate_cells => {
|
12
|
+
:default => nil,
|
13
|
+
:pat => [:colspan, :rowspan],
|
14
|
+
:desc => "integrate key cells (specify 'colspan' or 'rowspan')",
|
15
|
+
},
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
8
19
|
def output_to_worksheet(ws)
|
9
20
|
max_level = @data.max_level
|
10
21
|
max_value_length = @data.max_value_length
|
@@ -31,6 +42,25 @@ module HTOTConv
|
|
31
42
|
:border => { :style => :thin, :color => "00", :edges => edges })
|
32
43
|
end
|
33
44
|
end
|
45
|
+
|
46
|
+
case @option[:integrate_cells]
|
47
|
+
when :colspan
|
48
|
+
@data.item.each_with_index do |item, item_index|
|
49
|
+
if item.level < max_level
|
50
|
+
ws.merge_cells(ws.rows[item_index + 1].cells[((item.level - 1)..(max_level - 1))])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
when :rowspan
|
54
|
+
@data.item.each_with_index do |item, item_index|
|
55
|
+
cells = [ws.rows[item_index + 1].cells[item.level - 1]]
|
56
|
+
((item_index + 1)..(@data.item.length - 1)).each do |i|
|
57
|
+
break if @data.item[i].level <= item.level
|
58
|
+
cells << ws.rows[i + 1].cells[item.level - 1]
|
59
|
+
end
|
60
|
+
|
61
|
+
ws.merge_cells(cells) if cells.length > 1
|
62
|
+
end
|
63
|
+
end
|
34
64
|
end
|
35
65
|
end
|
36
66
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'axlsx'
|
2
3
|
|
3
4
|
require 'htot_conv/generator/base'
|
@@ -5,6 +6,16 @@ require 'htot_conv/generator/base'
|
|
5
6
|
module HTOTConv
|
6
7
|
module Generator
|
7
8
|
class XlsxType4 < XlsxBase
|
9
|
+
def self.option_help
|
10
|
+
{
|
11
|
+
:integrate_cells => {
|
12
|
+
:default => nil,
|
13
|
+
:pat => [:colspan, :rowspan, :both],
|
14
|
+
:desc => "integrate key cells (specify 'colspan', 'rowspan' or 'all')",
|
15
|
+
},
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
8
19
|
def output_to_worksheet(ws)
|
9
20
|
max_level = @data.max_level
|
10
21
|
max_value_length = @data.max_value_length
|
@@ -13,13 +24,14 @@ module HTOTConv
|
|
13
24
|
HTOTConv::Util.pad_array(@data.value_header, max_value_length)),
|
14
25
|
:style => Axlsx::STYLE_THIN_BORDER)
|
15
26
|
|
27
|
+
rowspan_cells = Array.new(max_level) { [] }
|
16
28
|
@data.to_tree.descendants.each do |node|
|
17
29
|
if node.leaf?
|
18
30
|
item = node.item
|
19
31
|
|
20
32
|
key_cell = Array.new(max_level, nil)
|
21
33
|
key_cell[node.item.level - 1] = item.key
|
22
|
-
node.ancestors do |ancestor|
|
34
|
+
node.ancestors.each do |ancestor|
|
23
35
|
key_cell[ancestor.item.level - 1] = ancestor.item.key if ancestor.item
|
24
36
|
break if ancestor.prev
|
25
37
|
end
|
@@ -29,7 +41,7 @@ module HTOTConv
|
|
29
41
|
ws.add_row(key_cell.concat(value_cell),
|
30
42
|
:style => Axlsx::STYLE_THIN_BORDER)
|
31
43
|
|
32
|
-
[node].concat(node.ancestors).each do |ancestor|
|
44
|
+
[node].concat(node.ancestors.to_a).each do |ancestor|
|
33
45
|
if (ancestor.parent && ancestor.parent.item && ancestor.parent.item.level)
|
34
46
|
edges = [:left, :right]
|
35
47
|
edges << :top unless ancestor.prev
|
@@ -45,6 +57,25 @@ module HTOTConv
|
|
45
57
|
ws.rows.last.cells[level - 1].style = ws.styles.add_style(
|
46
58
|
:border => { :style => :thin, :color => "00", :edges => edges })
|
47
59
|
end
|
60
|
+
|
61
|
+
if [:colspan, :both].include?(@option[:integrate_cells])
|
62
|
+
if item.level < max_level
|
63
|
+
ws.merge_cells(ws.rows.last.cells[((item.level - 1)..(max_level - 1))])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
node.ancestors.inject(node) do |c_node, a_node|
|
68
|
+
rowspan_cells[a_node.item.level - 1] << ws.rows.last.cells[a_node.item.level - 1]
|
69
|
+
unless c_node.next # if c_node is last?
|
70
|
+
if [:rowspan, :both].include?(@option[:integrate_cells])
|
71
|
+
if rowspan_cells[a_node.item.level - 1].length > 1
|
72
|
+
ws.merge_cells(rowspan_cells[a_node.item.level - 1])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
rowspan_cells[a_node.item.level - 1].clear
|
76
|
+
end
|
77
|
+
a_node
|
78
|
+
end
|
48
79
|
end
|
49
80
|
end
|
50
81
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'axlsx'
|
2
3
|
|
3
4
|
require 'htot_conv/generator/base'
|
@@ -5,6 +6,16 @@ require 'htot_conv/generator/base'
|
|
5
6
|
module HTOTConv
|
6
7
|
module Generator
|
7
8
|
class XlsxType5 < XlsxBase
|
9
|
+
def self.option_help
|
10
|
+
{
|
11
|
+
:integrate_cells => {
|
12
|
+
:default => nil,
|
13
|
+
:pat => [:colspan],
|
14
|
+
:desc => "integrate key cells (specify 'colspan')",
|
15
|
+
},
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
8
19
|
def output_to_worksheet(ws)
|
9
20
|
max_level = @data.max_level
|
10
21
|
max_value_length = @data.max_value_length
|
@@ -19,7 +30,7 @@ module HTOTConv
|
|
19
30
|
|
20
31
|
key_cell = Array.new(max_level, nil)
|
21
32
|
key_cell[node.item.level - 1] = item.key
|
22
|
-
node.ancestors do |ancestor|
|
33
|
+
node.ancestors.each do |ancestor|
|
23
34
|
key_cell[ancestor.item.level - 1] = ancestor.item.key if ancestor.item
|
24
35
|
end
|
25
36
|
|
@@ -35,6 +46,12 @@ module HTOTConv
|
|
35
46
|
ws.rows.last.cells[level - 1].style = ws.styles.add_style(
|
36
47
|
:border => { :style => :thin, :color => "00", :edges => edges })
|
37
48
|
end
|
49
|
+
|
50
|
+
if [:colspan].include?(@option[:integrate_cells])
|
51
|
+
if item.level < max_level
|
52
|
+
ws.merge_cells(ws.rows.last.cells[((item.level - 1)..(max_level - 1))])
|
53
|
+
end
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
data/lib/htot_conv/generator.rb
CHANGED
data/lib/htot_conv/outline.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module HTOTConv
|
2
3
|
class Outline
|
3
4
|
def initialize
|
@@ -96,7 +97,7 @@ module HTOTConv
|
|
96
97
|
end
|
97
98
|
alias :<< :add
|
98
99
|
|
99
|
-
def each # :
|
100
|
+
def each # :yield: child
|
100
101
|
@children.each do |v|
|
101
102
|
yield v if block_given?
|
102
103
|
end
|
@@ -129,28 +130,25 @@ module HTOTConv
|
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
132
|
-
def ancestors
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
133
|
+
def ancestors
|
134
|
+
Enumerator.new do |y|
|
135
|
+
node = self.parent
|
136
|
+
until (node.nil? || node.root?)
|
137
|
+
y << node
|
138
|
+
node = node.parent
|
139
|
+
end
|
139
140
|
end
|
140
|
-
ancestors
|
141
141
|
end
|
142
142
|
|
143
|
-
def descendants
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
yield descendant if block_given?
|
143
|
+
def descendants
|
144
|
+
Enumerator.new do |y|
|
145
|
+
@children.each do |child|
|
146
|
+
y << child
|
147
|
+
child.descendants.each do |descendant|
|
148
|
+
y << descendant
|
149
|
+
end
|
151
150
|
end
|
152
151
|
end
|
153
|
-
descendants
|
154
152
|
end
|
155
153
|
end
|
156
154
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'htot_conv/parser/base'
|
2
3
|
|
3
4
|
module HTOTConv
|
@@ -13,7 +14,17 @@ module HTOTConv
|
|
13
14
|
:delimiter => {
|
14
15
|
:default => nil,
|
15
16
|
:pat => String,
|
16
|
-
:desc => "separator character of additional data"
|
17
|
+
:desc => "separator character of additional data",
|
18
|
+
},
|
19
|
+
:preserve_empty_line => {
|
20
|
+
:defalut => false,
|
21
|
+
:pat => FalseClass,
|
22
|
+
:desc => "preserve empty line as a level-1 item (default: no)",
|
23
|
+
},
|
24
|
+
:value_header => {
|
25
|
+
:default => [],
|
26
|
+
:pat => Array,
|
27
|
+
:desc => "value header",
|
17
28
|
},
|
18
29
|
}
|
19
30
|
end
|
@@ -23,9 +34,11 @@ module HTOTConv
|
|
23
34
|
delimiter_regexp = (option[:delimiter].kind_of?(String))? Regexp.new(Regexp.escape(option[:delimiter])) : option[:delimiter]
|
24
35
|
outline = HTOTConv::Outline.new
|
25
36
|
outline.key_header = []
|
26
|
-
outline.value_header = []
|
37
|
+
outline.value_header = option[:value_header]
|
27
38
|
|
28
39
|
input.each_line do |line|
|
40
|
+
next if ((line.chomp == "") && (!option[:preserve_empty_line]))
|
41
|
+
|
29
42
|
level = 1
|
30
43
|
value = []
|
31
44
|
if (option[:indent] || '').length > 0
|
data/lib/htot_conv/parser.rb
CHANGED
data/lib/htot_conv/util.rb
CHANGED
data/lib/htot_conv/version.rb
CHANGED
data/lib/htot_conv.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htot_conv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@cat_in_136"
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- exe/htot_conv
|
100
100
|
- htot_conv.gemspec
|
101
101
|
- lib/htot_conv.rb
|
102
|
+
- lib/htot_conv/cli.rb
|
102
103
|
- lib/htot_conv/generator.rb
|
103
104
|
- lib/htot_conv/generator/base.rb
|
104
105
|
- lib/htot_conv/generator/xlsx_type0.rb
|