class Md2site::Md2site
Markdown形式ファイルによるサイト作成クラス
Public Class Methods
初期化
@param opts [Hash] オプション @option opts [Boolean] :debug nilでなければMessagexクラスのインスタンスに与えるデバッグモードであり、かつFileUtilsクラスのインスタンスメソッドに与える:verboseオプションの値を真にする @option opts [Boolean] :verbose nilでなければMessagexクラスのインスタンスに与えるデバッグモードであり、、かつFileUtilsクラスのインスタンスメソッドに与える:verboseオプションの値を真にする @option opts [String] :logfile Messagexクラスのインスタンスに与えるLoggerの出力先ファイル名
# File lib/md2site.rb, line 90 def initialize(opts) @src_data_dir = File.expand_path(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
Public Instance Methods
サブコマンド実行
@param cmd [String] サブコマンド名
# 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
オプション解析
@param opts [Hash] オプション @option opts [String,nil] :targetCommand nilでなければターゲットコマンド名 @option opts [String,nil] :subTargetCommand nilでなければサブターゲットコマンド名 @option opts [String,nil] :zcontents nilでなければダウンロード先ディレクトリ名 @option opts [String,nil] :contentUpdate nilでなければアップデート元ディレクトリ名 @option opts [String,nil] :getfiles nilでなければダウンロード先ディレクトリ名 @option opts [true,nil] :zlist nilでなければinfoサブコマンドのzlistオプションが有効 @option opts [true,nil] :zindex nilでなければinfoサブコマンドのzindexオプションが有効 @option opts [true,nil] :contentUpdate nilでなければsetupサブコマンドのzupdateオプションが有効 @option opts [String,nil] :init nilでなければプロジェクトルートディレクトリ @option opts [String,nil] :url nilでなければダウンロード対象URL @option opts [String] :confPath 構成ファイルパス @return [void]
# 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
構成ファイル、サイト固有設定ファイルで初期化
@param conf_path [String] 構成ファイルパス @param src_data_dir [String] インストール先データディレクトリ名
# 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.check_and_expand_file(fname_static, @obj_by_yaml, @mes), "%>"].join("\n") if fname_static end