mdextab 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/makemdtab CHANGED
@@ -14,30 +14,30 @@ if ARGV.empty?
14
14
  end
15
15
 
16
16
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Mdextab::VERSION, nil) do |parser|
17
- parser.on("--debug") {|_x| opts["debug"] = true }
18
- parser.on("--verbose") {|_x| opts["verbose"] = true }
19
- parser.on("--es path") {|x| opts["fnameStatic"] = x }
20
- parser.on("--ev path") {|x| opts["fnameVariable"] = x }
21
- parser.on("-t path", "--template") {|x| opts["template"] = opts["t"] = x }
22
- parser.on("-y path", "--yaml") {|x| opts["yaml"] = opts["y"] = x }
23
- parser.on("-o path", "--output") {|x| opts["output"] = opts["o"] = x }
24
- parser.on("-d path", "--data") {|x| opts["data"] = opts["d"] = x }
17
+ parser.on("--debug") { |_x| opts["debug"] = true }
18
+ parser.on("--verbose") { |_x| opts["verbose"] = true }
19
+ parser.on("--es path") { |x| opts["fnameStatic"] = x }
20
+ parser.on("--ev path") { |x| opts["fnameVariable"] = x }
21
+ parser.on("-t path", "--template") { |x| opts["template"] = opts["t"] = x }
22
+ parser.on("-y path", "--yaml") { |x| opts["yaml"] = opts["y"] = x }
23
+ parser.on("-o path", "--output") { |x| opts["output"] = opts["o"] = x }
24
+ parser.on("-d path", "--data") { |x| opts["data"] = opts["d"] = x }
25
25
  parser.on("--dataop op") do |x|
26
- if /^f/.match?(x.downcase)
27
- opts["dataop"] = :FILE_INCLUDE
28
- else
29
- opts["dataop"] = :YAML_TO_MD
30
- end
26
+ opts["dataop"] = if /^f/.match?(x.downcase)
27
+ :FILE_INCLUDE
28
+ else
29
+ :YAML_TO_MD
30
+ end
31
31
  end
32
32
  end
33
33
 
34
- if opts["debug"]
35
- mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :debug)
36
- elsif opts["verbose"]
37
- mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :verbose)
38
- else
39
- mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0)
40
- end
34
+ mes = if opts["debug"]
35
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :debug)
36
+ elsif opts["verbose"]
37
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :verbose)
38
+ else
39
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0)
40
+ end
41
41
 
42
42
  unless opts["data"]
43
43
  puts("Not specified -data")
@@ -55,11 +55,11 @@ opts["data"] = File.expand_path(opts["data"])
55
55
  opts["output"] = File.expand_path(opts["output"])
56
56
  opts["yaml"] = File.expand_path(opts["yaml"]) if opts["yaml"]
57
57
 
58
- if opts["yaml"]
59
- auxhs = Filex::Filex.checkAndLoadYamlfile(opts["yaml"], mes)
60
- else
61
- auxhs = {}
62
- end
58
+ auxhs = if opts["yaml"]
59
+ Filex::Filex.checkAndLoadYamlfile(opts["yaml"], mes)
60
+ else
61
+ {}
62
+ end
63
63
 
64
64
  x.makeMd2(opts["template"], auxhs)
65
65
  x.postProcess
data/bin/mdextab CHANGED
@@ -9,7 +9,7 @@ opts = {}
9
9
  banner = "Usage: bundle exec ruby bin/mdextab in_md_fname out_md_fname settng_yaml auxiliary_setting_yaml"
10
10
 
11
11
  Simpleoptparse::Simpleoptparse.parse(ARGV, opts, banner, Mdextab::VERSION, nil) do |parser|
12
- parser.on("-d", "--debug") {|_x| opts["debug"] = true }
12
+ parser.on("-d", "--debug") { |_x| opts["debug"] = true }
13
13
  end
14
14
 
15
15
  fname = ARGV[0]
data/lib/mdextab/layer.rb CHANGED
@@ -40,6 +40,7 @@ module Mdextab
40
40
  # @return [Symbol] 現在の状態
41
41
  def cur_state
42
42
  raise if @cur_layer.cur_state.class != Symbol
43
+
43
44
  @cur_layer.cur_state
44
45
  end
45
46
 
@@ -50,9 +51,9 @@ module Mdextab
50
51
  @cur_layer.table = val
51
52
  end
52
53
 
53
- # @overload tablee=(val)
54
+ # @overload tablee
54
55
  # カレントレイヤーのtableを取得
55
- # @param val [Table] カレントレイヤーのtable
56
+ # @return [Table] カレントレイヤーのtable
56
57
  def table
57
58
  @cur_layer.table
58
59
  end
@@ -83,11 +84,11 @@ module Mdextab
83
84
  @size = @layers.size
84
85
  # raise if state.class != Symbol
85
86
  new_layer.cur_state = state
86
- if @cur_layer
87
- new_layer.star = @cur_layer.star
88
- else
89
- new_layer.star = false
90
- end
87
+ new_layer.star = if @cur_layer
88
+ @cur_layer.star
89
+ else
90
+ false
91
+ end
91
92
  @cur_layer = new_layer
92
93
  end
93
94
 
@@ -123,9 +124,7 @@ module Mdextab
123
124
  # @return [void]
124
125
  def process_nested_table_start(token, lineno, fname)
125
126
  # TBODYトークンが出現する前にTABLE_STARTトークンが出現した場合、仮想的なTBODYトークンが出現したとみなす
126
- if table.tbody.nil?
127
- table.add_tbody(lineno)
128
- end
127
+ table.add_tbody(lineno) if table.tbody.nil?
129
128
  @mes.output_debug("B process_nested_table_start 1 @cur_layer.table=#{@cur_layer.table.object_id} token.kind=#{token.kind} token.opt[:lineno]=#{token.opt[:lineno]} cur_state=#{@cur_layer.cur_state}")
130
129
  # 新しいレイヤーを追加して、それをカレントレイヤーとし、カレントレイヤーにTableを追加する
131
130
  add_layer(fname, lineno, :OUT_OF_TABLE)
@@ -199,7 +198,7 @@ module Mdextab
199
198
  if @layers.size > 1
200
199
  @mes.output_fatal("illeagal nested env after parsing|:OUT_OF_TABLE")
201
200
  @mes.output_fatal("@layers.size=#{@layers.size} :TABLE_START #{fname} #{table.lineno}")
202
- @layers.map {|x| @mes.output_debug("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") }
201
+ @layers.map { |x| @mes.output_debug("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") }
203
202
  @mes.output_debug("== table")
204
203
  @mes.output_info(table)
205
204
  exit(@mes.ec("EXIT_CODE_EXCEPTION"))
@@ -208,7 +207,7 @@ module Mdextab
208
207
  if @layers.size > 1
209
208
  @mes.output_fatal("illeagal nested env after parsing|:START")
210
209
  @mes.output_fatal("@layers.size=#{@layers.size}")
211
- @layers.map {|x| @mes.output_error("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") }
210
+ @layers.map { |x| @mes.output_error("== @layers.cur_state=#{x.cur_state} :TABLE_START #{fname} #{x.table.lineno}") }
212
211
  @mes.output_error("== table")
213
212
  @mes.output_error(table)
214
213
  exit(@mes.ec("EXIT_CODE_EXCEPTION"))
@@ -217,7 +216,7 @@ module Mdextab
217
216
  @mes.output_fatal("illeagal state after parsing(@cur_layer.cur_state=#{@cur_layer.cur_state}|fname=#{fname}")
218
217
  @mes.output_fatal("@layers.size=#{@layers.size}")
219
218
  @mes.output_error("== cur_state=#{@cur_layer.cur_state}")
220
- @layers.map {|x| @mes.output_error("== @layers.cur_state=#{x.cur_state} #{fname}:#{x.table.lineno}") }
219
+ @layers.map { |x| @mes.output_error("== @layers.cur_state=#{x.cur_state} #{fname}:#{x.table.lineno}") }
221
220
  @mes.output_error("")
222
221
  exit(@mes.ec("EXIT_CODE_ILLEAG<AL_STATE"))
223
222
  end
@@ -1,3 +1,4 @@
1
+ # テーブル拡張Markdownモジュール
1
2
  module Mdextab
2
3
  require "digest"
3
4
  require "pp"
@@ -9,8 +10,8 @@ module Mdextab
9
10
  #
10
11
  # 初期化
11
12
  #
12
- # @param opt [Hash] オプション
13
- # @option opt [Symbol] :debug Messagexクラスのインスタンスに与えるデバッグモード
13
+ # @param opts [Hash] オプション
14
+ # @option opts [Symbol] :debug Messagexクラスのインスタンスに与えるデバッグモード
14
15
  # @param eruby_variable_str [String] 2回の置き換えが必要なeRubyスクリプト
15
16
  # @param eruby_static_str [String] 1回の置き換えが必要なeRubyスクリプト
16
17
  # @param obj_by_yaml [Hash] eRubyスクリプト向け置換用ハッシュ
@@ -24,15 +25,13 @@ module Mdextab
24
25
  @obj_by_yaml = obj_by_yaml
25
26
 
26
27
  @mes = mes
27
- unless @mes
28
- if opts[:debug]
29
- @mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :debug)
30
- elsif opts[:verbose]
31
- @mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :verbose)
32
- else
33
- @mes = Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0)
34
- end
35
- end
28
+ @mes ||= if opts[:debug]
29
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :debug)
30
+ elsif opts[:verbose]
31
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0, :verbose)
32
+ else
33
+ Messagex::Messagex.new("EXIT_CODE_NORMAL_EXIT", 0)
34
+ end
36
35
  @mes.add_exitcode("EXIT_CODE_ILLEGAL_DATAOP")
37
36
  Filex::Filex.setup(@mes)
38
37
 
@@ -42,14 +41,14 @@ module Mdextab
42
41
  #
43
42
  # ファイルから生成(使われていない?)
44
43
  #
45
- # @param opt [Hash] オプション
46
- # @option opt [String] :debug Messagexクラスのインスタンスに与えるデバッグモード
47
- # @option opt [IO] :output 出力先IO
48
- # @param fname_variable_str [String] 2回の置き換えが必要なeRubyスクリプトファイル名
49
- # @param fname_static_str [String] 1回の置き換えが必要なeRubyスクリプトファイル名
44
+ # @param opts [Hash] オプション
45
+ # @option opts [String] :debug Messagexクラスのインスタンスに与えるデバッグモード
46
+ # @option opts [IO] :output 出力先IO
47
+ # @param fname_variable [String] 2回の置き換えが必要なeRubyスクリプトファイル名
48
+ # @param fname_static [String] 1回の置き換えが必要なeRubyスクリプトファイル名
50
49
  # @param root_settingfile [String] eRubyスクリプト向け置換用YAML形式ファイル名
51
50
  # @param mes [Messagex] Messagexクラスのインスタンス
52
- # @retrun [Makemdtab]
51
+ # @return [Makemdtab]
53
52
  def self.create(opts, fname_variable, fname_static, root_settingfile, mes)
54
53
  Filex::Filex.setup(mes)
55
54
 
@@ -71,7 +70,7 @@ module Mdextab
71
70
  # @param root_dir [String] ルートディレクト(templatefileが示す相対パスの起点)
72
71
  # @param templatefile [String,nil] テーブル拡張Makrdown形式の変換元YAML形式ファイルへの相対パス
73
72
  # @param auxhs [Hash] eRubyスクリプト向け置換用ハッシュ(@obj_by_yamlにマージする)
74
- # @retrun [void]
73
+ # @return [void]
75
74
  def make_md2(root_dir, templatefile=nil, auxhs={})
76
75
  # 補助的な置換用ハッシュを@obj_by_yamlにマージする
77
76
  objx = @obj_by_yaml.merge(auxhs)
@@ -93,7 +92,7 @@ module Mdextab
93
92
  else
94
93
  array = []
95
94
  end
96
- array.map {|x| @mes.exc_file_write(@outputfname) { @output.puts(x) } }
95
+ array.map { |x| @mes.exc_file_write(@outputfname) { @output.puts(x) } }
97
96
  end
98
97
 
99
98
  #
@@ -102,23 +101,23 @@ module Mdextab
102
101
  # @param root_dir [String] ルートディレクト(eruby_fnameが示す相対パスの起点)
103
102
  # @param eruby_fname [String] fileReadメソッド呼び出しを含むeRubyスクリプトファイル名
104
103
  # @param objx [Hash] eRubyスクリプト向け置換用ハッシュ
105
- # @retrun [Array<String>] 指定ファイルを取り込んで展開した結果の文字列の配列(ただし要素は1個のみ)
104
+ # @return [Array<String>] 指定ファイルを取り込んで展開した結果の文字列の配列(ただし要素は1個のみ)
106
105
  def load_file_include(root_dir, eruby_fname, objx)
107
106
  # eruby_fnameはfileReadメソッド呼び出しを含むeRubyスクリプトファイル
108
107
  # fileReadメソッドは、引数を読み込むべきファイルへのパスに変換して、ファイルを読み込む
109
108
 
110
109
  # fileReadメソッドで参照するparentDirという変数に、root_dirの値を割り当てる
111
- objy = { "parentDir" => "%q!" + root_dir + "!" }
110
+ objy = { "parentDir" => "%q!#{root_dir}!" }
112
111
  # @eruby_variable_strにfileReadメソッドの定義が含まれる
113
112
  eruby_exanpded_str = ""
114
113
  if @eruby_variable_str
115
- if @eruby_variable_str.empty?
116
- eruby_exanpded_str = ""
117
- else
118
- # 変数parent_dirをobjyで定義された値に置換て、fileReadメソッドの定義を完成させる
119
- # 置換して得られた文字列を、もう一度eRubyスクリプトにする
120
- eruby_exanpded_str = ["<% ", Filex::Filex.expand_str(@eruby_variable_str, objy, @mes), " %>"].join("\n")
121
- end
114
+ eruby_exanpded_str = if @eruby_variable_str.empty?
115
+ ""
116
+ else
117
+ # 変数parent_dirをobjyで定義された値に置換て、fileReadメソッドの定義を完成させる
118
+ # 置換して得られた文字列を、もう一度eRubyスクリプトにする
119
+ ["<% ", Filex::Filex.expand_str(@eruby_variable_str, objy, @mes), " %>"].join("\n")
120
+ end
122
121
  end
123
122
  # fileReadメソッド呼び出しを含むeRubyスクリプトファイルを読み込む
124
123
  mbstr = Filex::Filex.check_and_load_file(eruby_fname, @mes)
@@ -141,7 +140,7 @@ module Mdextab
141
140
  # @param datayamlfname [String] eRubyスクリプトファイルでもあるYAML形式ファイル
142
141
  # @param templatefile [String] YAML形式をテーブル拡張Markdwon形式に変換するeRubyスクリプトファイル
143
142
  # @param objx [Hash] eRubyスクリプト向け置換用ハッシュ
144
- # @retrun [Array<String>] 変換されたテーブル拡張Markdwon形式の文字列の配列(ただし要素は1個のみ)
143
+ # @return [Array<String>] 変換されたテーブル拡張Markdwon形式の文字列の配列(ただし要素は1個のみ)
145
144
  def load_yaml_to_md(datayamlfname, templatefile, objx)
146
145
  @mes.output_debug("datayamlfname=#{datayamlfname}")
147
146
  @mes.output_debug("objx=#{objx}")
@@ -159,9 +158,7 @@ module Mdextab
159
158
  @mes.output_debug("dx=#{dx}")
160
159
  # eRubyスクリプトにdatayamlfnameの内容を置換用ハッシュとして適用して、テーブル拡張Markdown形式に変換する
161
160
  # Filex::Filex.expand_strに渡すハッシュは、エラーメッセージに用いるためのものであり、eRubyスクリプトとは無関係である
162
- array = [Filex::Filex.expand_str(dx, objy, @mes, { "datayamlfname" => datayamlfname, "templatefile" => templatefile })]
163
-
164
- array
161
+ [Filex::Filex.expand_str(dx, objy, @mes, { "datayamlfname" => datayamlfname, "templatefile" => templatefile })]
165
162
  end
166
163
 
167
164
  #
data/lib/mdextab/table.rb CHANGED
@@ -32,7 +32,7 @@ module Mdextab
32
32
  #
33
33
  # @param lineno [Integer] TABLE_STARTトークンの出現行の行番号
34
34
  # @param mes [Messagex] Messagexクラスのインスタンス
35
- # @param sttr [String] TABLE_STARTトークンの属性
35
+ # @param attr [String] TABLE_STARTトークンの属性
36
36
  def initialize(lineno, mes, attr=nil)
37
37
  @lineno = lineno
38
38
  @attr = attr
@@ -70,18 +70,18 @@ module Mdextab
70
70
  #
71
71
  # @param debug [Symbol] デバッグ用フラグ true: デバッグ情報を付加する false: デバッグ情報を付加しない
72
72
  # @return [String] HTMLのTABLEタグとして文字列化したもの
73
- def to_s(debug=false)
74
- if @attr
75
- if debug
76
- str = %Q(<table #{@attr} lineno:#{@lineno}>)
77
- else
78
- str = %Q(<table #{@attr}>)
79
- end
80
- elsif debug
81
- str = %Q(<table lineno:#{@lineno}>)
82
- else
83
- str = %Q(<table>)
84
- end
73
+ def to_s(debug: false)
74
+ str = if @attr
75
+ if debug
76
+ %(<table #{@attr} lineno:#{@lineno}>)
77
+ else
78
+ %(<table #{@attr}>)
79
+ end
80
+ elsif debug
81
+ %(<table lineno:#{@lineno}>)
82
+ else
83
+ %(<table>)
84
+ end
85
85
 
86
86
  [str, @tbody.to_s, "</table>"].join("\n")
87
87
  end
data/lib/mdextab/tbody.rb CHANGED
@@ -18,8 +18,8 @@ module Mdextab
18
18
  #
19
19
  # 初期化
20
20
  #
21
- # @param fname [String] 構文解析対象のMarkdownファイル名
22
21
  # @param lineno [String] TBODYトークン出現行の行番号
22
+ # @param mes [Messagex] Messagexクラスのインスタンス
23
23
  def initialize(lineno, mes)
24
24
  @array = []
25
25
  @tr = nil
data/lib/mdextab/td.rb CHANGED
@@ -19,8 +19,8 @@ module Mdextab
19
19
  # @param content [String] TDトークンのコンテンツ
20
20
  # @param condense [Boolean] 文字列化方法 true:改行を含めない false:改行を含める
21
21
  # @return [void]
22
- def add(content, condnese)
23
- if condnese
22
+ def add(content, condense)
23
+ if condense
24
24
  if @content
25
25
  if @contnet.match?(/^\s*$/)
26
26
  @content = content.to_s
@@ -41,9 +41,9 @@ module Mdextab
41
41
  # @return [String] HTMLのTDタグとして文字列化したもの
42
42
  def to_s
43
43
  if @attr.nil?
44
- %Q(<td>#{@content}</td>)
44
+ %(<td>#{@content}</td>)
45
45
  else
46
- %Q(<td #{@attr}>#{@content}</td>)
46
+ %(<td #{@attr}>#{@content}</td>)
47
47
  end
48
48
  end
49
49
  end
data/lib/mdextab/th.rb CHANGED
@@ -41,9 +41,9 @@ module Mdextab
41
41
  # @return [String] HTMLのTHタグとして文字列化したもの
42
42
  def to_s
43
43
  if @attr.nil?
44
- %Q(<th>#{@content}</th>)
44
+ %(<th>#{@content}</th>)
45
45
  else
46
- %Q(<th #{@attr}>#{@content}</th>)
46
+ %(<th #{@attr}>#{@content}</th>)
47
47
  end
48
48
  end
49
49
  end
data/lib/mdextab/token.rb CHANGED
@@ -40,13 +40,10 @@ module Mdextab
40
40
  # @note TABLE_STARTトークンが存在するかもしれないと判断されたときに呼ばれる
41
41
  def get_token_table_start(line, lineno)
42
42
  if /^\s*<table>\s*$/.match?(line)
43
- ret = create_token(:TABLE_START, { lineno: lineno })
43
+ create_token(:TABLE_START, { lineno: lineno })
44
44
  elsif (m = /^\s*<table\s+(.+)>\s*$/.match(line))
45
- ret = create_token(:TABLE_START, { attr: m[1], lineno: lineno })
46
- else
47
- ret = nil
45
+ create_token(:TABLE_START, { attr: m[1], lineno: lineno })
48
46
  end
49
- ret
50
47
  end
51
48
 
52
49
  #
@@ -57,12 +54,7 @@ module Mdextab
57
54
  # @return [Struct,nil] 生成されたトークンまたはnil(トークンが存在しない場合)
58
55
  # @note TBODY_STARTトークンが存在するかもしれないと判断されたときに呼ばれる
59
56
  def get_token_tbody_start(line, lineno)
60
- if /^\s*<tbody>\s*$/.match?(line)
61
- ret = create_token(:TBODY_START, { lineno: lineno })
62
- else
63
- ret = nil
64
- end
65
- ret
57
+ (create_token(:TBODY_START, { lineno: lineno }) if /^\s*<tbody>\s*$/.match?(line))
66
58
  end
67
59
 
68
60
  #
@@ -74,7 +66,7 @@ module Mdextab
74
66
  # @param cont [String] 現在行の中の:の並びを区切り文字列とした場合の右側の部分
75
67
  # @return [Struct,nil] 生成されたトークンまたはnil(トークンが存在しない場合)
76
68
  # @note 先頭が:のときに呼ばれる
77
- def get_token_colon_start(line, lineno, nth, cont)
69
+ def get_token_colon_start(_line, lineno, nth, cont)
78
70
  if (m = /^th(.*)/.match(cont))
79
71
  cont2 = m[1]
80
72
  if (m2 = /^\s(.*)/.match(cont2))
@@ -112,12 +104,7 @@ module Mdextab
112
104
  # @return [Struct,nil] 生成されたトークンまたはnil(トークンが存在しない場合)
113
105
  # @note TABLE_ENDトークンが存在するかもしれないと判断されたときに呼ばれる
114
106
  def get_token_table_end(line, lineno)
115
- if %r{^\s*</table>\s*$}.match?(line)
116
- ret = create_token(:TABLE_END, { lineno: lineno })
117
- else
118
- ret = nil
119
- end
120
- ret
107
+ (create_token(:TABLE_END, { lineno: lineno }) if %r{^\s*</table>\s*$}.match?(line))
121
108
  end
122
109
 
123
110
  #
@@ -138,7 +125,7 @@ module Mdextab
138
125
  ret = get_token_table_start(line, lineno)
139
126
  when /^\s*<tbody/
140
127
  ret = get_token_tbody_start(line, lineno)
141
- when /^\s*(\:+)(.*)$/
128
+ when /^\s*(:+)(.*)$/
142
129
  nth = Regexp.last_match(1).size
143
130
  cont = Regexp.last_match(2)
144
131
  ret = get_token_colon_start(line, lineno, nth, cont)
data/lib/mdextab/tr.rb CHANGED
@@ -14,7 +14,7 @@ module Mdextab
14
14
  #
15
15
  # TRトークンのコンテンツ追加
16
16
  #
17
- # @param content [String] TRトークンのコンテンツ
17
+ # @param cont [String] TRトークンのコンテンツ
18
18
  # @return [void]
19
19
  def add(cont)
20
20
  @array << cont
@@ -1,4 +1,4 @@
1
1
  module Mdextab
2
2
  # バージョン番号
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.9".freeze
4
4
  end