htot_conv 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +135 -135
- data/.travis.yml +12 -12
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +46 -138
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/docs/image/output_xlsx_type0.png +0 -0
- data/docs/image/output_xlsx_type1.png +0 -0
- data/docs/image/output_xlsx_type1_outline_rows_yes.png +0 -0
- data/docs/image/output_xlsx_type2.png +0 -0
- data/docs/image/output_xlsx_type2_integrate_cells_colspan.png +0 -0
- data/docs/image/output_xlsx_type2_outline_rows_yes.png +0 -0
- data/docs/image/output_xlsx_type3.png +0 -0
- data/docs/image/output_xlsx_type3_integrate_cells_both.png +0 -0
- data/docs/image/output_xlsx_type4.png +0 -0
- data/docs/image/output_xlsx_type4_integrate_cells_both.png +0 -0
- data/docs/image/output_xlsx_type5.png +0 -0
- data/docs/image/output_xlsx_type5_integrate_cells_colspan.png +0 -0
- data/docs/index.md +88 -0
- data/exe/htot_conv +8 -8
- data/htot_conv.gemspec +37 -37
- data/lib/htot_conv.rb +20 -20
- data/lib/htot_conv/cli.rb +174 -174
- data/lib/htot_conv/generator.rb +30 -30
- data/lib/htot_conv/generator/base.rb +34 -35
- data/lib/htot_conv/generator/xlsx_type0.rb +36 -24
- data/lib/htot_conv/generator/xlsx_type1.rb +57 -69
- data/lib/htot_conv/generator/xlsx_type2.rb +100 -104
- data/lib/htot_conv/generator/xlsx_type3.rb +99 -85
- data/lib/htot_conv/generator/xlsx_type4.rb +109 -84
- data/lib/htot_conv/generator/xlsx_type5.rb +75 -62
- data/lib/htot_conv/outline.rb +176 -176
- data/lib/htot_conv/parser.rb +27 -27
- data/lib/htot_conv/parser/base.rb +15 -15
- data/lib/htot_conv/parser/dir_tree.rb +54 -54
- data/lib/htot_conv/parser/html_list.rb +71 -71
- data/lib/htot_conv/parser/opml.rb +70 -70
- data/lib/htot_conv/parser/simple_text.rb +70 -70
- data/lib/htot_conv/util.rb +13 -13
- data/lib/htot_conv/version.rb +4 -4
- metadata +19 -6
data/lib/htot_conv/generator.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'htot_conv/generator/xlsx_type0.rb'
|
3
|
-
require 'htot_conv/generator/xlsx_type1.rb'
|
4
|
-
require 'htot_conv/generator/xlsx_type2.rb'
|
5
|
-
require 'htot_conv/generator/xlsx_type3.rb'
|
6
|
-
require 'htot_conv/generator/xlsx_type4.rb'
|
7
|
-
require 'htot_conv/generator/xlsx_type5.rb'
|
8
|
-
|
9
|
-
require 'rinne'
|
10
|
-
|
11
|
-
module HTOTConv
|
12
|
-
module Generator
|
13
|
-
def create(type, *args)
|
14
|
-
klass = HTOTConv::Generator.const_get(Rinne.camelize(type.to_s))
|
15
|
-
klass.new(*args)
|
16
|
-
end
|
17
|
-
module_function :create
|
18
|
-
|
19
|
-
def types
|
20
|
-
HTOTConv::Generator.constants.reject { |klass|
|
21
|
-
klass =~ /Base$/
|
22
|
-
}.select { |klass|
|
23
|
-
HTOTConv::Generator.const_get(klass).kind_of?(Class)
|
24
|
-
}.map { |klass|
|
25
|
-
Rinne.to_snake(klass.to_s).to_sym
|
26
|
-
}
|
27
|
-
end
|
28
|
-
module_function :types
|
29
|
-
end
|
30
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'htot_conv/generator/xlsx_type0.rb'
|
3
|
+
require 'htot_conv/generator/xlsx_type1.rb'
|
4
|
+
require 'htot_conv/generator/xlsx_type2.rb'
|
5
|
+
require 'htot_conv/generator/xlsx_type3.rb'
|
6
|
+
require 'htot_conv/generator/xlsx_type4.rb'
|
7
|
+
require 'htot_conv/generator/xlsx_type5.rb'
|
8
|
+
|
9
|
+
require 'rinne'
|
10
|
+
|
11
|
+
module HTOTConv
|
12
|
+
module Generator
|
13
|
+
def create(type, *args)
|
14
|
+
klass = HTOTConv::Generator.const_get(Rinne.camelize(type.to_s))
|
15
|
+
klass.new(*args)
|
16
|
+
end
|
17
|
+
module_function :create
|
18
|
+
|
19
|
+
def types
|
20
|
+
HTOTConv::Generator.constants.reject { |klass|
|
21
|
+
klass =~ /Base$/
|
22
|
+
}.select { |klass|
|
23
|
+
HTOTConv::Generator.const_get(klass).kind_of?(Class)
|
24
|
+
}.map { |klass|
|
25
|
+
Rinne.to_snake(klass.to_s).to_sym
|
26
|
+
}
|
27
|
+
end
|
28
|
+
module_function :types
|
29
|
+
end
|
30
|
+
end
|
@@ -1,35 +1,34 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
{}
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubyXL'
|
4
|
+
|
5
|
+
module HTOTConv
|
6
|
+
module Generator
|
7
|
+
class Base
|
8
|
+
def initialize(data, option={})
|
9
|
+
data.validate
|
10
|
+
@data = data
|
11
|
+
@option = self.class.option_help.inject({}) { |h, pair| h[pair[0]] = pair[1][:default]; h}.merge(option)
|
12
|
+
end
|
13
|
+
def self.option_help
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
|
17
|
+
def output(outputfile)
|
18
|
+
raise NotImplementedError.new("#{self.class.name}.#{__method__} is an abstract method.")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class XlsxBase < Base
|
23
|
+
def output_to_worksheet(ws)
|
24
|
+
raise NotImplementedError.new("#{self.class.name}.#{__method__} is an abstract method.")
|
25
|
+
end
|
26
|
+
|
27
|
+
def output(outputfile)
|
28
|
+
wb = RubyXL::Workbook.new
|
29
|
+
output_to_worksheet(wb[0])
|
30
|
+
wb.write(outputfile)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,24 +1,36 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
max_value_length = @data.max_value_length
|
11
|
-
|
12
|
-
|
13
|
-
HTOTConv::Util.pad_array(@data.value_header, max_value_length)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'htot_conv/generator/base'
|
4
|
+
|
5
|
+
module HTOTConv
|
6
|
+
module Generator
|
7
|
+
class XlsxType0 < XlsxBase
|
8
|
+
def output_to_worksheet(ws)
|
9
|
+
row_index = 0
|
10
|
+
max_value_length = @data.max_value_length
|
11
|
+
|
12
|
+
[@data.key_header[0], 'Outline Level'].concat(
|
13
|
+
HTOTConv::Util.pad_array(@data.value_header, max_value_length)
|
14
|
+
).each_with_index do |v, col_index|
|
15
|
+
ws.add_cell(row_index, col_index, v)
|
16
|
+
[:top, :bottom, :left, :right].each do |edge|
|
17
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
row_index = row_index.succ
|
21
|
+
|
22
|
+
@data.item.each do |item|
|
23
|
+
[item.key, item.level.to_i].concat(
|
24
|
+
HTOTConv::Util.pad_array(item.value, max_value_length)
|
25
|
+
).each_with_index do |v, col_index|
|
26
|
+
ws.add_cell(row_index, col_index, v)
|
27
|
+
[:top, :bottom, :left, :right].each do |edge|
|
28
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
row_index = row_index.succ
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,69 +1,57 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
tmp_str = "".dup
|
59
|
-
super(tmp_str)
|
60
|
-
str << tmp_str.sub('<pageSetUpPr', '<outlinePr summaryBelow="0" /><pageSetUpPr')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'htot_conv/generator/base'
|
4
|
+
|
5
|
+
module HTOTConv
|
6
|
+
module Generator
|
7
|
+
class XlsxType1 < XlsxBase
|
8
|
+
def self.option_help
|
9
|
+
{
|
10
|
+
:outline_rows => {
|
11
|
+
:default => false,
|
12
|
+
:pat => FalseClass,
|
13
|
+
:desc => "group rows (default: no)",
|
14
|
+
},
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def output_to_worksheet(ws)
|
19
|
+
row_index = 0
|
20
|
+
max_value_length = @data.max_value_length
|
21
|
+
|
22
|
+
[@data.key_header[0]].concat(
|
23
|
+
HTOTConv::Util.pad_array(@data.value_header, max_value_length)
|
24
|
+
).each_with_index do |v, col_index|
|
25
|
+
ws.add_cell(row_index, col_index, v)
|
26
|
+
[:top, :bottom, :left, :right].each do |edge|
|
27
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
row_index = row_index.succ
|
31
|
+
|
32
|
+
@data.item.each do |item|
|
33
|
+
([item.key].concat(
|
34
|
+
HTOTConv::Util.pad_array(item.value, max_value_length))
|
35
|
+
).each_with_index do |v, col_index|
|
36
|
+
ws.add_cell(row_index, col_index, v)
|
37
|
+
[:top, :bottom, :left, :right].each do |edge|
|
38
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
row_index = row_index.succ
|
42
|
+
end
|
43
|
+
|
44
|
+
if @option[:outline_rows]
|
45
|
+
@data.item.each_with_index do |item, item_index|
|
46
|
+
ws[item_index + 1].outline_level = (item.level > 1)? (item.level - 1) : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
ws.sheet_pr ||= RubyXL::WorksheetProperties.new
|
50
|
+
ws.sheet_pr.outline_pr ||= RubyXL::OutlineProperties.new
|
51
|
+
ws.sheet_pr.outline_pr.summary_below = false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -1,104 +1,100 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:
|
13
|
-
:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:
|
18
|
-
:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
max_level = @data.max_level
|
26
|
-
max_value_length = @data.max_value_length
|
27
|
-
|
28
|
-
|
29
|
-
HTOTConv::Util.pad_array(@data.value_header, max_value_length))
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
(item.level
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'htot_conv/generator/base'
|
4
|
+
|
5
|
+
module HTOTConv
|
6
|
+
module Generator
|
7
|
+
class XlsxType2 < XlsxBase
|
8
|
+
def self.option_help
|
9
|
+
{
|
10
|
+
:integrate_cells => {
|
11
|
+
:default => nil,
|
12
|
+
:pat => [:colspan, :rowspan],
|
13
|
+
:desc => "integrate key cells (specify 'colspan' or 'rowspan')",
|
14
|
+
},
|
15
|
+
:outline_rows => {
|
16
|
+
:default => false,
|
17
|
+
:pat => FalseClass,
|
18
|
+
:desc => "group rows (default: no)",
|
19
|
+
},
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def output_to_worksheet(ws)
|
24
|
+
row_index = 0
|
25
|
+
max_level = @data.max_level
|
26
|
+
max_value_length = @data.max_value_length
|
27
|
+
|
28
|
+
(((1..max_level).map {|l| @data.key_header[l - 1] || nil }).concat(
|
29
|
+
HTOTConv::Util.pad_array(@data.value_header, max_value_length))
|
30
|
+
).each_with_index do |v, col_index|
|
31
|
+
ws.add_cell(row_index, col_index, v)
|
32
|
+
[:top, :bottom, :left, :right].each do |edge|
|
33
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
row_index = row_index.succ
|
37
|
+
|
38
|
+
@data.item.each_with_index do |item, item_index|
|
39
|
+
key_cell = Array.new(max_level, nil)
|
40
|
+
key_cell[item.level - 1] = item.key
|
41
|
+
value_cell = HTOTConv::Util.pad_array(item.value, max_value_length)
|
42
|
+
|
43
|
+
key_cell.concat(value_cell).each_with_index do |v, col_index|
|
44
|
+
ws.add_cell(row_index, col_index, v)
|
45
|
+
if col_index >= max_level
|
46
|
+
[:top, :bottom, :left, :right].each do |edge|
|
47
|
+
ws[row_index][col_index].change_border(edge, "thin")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
(1..max_level).each do |level|
|
53
|
+
edges = []
|
54
|
+
edges << :left if (level <= item.level)
|
55
|
+
edges << :right if ((level < item.level) || (level == max_level))
|
56
|
+
edges << :top if ((level >= item.level) || (item_index == 0))
|
57
|
+
edges << :bottom if ((level > item.level) || (item_index == @data.item.length - 1))
|
58
|
+
edges.each do |edge|
|
59
|
+
ws[row_index][level - 1].change_border(edge, "thin")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
row_index = row_index.succ
|
64
|
+
end
|
65
|
+
|
66
|
+
if @option[:outline_rows]
|
67
|
+
@data.item.each_with_index do |item, item_index|
|
68
|
+
ws[item_index + 1].outline_level = (item.level > 1)? (item.level - 1) : nil
|
69
|
+
end
|
70
|
+
|
71
|
+
ws.sheet_pr ||= RubyXL::WorksheetProperties.new
|
72
|
+
ws.sheet_pr.outline_pr ||= RubyXL::OutlineProperties.new
|
73
|
+
ws.sheet_pr.outline_pr.summary_below = false
|
74
|
+
end
|
75
|
+
|
76
|
+
case @option[:integrate_cells]
|
77
|
+
when :colspan
|
78
|
+
@data.item.each_with_index do |item, item_index|
|
79
|
+
if item.level < max_level
|
80
|
+
ws.merge_cells(item_index + 1, item.level - 1, item_index + 1, max_level - 1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
when :rowspan
|
84
|
+
@data.item.each_with_index do |item, item_index|
|
85
|
+
min_row_index = item_index + 1
|
86
|
+
max_row_index = min_row_index
|
87
|
+
((item_index + 1)..(@data.item.length - 1)).each do |i|
|
88
|
+
break if @data.item[i].level <= item.level
|
89
|
+
max_row_index = i + 1
|
90
|
+
end
|
91
|
+
|
92
|
+
unless min_row_index == max_row_index
|
93
|
+
ws.merge_cells(min_row_index, item.level - 1, max_row_index, item.level - 1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|