Class: Md2site::Md2site
- Inherits:
-
Object
- Object
- Md2site::Md2site
- Defined in:
- lib/md2site.rb
Overview
Markdown形式ファイルによるサイト作成クラス
Instance Method Summary collapse
-
#execute_command(cmd) ⇒ Object
サブコマンド実行.
-
#initialize(opts) ⇒ Md2site
constructor
初期化.
-
#option_parse(opts) ⇒ void
オプション解析.
-
#setup_env(conf_path, src_data_dir) ⇒ Object
構成ファイル、サイト固有設定ファイルで初期化.
Constructor Details
#initialize(opts) ⇒ Md2site
初期化
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/md2site.rb', line 90 def initialize(opts) @src_data_dir = File.(File.dirname(__FILE__) + %q(/../data)) @init = nil @testx = nil @make = nil @setup = nil @info = nil if opts[:debug] @debug = :debug @verbose = true elsif opts[:verbose] @debug = :verbose @verbose = true else @debug = :warn @verbose = false end @mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, @debug, nil, opts[:logfile]) @mes.register_exc @mes.add_exitcode("EXIT_CODE_BY_CANNOT_FIND_TARGET") @mes.add_exitcode("EXIT_CODE_BY_CANNOT_FIND_SUBTARGET") @mes.add_exitcode("EXIT_CODE_ILLEAGAL_TARGETCOMMAND") @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_CONFPATH") @mes.add_exitcode("EXIT_CODE_CANNOT_CONVERT_FROM_MD_TO_HTML") @mes.add_exitcode("EXIT_CODE_PANDOC_EXIT_ABNORMALLY") Filex::Filex.setup(@mes) @opt_struct = Struct.new(:name, :value) option_parse(opts) end |
Instance Method Details
#execute_command(cmd) ⇒ Object
サブコマンド実行
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/md2site.rb', line 196 def execute_command(cmd) @init ||= Init.new(@src_data_dir, @mes, @verbose) if cmd == "init" @init.execute_subcommand(@option, @option_url) elsif cmd == "testx" @testx ||= Testx.new(@option, @mes, @verbose, @src_data_dir, @opt_struct) conf_path, content_path = testx.execute_subcommandInit(@option_url) setup_env(conf_path, @src_data_dir) @testx.execute_subcommandRemain(@env, content_path, @str_variable, @str_static, @obj_by_yaml) else setup_env(@option_conf_path.value, @src_data_dir) unless @env case cmd when "make" @make ||= Make.new(@env, @mes, @verbose, @str_variable, @str_static, @obj_by_yaml) if @target_command == "_z" @env.commands.keys.map {|x| @make.do_multiple_commands(x) } else @make.execute_subcommand(@target_command, @subtarget_command) end when "setup" @setup ||= Setup.new(@env, @mes) @setup.execute_subcommand(@option) when "info" @info ||= Info.new(@env, @mes) @info.execute_subcommand(@option) end end end |
#option_parse(opts) ⇒ void
This method returns an undefined value.
オプション解析
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/md2site.rb', line 141 def option_parse(opts) @target_command = opts[:targetCommand] @subtarget_command = opts[:subTargetCommand] if opts[:zcontents] @option = @opt_struct.new("zcontents", opts[:zcontents]) elsif opts[:contentUpdate] @option = @opt_struct.new("contentUpdate") elsif opts[:getfiles] @option = @opt_struct.new("getfiles", opts[:getfiles]) elsif opts[:zlist] @option = @opt_struct.new("zlist") elsif opts[:zindex] @option = @opt_struct.new("zindex") elsif opts[:zsetup] @option = @opt_struct.new("zsetup", opts[:zsetup]) elsif opts[:init] @option = @opt_struct.new("init", opts[:init]) end @option_url = nil if opts[:url] @option_url = @opt_struct.new("url", opts[:url]) end @option_conf_path = @opt_struct.new("confPath", opts[:confPath]) end |
#setup_env(conf_path, src_data_dir) ⇒ Object
構成ファイル、サイト固有設定ファイルで初期化
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/md2site.rb', line 173 def setup_env(conf_path, src_data_dir) unless File.exist?(conf_path) @mes.output_fatal("Can't find #{conf_path} specified by -c or --confpath option") exit(@mes.ec("EXIT_CODE_CANNOT_FIND_CONFPATH")) end # 構成ファイル読み込みEnvクラスのインスタンスの属性としてアクセス可能にする @env = Env.new(conf_path, @mes, @verbose) # サイト固有設定ファイル(YAML形式ファイル)を読み込み、Rubyのハッシュとしてアクセス可能にする @obj_by_yaml = Filex::Filex.check_and_load_yamlfile(@env.absolutepath_root_settingfile, @mes) # Testdata.new(src_data_dir, @init.template_dir, @env.conf_hs) fname_variable = @env.conf_hs["ROOT_TEMPLATE_FUNCTIONS_VARIABLE"] @str_variable = Filex::Filex.check_and_load_file(fname_variable, @mes) if fname_variable fname_static = @env.conf_hs["ROOT_TEMPLATE_FUNCTIONS_STATIC"] @str_static = ["<% ", Filex::Filex.(fname_static, @obj_by_yaml, @mes), "%>"].join("\n") if fname_static end |