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,75 @@
1
+ module Md2site
2
+ require "yaml"
3
+
4
+ class StatusFile
5
+ attr_accessor :baseurl, :fname, :fpath, :last_datetime, :last_contents_path, :path
6
+
7
+ def initialize(path, baseurl, mes)
8
+ @path = path
9
+ @baseurl = baseurl
10
+ @mes = mes
11
+
12
+ mes.add_exitcode("EXIT_CODE_CANNOT_ANALYZE_YAMLFILE")
13
+ mes.add_exitcode("EXIT_CODE_CANNOT_DUMP_TO_YAML")
14
+
15
+ content = get_statusfile(@path)
16
+
17
+ if content && !content.strip.empty?
18
+ obj = Filex::Filex.load_yaml(content, @mes)
19
+ @baseurl = obj[:baseurl]
20
+ @fname = obj[:fname]
21
+ @fpath = obj[:path]
22
+ @last_datetime = obj[:last_datetime]
23
+ @last_contents_path = obj[:last_contents_path]
24
+ else
25
+ @baseurl = @baseurl
26
+ @fname = nil
27
+ @fpath = nil
28
+ @last_datetime = nil
29
+ @last_contents_path = nil
30
+ end
31
+ end
32
+
33
+ def output(path, content)
34
+ File.open(path, "w") do |ofile|
35
+ ofile.puts(content)
36
+ ofile.flush
37
+ end
38
+ end
39
+
40
+ def update
41
+ hs = { baseurl: @baseurl, fname: @fname, path: @fpath, last_datetime: @last_datetime, last_contents_path: @last_contents_path }
42
+ begin
43
+ content = YAML.dump(hs)
44
+ rescue Error => e
45
+ @mes.output_exception(e)
46
+ exit(@mes.ec("EXIT_CODE_CANNOT_DUMP_TO_YAML"))
47
+ end
48
+
49
+ return unless content
50
+
51
+ @mes.exc_file_write(@path) { output(@path, content) }
52
+ end
53
+
54
+ def get_statusfile(path)
55
+ unless path
56
+ raise
57
+ end
58
+
59
+ content = nil
60
+ if File.exist?(path)
61
+ @mes.exc_file_read(path) { content = File.read(path) }
62
+ end
63
+ content
64
+ end
65
+
66
+ def pint
67
+ @mes.output_info("baseurl=#{@baseurl}")
68
+ @mes.output_info("fname=#{@fname}")
69
+ @mes.output_info("fpath=#{@fpath}")
70
+ @mes.output_info("last_datetime=#{@last_datetime}")
71
+ @mes.output_info("last_contents_path=#{@last_contents_path}")
72
+ @mes.output_info("path=#{@path}")
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,50 @@
1
+ module Md2site
2
+ class Testdata
3
+ def initialize(src_data_dir, templatedir, hash, num=1)
4
+ @hash = hash
5
+ @src_data_dir = src_data_dir
6
+ @templatedir = templatedir
7
+ @content_division = @hash["CONTENT_DIVISION_WAY"]
8
+ check_additional_conf(@hash)
9
+ require_htmlutils(num) unless defined?(HTMLUtils)
10
+ end
11
+
12
+ def check_additional_conf(hash)
13
+ url = hash["url"]
14
+ hash["functions_variable"] ||= ""
15
+ hash["functions_static"] ||= %Q(ROOT_TEMPLATE_FUNCTIONS_VARIABLE=#{File.join(@src_data_dir, %q(/template/functions_variable.erb))})
16
+ hash["contentDivisionWay"] ||= ""
17
+
18
+ case url
19
+ when /www\.toppers\.jp/
20
+ hash["contentDivisionWay"] = "CONTENT_DIVISION_WAY=0"
21
+ hash["functions_variable"] = %Q(ROOT_TEMPLATE_FUNCTIONS_VARIABLE=#{File.join(@src_data_dir, %q(/template/functions_variable.erb))})
22
+ hash["functions_static"] = %Q(ROOT_TEMPLATE_FUNCTIONS_STATIC=#{File.join(@src_data_dir, %q(/template/functions_static.erb))})
23
+ end
24
+ end
25
+
26
+ def template_dir_array
27
+ array = [@templatedir]
28
+
29
+ case @hash["url"]
30
+ when /www\.toppers\.jp/
31
+ array << TEMPLATE_DIR2
32
+ end
33
+
34
+ array
35
+ end
36
+
37
+ def require_htmlutils(num=1)
38
+ if @content_division
39
+ num = @content_division.to_i
40
+ end
41
+
42
+ case num
43
+ when 0
44
+ require "md2site/htmlutils0"
45
+ else
46
+ require "md2site/htmlutils"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,73 @@
1
+ module Md2site
2
+ class Testx
3
+ def initialize(option, mes, verbose, src_data_dir, opt_struct)
4
+ @option = option
5
+ @mes = mes
6
+ @verbose = verbose
7
+ @src_data_dir = src_data_dir
8
+ @opt_struct = opt_struct
9
+ end
10
+
11
+ def execute_subcommand_init(option_url)
12
+ case option_url.value
13
+ when /northern\-cross\.info/
14
+ init_a(option_url, %q(/testdata/site.tsv), "testdata/*")
15
+ when /www\.toppers\.jp/
16
+ init_a(option_url, %q(/testdata/site.tsv), "testdata0/*")
17
+ when /example\.com/
18
+ init_b(@option, option_url)
19
+ else
20
+ init_b(@option, option_url)
21
+ end
22
+ end
23
+
24
+ def init_a(option_url, tsv_filepath, test_data_dir_path)
25
+ root_path = @option.value
26
+ optionx = @opt_struct.new("init", root_path)
27
+ init = Init.new(@src_data_dir, @mes, @verbose)
28
+ init.execute_subcommand(optionx, option_url)
29
+
30
+ conf_dir = File.join(root_path, init.hs["conf_dir"])
31
+ conf_path = File.join(conf_dir, init.confFile)
32
+ dir = File.dirname(root_path)
33
+ base = File.basename(root_path)
34
+ content_path = File.join(dir, %Q(#{base}-contents))
35
+ @mes.exc_make_directory(content_path) { FileUtils.mkdir_p(content_path) }
36
+ src_path = File.join(@src_data_dir, tsv_filepath)
37
+ dest_path = conf_dir
38
+ @mes.exc_file_copy(src_path, dest_path) { FileUtils.copy(src_path, dest_path) }
39
+ Dir[File.join(@src_data_dir, test_data_dir_path)].each do |x|
40
+ next if File.directory?(x)
41
+ @mes.exc_file_copy(x, conf_dir) { FileUtils.cp(x, conf_dir) }
42
+ end
43
+
44
+ [conf_path, content_path]
45
+ end
46
+
47
+ def init_b(option, option_url)
48
+ @mes.output_warn(%Q(option=#{option.value}))
49
+ @mes.output_warn(%Q(optionUrl=#{option_url.value}))
50
+ exit(@mes.ec("EXIT_CODE_NORMAL_EXIT"))
51
+ end
52
+
53
+ def execute_subcommand_remain(env, content_path, str_variable, str_static, obj_by_yaml)
54
+ setup = Setup.new(env, @mes)
55
+ optionx = @opt_struct.new("zcontents", content_path)
56
+ setup.execute_subcommand(optionx)
57
+ optionx = @opt_struct.new("getfiles", content_path)
58
+ setup.execute_subcommand(optionx)
59
+ optionx = @opt_struct.new("contentUpdate")
60
+ setup.execute_subcommand(optionx)
61
+
62
+ info = Info.new(env)
63
+ optionx = @opt_struct.new("zlist")
64
+ info.execute_subcommand(optionx)
65
+ optionx = @opt_struct.new("zindex")
66
+ info.execute_subcommand(optionx)
67
+
68
+ make = Make.new(env, @mes, @verbose, str_variable, str_static, obj_by_yaml)
69
+
70
+ env.commands.map {|x| make.do_multiple_commands(x[0]) }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Md2site
2
+ VERSION = "0.1.2"
3
+ end
data/lib/md2site.rb ADDED
@@ -0,0 +1,161 @@
1
+ require "md2site/version"
2
+
3
+ module Md2site
4
+ CONF_FILE = "conf.sh"
5
+ CONF_DIR = "conf"
6
+ TEMPLATE_DIR = "template"
7
+ OUTPUT_DIR = "output"
8
+ SRC_DIR = "src"
9
+ DATA_DIR = "data"
10
+ WORK_DIR = "work"
11
+ MATERIAL_DIR = "material"
12
+ STATUS_FILE = "status.txt"
13
+ SITE_FILE = "site.tsv"
14
+ SETTING_FILE = "setting.yml"
15
+ CATEGORY_CONF_PREFIX = "conf-"
16
+ DEFAULT_TABLE_TEMPLATE_FILE = "5col_no_attr_b.erb"
17
+ DEFAULT_URL_SETTING = %Q(# URL=http://example.com)
18
+ KEY_ABSOLUTE_PATH_ROOT = "absolutePathRoot"
19
+ KEY_URL = "url"
20
+ INCLUDE_INDICATOR = ":include"
21
+ ZINDEX_HTML_FILE = "zindex.html"
22
+ TARGET_COMMAND_OF_ALL = "_z"
23
+ SUB_TARGET_COMMAND_OF_ALL = "_z"
24
+ LIST_FILE = "filelist.tsv"
25
+ FIELD_FILENMAE = "filename"
26
+ FIELD_DATETIMESTR = "datetimestr"
27
+ FIELD_UNIXTIME = "unixtime"
28
+ FIELD_MD5 = "md5"
29
+ TEMPLATE_DIR2 = "template2"
30
+
31
+ class Error < StandardError; end
32
+ # Your code goes here...
33
+
34
+ class Md2site
35
+ require "mdextab"
36
+ require "messagex"
37
+ require "filex"
38
+ require "open3"
39
+ require "tempfile"
40
+ require "md2site/env"
41
+ require "md2site/init"
42
+ require "md2site/testdata"
43
+ require "md2site/setup"
44
+ require "md2site/info"
45
+ require "md2site/make"
46
+ require "md2site/testx"
47
+
48
+ attr_accessor :option, :optionUrl, :mes, :verbose, :srcDataDir, :optStruct
49
+
50
+ def initialize(opts)
51
+ @src_data_dir = File.expand_path(File.dirname(__FILE__) + %q(/../data))
52
+
53
+ @init = nil
54
+ @testx = nil
55
+ @make = nil
56
+ @setup = nil
57
+ @info = nil
58
+
59
+ if opts["debug"]
60
+ @debug = :debug
61
+ @verbose = true
62
+ elsif opts["verbose"]
63
+ @debug = :verbose
64
+ @verbose = true
65
+ else
66
+ @debug = :warn
67
+ @verbose = false
68
+ end
69
+
70
+ @mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, @debug, nil, opts["logfile"])
71
+ @mes.register_exc
72
+ @mes.add_exitcode("EXIT_CODE_BY_CANNOT_FIND_TARGET")
73
+ @mes.add_exitcode("EXIT_CODE_BY_CANNOT_FIND_SUBTARGET")
74
+ @mes.add_exitcode("EXIT_CODE_ILLEAGAL_TARGETCOMMAND")
75
+ @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_CONFPATH")
76
+ @mes.add_exitcode("EXIT_CODE_CANNOT_CONVERT_FROM_MD_TO_HTML")
77
+ @mes.add_exitcode("EXIT_CODE_PANDOC_EXIT_ABNORMALLY")
78
+ Filex::Filex.setup(@mes)
79
+
80
+ @opt_struct = Struct.new(:name, :value)
81
+
82
+ option_parse(opts)
83
+ end
84
+
85
+ def option_parse(opts)
86
+ @target_command = opts["targetCommand"]
87
+ @subtarget_command = opts["subTargetCommand"]
88
+ if opts["all"]
89
+ @option = @opt_struct.new("all", opts["all"])
90
+ elsif opts["zcontents"]
91
+ @option = @opt_struct.new("zcontents", opts["zcontents"])
92
+ elsif opts["contentUpdate"]
93
+ @option = @opt_struct.new("contentUpdate")
94
+ elsif opts["getfiles"]
95
+ @option = @opt_struct.new("getfiles", opts["getfiles"])
96
+ elsif opts["zlist"]
97
+ @option = @opt_struct.new("zlist")
98
+ elsif opts["zindex"]
99
+ @option = @opt_struct.new("zindex")
100
+ elsif opts["zsetup"]
101
+ @option = @opt_struct.new("zsetup", opts["zsetup"])
102
+ elsif opts["init"]
103
+ @option = @opt_struct.new("init", opts["init"])
104
+ end
105
+
106
+ @option_url = nil
107
+ if opts["url"]
108
+ @option_url = @opt_struct.new("url", opts["url"])
109
+ end
110
+ @option_conf_path = @opt_struct.new("confPath", opts["confPath"])
111
+ end
112
+
113
+ def setup_env(conf_path, src_data_dir)
114
+ unless File.exist?(conf_path)
115
+ @mes.output_fatal("Can't find #{conf_path} specified by -c or --confpath option")
116
+ exit(@mes.ec("EXIT_CODE_CANNOT_FIND_CONFPATH"))
117
+ end
118
+
119
+ @env = Env.new(conf_path, @mes, @verbose)
120
+
121
+ @obj_by_yaml = Filex::Filex.check_and_load_yamlfile(@env.absolutepath_root_settingfile, @mes)
122
+
123
+ Testdata.new(src_data_dir, @init.templateDir, @env.conf_hs)
124
+ fname_variable = @env.conf_hs["ROOT_TEMPLATE_FUNCTIONS_VARIABLE"]
125
+ @str_variable = Filex::Filex.check_and_load_file(fname_variable, @mes) if fname_variable
126
+ fname_static = @env.conf_hs["ROOT_TEMPLATE_FUNCTIONS_STATIC"]
127
+ @str_static = ["<% ", Filex::Filex.check_and_expand_file(fname_static, @obj_by_yaml, @mes), "%>"].join("\n") if fname_static
128
+ end
129
+
130
+ def execute_command(cmd)
131
+ @init ||= Init.new(@src_data_dir, @mes, @verbose)
132
+
133
+ if cmd == "init"
134
+ @init.execute_subcommand(@option, @option_url)
135
+ elsif cmd == "testx"
136
+ @testx ||= Testx.new(@option, @mes, @verbose, @src_data_dir, @opt_struct)
137
+ conf_path, content_path = testx.execute_subcommandInit(@option_url)
138
+ setup_env(conf_path, @src_data_dir)
139
+ @testx.execute_subcommandRemain(@env, content_path, @str_variable, @str_static, @obj_by_yaml)
140
+ else
141
+ setup_env(@option_conf_path.value, @src_data_dir) unless @env
142
+
143
+ case cmd
144
+ when "make"
145
+ @make ||= Make.new(@env, @mes, @verbose, @str_variable, @str_static, @obj_by_yaml)
146
+ if @target_command == "_z"
147
+ @env.commands.map {|x| @make.do_multiple_commands(x[0]) }
148
+ else
149
+ @make.execute_subcommand(@target_command, @subtarget_command)
150
+ end
151
+ when "setup"
152
+ @setup ||= Setup.new(@env, @mes)
153
+ @setup.execute_subcommand(@option)
154
+ when "info"
155
+ @info ||= Info.new(@env, @mes)
156
+ @info.execute_subcommand(@option)
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
data/md2site.gemspec ADDED
@@ -0,0 +1,59 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "md2site/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "md2site"
8
+ spec.version = Md2site::VERSION
9
+ spec.authors = ["yasuo kominami"]
10
+ spec.email = ["ykominami@gmail.com"]
11
+
12
+ spec.summary = %q{make Markdown to site with Pandoc.}
13
+ spec.description = %q{make Markdown to site with Pandoc.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "bin"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_runtime_dependency "bundler", "~> 2.0"
40
+
41
+ spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "byebug"
45
+ spec.add_development_dependency "power_assert", "~> 1.1.4"
46
+ spec.add_development_dependency "test-unit"
47
+ spec.add_development_dependency "test-unit-rr"
48
+ spec.add_development_dependency "rubocop"
49
+ spec.add_development_dependency "rubocop-performance"
50
+
51
+ spec.add_runtime_dependency "simpleoptparse"
52
+ spec.add_runtime_dependency "erubis"
53
+ spec.add_runtime_dependency "mdextab", "~> 0.1.4"
54
+ spec.add_runtime_dependency "nokogiri"
55
+ spec.add_runtime_dependency "messagex"
56
+ spec.add_runtime_dependency "filex"
57
+ spec.add_runtime_dependency "faraday"
58
+ spec.add_runtime_dependency "faraday_middleware"
59
+ end