md2site 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +138 -0
  6. data/.rubocop_todo.yml +47 -0
  7. data/.travis.yml +7 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +98 -0
  10. data/LICENSE +8 -0
  11. data/LICENSE.txt +8 -0
  12. data/README.md +39 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/md2site +157 -0
  16. data/bin/setup +8 -0
  17. data/data/conf/conf-sample.yml +5 -0
  18. data/data/conf/conf.sh +32 -0
  19. data/data/conf/setting.yml +3 -0
  20. data/data/conf/site.tsv +1 -0
  21. data/data/template/5col_no_attr.erb +72 -0
  22. data/data/template/5col_no_attr_b.erb +72 -0
  23. data/data/template/functions_static.erb +10 -0
  24. data/data/template/functions_variable.erb +3 -0
  25. data/data/template2/contest_notification.erb +16 -0
  26. data/data/template2/contest_notification_2.erb +34 -0
  27. data/data/template2/contest_winners.erb +69 -0
  28. data/data/template2/contest_winners_statement.erb +1 -0
  29. data/data/testdata/conf-blog.yml +6 -0
  30. data/data/testdata/conf-download.yml +6 -0
  31. data/data/testdata/conf-link.yml +6 -0
  32. data/data/testdata/conf-profile.yml +6 -0
  33. data/data/testdata/conf-top.yml +6 -0
  34. data/data/testdata/site.tsv +5 -0
  35. data/data/testdata0/conf-appliction.yml +1 -0
  36. data/data/testdata0/conf-attempt.yml +69 -0
  37. data/data/testdata0/conf-autosar.yml +11 -0
  38. data/data/testdata0/conf-community.yml +3 -0
  39. data/data/testdata0/conf-document.yml +1 -0
  40. data/data/testdata0/conf-download.yml +1 -0
  41. data/data/testdata0/conf-edu.yml +52 -0
  42. data/data/testdata0/conf-etc.yml +1 -0
  43. data/data/testdata0/conf-members.yml +2 -0
  44. data/data/testdata0/conf-product.yml +37 -0
  45. data/data/testdata0/conf-project.yml +14 -0
  46. data/data/testdata0/conf-rtk.yml +25 -0
  47. data/data/testdata0/conf-top.yml +1 -0
  48. data/data/testdata0/setting.yml +33 -0
  49. data/data/testdata0/site.tsv +123 -0
  50. data/lib/md2site/env.rb +649 -0
  51. data/lib/md2site/htmlutils.rb +142 -0
  52. data/lib/md2site/htmlutils0.rb +223 -0
  53. data/lib/md2site/info.rb +17 -0
  54. data/lib/md2site/init.rb +90 -0
  55. data/lib/md2site/listfile.rb +22 -0
  56. data/lib/md2site/make.rb +295 -0
  57. data/lib/md2site/nkfguess.rb +33 -0
  58. data/lib/md2site/setup.rb +358 -0
  59. data/lib/md2site/statusfile.rb +75 -0
  60. data/lib/md2site/testdata.rb +50 -0
  61. data/lib/md2site/testx.rb +73 -0
  62. data/lib/md2site/version.rb +3 -0
  63. data/lib/md2site.rb +161 -0
  64. data/md2site.gemspec +59 -0
  65. metadata +359 -0
@@ -0,0 +1,142 @@
1
+ module Md2site
2
+ class HTMLUtils
3
+ require "md2site/nkfguess"
4
+
5
+ def initialize(htmlfname, mes)
6
+ @htmlfname = htmlfname
7
+ @mes = mes
8
+ end
9
+
10
+ def parse_line(state, line)
11
+ event = get_event(line)
12
+
13
+ @mes.output_debug("#{@lineno}|#{state}|#{event}|#{line}")
14
+
15
+ case state
16
+ when :IN_PART0
17
+ next_state = state_in_part0(event, line)
18
+ when :IN_PART1
19
+ next_state = state_in_part1(event, line)
20
+ when :IN_PART2
21
+ next_state = state_in_part2(event, line)
22
+ else
23
+ @mes.output_fatal("state=#{state}")
24
+ @mes.output_fatal("event=#{event}")
25
+ raise
26
+ end
27
+ next_state
28
+ end
29
+
30
+ def divide_html
31
+ part_struct = Struct.new(:lines, :status)
32
+ @part0 = part_struct.new([], false)
33
+ @part1 = part_struct.new([], false)
34
+ @part2 = part_struct.new([], false)
35
+
36
+ encoding = Nkfguess.guess_file(@htmlfname, @mes)
37
+ mode = "r:#{encoding}"
38
+ f = @mes.exc_file_gets(@htmlfname) { File.open(@htmlfname, mode) }
39
+
40
+ @lines = []
41
+ @lineno = 0
42
+ state = :IN_PART0
43
+ while (line = @mes.exc_file_gets(@htmlfname) { f.gets })
44
+ state = parse_line(state, line)
45
+ end
46
+ @part2.lines << @lines
47
+
48
+ @mes.exc_file_close(@htmlfname) { f.close }
49
+
50
+ [@part0.lines.flatten.join("\n"),
51
+ @part1.lines.flatten.join("\n"),
52
+ @part2.lines.flatten.join("\n")]
53
+ end
54
+
55
+ private
56
+
57
+ def get_event(line)
58
+ line.chomp!
59
+ begin
60
+ ldc = line.downcase
61
+ rescue Error => e
62
+ @mes.output_exception(e)
63
+ @mes.output_fatal("Can't convert downcase #{@htmlfname}")
64
+ exit(100)
65
+ rescue ArgumentError => e
66
+ @mes.output_exception(e)
67
+ @mes.output_fatal("Can't convert downcase #{@htmlfname}")
68
+ exit(100)
69
+ end
70
+ @lineno += 1
71
+ if ldc.index("<body")
72
+ event = :BODY_BEGIN
73
+
74
+ elsif ldc.index("</body>")
75
+ event = :BODY_END
76
+
77
+ else
78
+ event = :ELSE
79
+ end
80
+
81
+ event
82
+ end
83
+
84
+ def state_in_part0(event, line)
85
+ case event
86
+ when :BODY_BEGIN
87
+ @part0.lines << @lines
88
+ @lines = []
89
+ @lines << line
90
+ next_state = :IN_PART1
91
+ when :BODY_END
92
+ @lines << line
93
+ @part1.lines << @lines
94
+ @lines = []
95
+ next_state = :IN_PART2
96
+ when :ELSE
97
+ @lines << line
98
+ next_state = :IN_PART0
99
+ else
100
+ raise
101
+ end
102
+
103
+ next_state
104
+ end
105
+
106
+ def state_in_part1(event, line)
107
+ case event
108
+ when :BODY_BEGIN
109
+ @lines << line
110
+ next_state = :IN_PART1
111
+ when :BODY_END
112
+ @lines << line
113
+ @part1.lines << @lines
114
+ @lines = []
115
+ next_state = :IN_PART2
116
+ when :ELSE
117
+ @lines << line
118
+ next_state = :IN_PART1
119
+ else
120
+ raise
121
+ end
122
+
123
+ next_state
124
+ end
125
+
126
+ def state_in_part2(event, line)
127
+ case event
128
+ when :BODY_BEGIN
129
+ raise
130
+ when :BODY_END
131
+ raise
132
+ when :ELSE
133
+ @lines << line
134
+ next_state = :IN_PART2
135
+ else
136
+ raise
137
+ end
138
+
139
+ next_state
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,223 @@
1
+ module Md2site
2
+ class HTMLUtils
3
+ require "md2site/nkfguess"
4
+
5
+ def initialize(htmlfname, mes)
6
+ @htmlfname = htmlfname
7
+ @mes = mes
8
+ end
9
+
10
+ def parse_line(state, line)
11
+ event = get_event(line)
12
+
13
+ @mes.output_debug("#{@lineno}|#{state}|#{event}|#{line}")
14
+
15
+ case state
16
+ when :IN_PART0
17
+ next_state = state_in_part0(event, line)
18
+ when :IN_PART0_CONTENTS
19
+ next_state = state_in_part0_contents(event, line)
20
+ when :IN_PART1
21
+ next_state = state_in_part1(event, line)
22
+ when :IN_PART2
23
+ next_state = state_in_part2(event, line)
24
+ else
25
+ @mes.output_fatal("state=#{state}")
26
+ @mes.output_fatal("event=#{event}")
27
+ raise
28
+ end
29
+ next_state
30
+ end
31
+
32
+ def divide_html
33
+ part_struct = Struct.new(:lines, :status)
34
+ @part0 = part_struct.new([], false)
35
+ @part1 = part_struct.new([], false)
36
+ @part2 = part_struct.new([], false)
37
+ @div_body_main = nil
38
+ @div_cse = nil
39
+
40
+ encoding = Nkfguess.guess_file(@htmlfname, @mes)
41
+ mode = "r:#{encoding}"
42
+ f = @mes.exc_file_gets(@htmlfname) { File.open(@htmlfname, mode) }
43
+
44
+ @lines = []
45
+ @lineno = 0
46
+ state = :IN_PART0
47
+ while (line = @mes.exc_file_gets(@htmlfname) { f.gets })
48
+ state = parse_line(state, line)
49
+ end
50
+ @part2.lines << @lines
51
+
52
+ @mes.exc_file_close(@htmlfname) { f.close }
53
+
54
+ [@part0.lines.flatten.join("\n"),
55
+ @part1.lines.flatten.join("\n"),
56
+ @part2.lines.flatten.join("\n")]
57
+ end
58
+
59
+ private
60
+
61
+ def get_event(line)
62
+ line.chomp!
63
+ @lineno += 1
64
+ if line.index("CONTENTS BEGIN")
65
+ event = :CONTENTS_BEGIN
66
+ elsif line.index("CONTENTS END")
67
+ event = :CONTENTS_END
68
+ elsif line.index("<div")
69
+ if line.index(%Q(id="body_main"))
70
+ event = :ID_BODY_MAIN
71
+ elsif line.index(%Q(id="cse"))
72
+ event = :ID_CSE
73
+ else
74
+ event = :ELSE
75
+ end
76
+ elsif /^\s*$/.match?(line)
77
+ event = :WHITE_SPACE
78
+ else
79
+ event = :ELSE
80
+ end
81
+ event
82
+ end
83
+
84
+ def state_in_part0_contents_end(line)
85
+ @part0.lines << @lines
86
+ if !@div_body_main.nil? && !@div_cse.nil?
87
+ @part0.status = true
88
+ end
89
+ @lines = []
90
+ @lines << line
91
+ raise unless @div_body_main
92
+ raise unless @div_cse
93
+ :IN_PART2
94
+ end
95
+
96
+ def state_in_part0(event, line)
97
+ case event
98
+ when :CONTENTS_BEGIN
99
+ @part0.lines << @lines
100
+ if !@div_body_main.nil? && !@div_cse.nil?
101
+ @part0.status = true
102
+ end
103
+ @lines = []
104
+ @lines << line
105
+ next_state = :IN_PART0_CONTENTS
106
+ when :CONTENTS_END
107
+ next_state = state_in_part0_contents_end(line)
108
+ when :ID_BODY_MAIN
109
+ @lines << line
110
+ @div_body_main ||= line
111
+ next_state = :IN_PART1
112
+ when :ID_CSE
113
+ @lines << line
114
+ @div_cse ||= line
115
+ next_state = :IN_PART1
116
+ when :WHITE_SPACE
117
+ @lines << line
118
+ next_state = :IN_PART1
119
+ when :ELSE
120
+ @lines << line
121
+ next_state = :IN_PART1
122
+ else
123
+ raise
124
+ end
125
+ next_state
126
+ end
127
+
128
+ def state_in_part0_contents_contents_env(line)
129
+ @part1.lines << @lines
130
+ if !@div_body_main.nil? && !@div_cse.nil?
131
+ @part1.status = true
132
+ end
133
+ @lines = []
134
+ @lines << line
135
+ raise unless @div_body_main
136
+ raise unless @div_cse
137
+ :IN_PART2
138
+ end
139
+
140
+ def state_in_part0_contents(event, line)
141
+ case event
142
+ when :CONTENTS_BEGIN
143
+ @lines << line
144
+ next_state = :IN_PART0_CONTENTS
145
+ when :CONTENTS_END
146
+ next_state = state_in_part0_contents_contents_env(line)
147
+ when :ID_BODY_MAIN
148
+ @lines << line
149
+ @div_body_main = line
150
+ next_state = :IN_PART0_CONTENTS
151
+ when :ID_CSE
152
+ @lines << line
153
+ @div_cse = line
154
+ next_state = :IN_PART0_CONTENTS
155
+ when :WHITE_SPACE
156
+ @lines << line
157
+ next_state = :IN_PART0_CONTENTS
158
+ when :ELSE
159
+ @part0.lines << @lines
160
+ if !@div_body_main.nil? && !@div_cse.nil?
161
+ @part0.status = true
162
+ end
163
+ @lines = []
164
+ @lines << line
165
+ next_state = :IN_PART1
166
+ else
167
+ raise
168
+ end
169
+ next_state
170
+ end
171
+
172
+ def state_in_part1_contents_end(line)
173
+ @part1.lines << @lines
174
+ if !@div_body_main.nil? && !@div_cse.nil?
175
+ @part1.status = true
176
+ end
177
+ @lines = []
178
+ @lines << line
179
+ raise unless @div_body_main
180
+ raise unless @div_cse
181
+ :IN_PART2
182
+ end
183
+
184
+ def state_in_part1(event, line)
185
+ case event
186
+ when :CONTENTS_BEGIN
187
+ @part0.lines << @lines
188
+ @lines = []
189
+ @lines << line
190
+ next_state = :IN_PART0_CONTENTS
191
+ when :CONTENTS_END
192
+ next_state = state_in_part1_contents_end(line)
193
+ when :ID_BODY_MAIN
194
+ @div_body_main = line
195
+ @part0.lines << line
196
+
197
+ next_state = :IN_PART1
198
+ when :ID_CSE
199
+ @div_cse = line
200
+ @part0.lines << line
201
+
202
+ next_state = :IN_PART1
203
+ when :WHITE_SPACE
204
+ @lines << line
205
+ next_state = :IN_PART1
206
+ when :ELSE
207
+ @lines << line
208
+ next_state = :IN_PART1
209
+ else
210
+ @mes.output_fatal("state=:IN_PART1")
211
+ @mes.output_fatal("event=#{event}|")
212
+ raise
213
+ end
214
+ next_state
215
+ end
216
+
217
+ def state_in_part2(event, line)
218
+ @lines << line
219
+
220
+ :IN_PART2
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,17 @@
1
+ module Md2site
2
+ class Info
3
+ def initialize(env, mes)
4
+ @env = env
5
+ @mes = mes
6
+ end
7
+
8
+ def execute_subcommand(option)
9
+ case option.name
10
+ when "zlist"
11
+ @env.make_zlist.map {|x| @mes.output_fatal(x) }
12
+ when "zindex"
13
+ @env.make_zindex_html
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,90 @@
1
+ module Md2site
2
+ class Init
3
+ attr_reader :hs, :confFile, :templateDir
4
+
5
+ require "md2site/testdata"
6
+
7
+ def initialize(src_root_dir, mes, verbose)
8
+ @mes = mes
9
+ @verbose = verbose
10
+ @src_root_dir = src_root_dir
11
+
12
+ @conf_file = CONF_FILE
13
+ @conf_dir = CONF_DIR
14
+ @template_dir = TEMPLATE_DIR
15
+ @root_output_dir = OUTPUT_DIR
16
+ @hs = {
17
+ "rootOutputDir" => @root_output_dir,
18
+ "templateDir" => @template_dir,
19
+ "confDir" => @conf_dir,
20
+ "rootSrcDir" => SRC_DIR,
21
+ "statusFile" => STATUS_FILE,
22
+ "siteFile" => SITE_FILE,
23
+ "settingfile" => SETTING_FILE,
24
+ "dataDir" => DATA_DIR,
25
+ "workDir" => WORK_DIR,
26
+ "materialDir" => MATERIAL_DIR,
27
+ "categoryConfPrefix" => CATEGORY_CONF_PREFIX,
28
+ "defaultTableTampleteFile" => DEFAULT_TABLE_TEMPLATE_FILE,
29
+ }
30
+ end
31
+
32
+ def execute_subcommand(option, option_url)
33
+ root_dir = option.value
34
+ unless File.exist?(root_dir)
35
+ @mes.exc_make_directory(root_dir) { FileUtils.mkdir_p(root_dir, { verbose: @verbose }) }
36
+ end
37
+ absolute_path_root = File.absolute_path(option.value)
38
+
39
+ if option_url
40
+ url = %Q(URL=#{option_url.value})
41
+ else
42
+ url = DEFAULT_URL_SETTING
43
+ end
44
+
45
+ @hs[KEY_ABSOLUTE_PATH_ROOT] = absolute_path_root
46
+ @hs[KEY_URL] = url
47
+
48
+ td = Testdata.new(@src_root_dir, @template_dir, hs)
49
+
50
+ copy_all_files(@src_root_dir, @conf_dir, absolute_path_root, @conf_dir)
51
+ template_dir_array = td.template_dir_array
52
+ copy_templatefile(@src_root_dir, template_dir_array, absolute_path_root, @template_dir)
53
+ files = expand_and_write_files(@src_root_dir, @conf_dir, absolute_path_root, [@conf_file], @hs)
54
+ root_output_path = File.join(absolute_path_root, @root_output_dir)
55
+ @mes.exc_make_directory(root_output_path) { FileUtils.mkdir_p(root_output_path, { verbose: @verbose }) }
56
+ @env = Env.new(files[0], @mes, @verbose)
57
+ end
58
+
59
+ private
60
+
61
+ def expand_and_write_files(src_root_dir, src_dir, dest_root_dir, files, hash)
62
+ files.map do |x|
63
+ src_path = File.join(src_root_dir, src_dir, x)
64
+ content = Filex::Filex.check_and_expand_file(src_path, hash, @mes)
65
+ dest_dir = File.join(dest_root_dir, src_dir)
66
+ @mes.exc_make_directory(dest_dir) { FileUtils.mkdir_p(dest_dir, { verbose: @verbose }) }
67
+ dest_path = File.join(dest_dir, x)
68
+ @mes.exc_file_write(dest_path) { File.open(dest_path, "w") {|f| f.puts(content) } }
69
+ dest_path
70
+ end
71
+ end
72
+
73
+ def copy_templatefile(src_root_dir, src_dir_array, dest_root_dir, dest_dir)
74
+ src_dir_array.map {|x| copy_all_files(src_root_dir, x, dest_root_dir, dest_dir) }.flatten
75
+ end
76
+
77
+ def copy_all_files(src_root_dir, src_dir, dest_root_dir, dest_dir)
78
+ dir = File.join(src_root_dir, src_dir)
79
+ files = Dir[%Q(#{dir}/*)].map do |x|
80
+ fname = File.basename(x)
81
+ dest_path = File.join(dest_root_dir, dest_dir, fname)
82
+ dest_dir_path = File.dirname(dest_path)
83
+ @mes.exc_make_directory(dest_dir_path) { FileUtils.mkdir_p(dest_dir_path, { verbose: @verbose }) }
84
+ @mes.exc_file_copy(x, dest_path) { FileUtils.cp(x, dest_path, { verbose: @verbose }) }
85
+ dest_path
86
+ end
87
+ files
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,22 @@
1
+ module Md2site
2
+ require "csv"
3
+
4
+ class ListFile
5
+ def initialize(dir, mes)
6
+ @fname = File.join(dir, LIST_FILE)
7
+ @mes = mes
8
+
9
+ @mes.exc_file_open(@fname) { @csv = CSV.open(@fname, "w", { col_sep: "\t", headers: true }) }
10
+
11
+ @csv.add_row([FIELD_FILENMAE, FIELD_DATETIMESTR, FIELD_UNIXTIME, FIELD_MD5])
12
+ end
13
+
14
+ def add(row)
15
+ @csv.add_row(row)
16
+ end
17
+
18
+ def close
19
+ @mes.exc_file_close(@fname) { @csv.close }
20
+ end
21
+ end
22
+ end