Class: Md2site::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/md2site/env.rb

Overview

環境クラス

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf_path, mes, verbose) ⇒ Env

初期化

Parameters:

  • conf_path (String)

    構成ファイルのパス

  • mes (Messagex)

    Messagexクラスのインスタンス

  • verbose (Boolean)

    FileUtilsクラスのメソッドのverbose引数に与える値



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/md2site/env.rb', line 37

def initialize(conf_path, mes, verbose)
  @mes = mes
  @verbose = verbose
  register_exit_codes

  @envcheck = EnvCheck.new(mes, conf_path)

  # カテゴリ・ターゲットストラクト定義
  #
  # カテゴリに含まれるターゲットとサブターゲットを関連付ける
  # カテゴリはターゲットをまとめるのが役割である。。
  # ターゲット名は全カテゴリにおいて一意でなければならない。
  @category_target_struct = Struct.new(:target, :misc, :subTargets, :subTargetsByHtmlfile)

  # ターゲットストラクト定義
  #
  # ターゲットはサブターゲットをまとめるのが役割である。
  # サブターゲットは1個のHTMLを生成するのが役割である。
  # ターゲットストラクト定義はターゲット向けのものとサブターゲット向けのものとの両方を含んでいて、
  # ターゲット、サブターゲットのどちらに対しても用いる。
  #
  @target_struct = Struct.new(:name, :dir, :dataDir, :workDir, :materialDir, :htmldir, :htmlfile, :mdfile, :filedir, :except, :command, :aliashtmldir, :aliashtmlfile, :templates)

  # templateストラクト定義
  #
  # YAML形式ファイルまたはMakrdown型式ファイルから、Markdown形式ファイルを生成するために必要な情報を持つ
  @template_struct = Struct.new(:datafname, :templatefname, :outputfname, :macroname, :kind, :src_subtarget_name)

  # ファイルディレクトリストラクト定義
  #
  # Makrdown型式ファイルから、HTML形式ファイルを生成するために必要な情報を持つ
  @filedir_struct = Struct.new(:html_output, :html_input, :partAhtml, :partChtml, :input_md, :output_md, :root_output_md, :data_dir)

  # コマンドストラクト定義
  #
  # ターゲットコマンド名、サブターゲットコマンド名からターゲット、サブターゲットを得るための情報を持つ
  @command_struct = Struct.new(:target, :subtargets)

  # ターゲットコマンド名引きコマンドストラクトハッシュ
  @commands = {}

  # ターゲット名引きカテゴリ・ターゲットストラクトハッシュ
  @category_target = {}

  # 構成ファイル中の変数名をキー都市、変数値を値とする構成ハッシュ
  @conf_hs = {}

  @envcheck.check_conf_path
  @absolutepath_root = File.dirname(File.dirname(File.absolute_path(conf_path)))
  @conf_hs["ABSOLUTE_PATH_ROOT"] = @absolutepath_root
  setup_from_conf(conf_path, @conf_hs)

  check_conf_hs_for_attribute
  check_conf_hs_and_set
  check_conf_hs

  setup_category(@sitefile_path)
  setup_config
end

Instance Attribute Details

#absolutepath_rootString (readonly)

Returns プロジェクトルートディレクトリの絶対パス.

Returns:

  • (String)

    プロジェクトルートディレクトリの絶対パス



27
28
29
# File 'lib/md2site/env.rb', line 27

def absolutepath_root
  @absolutepath_root
end

#absolutepath_root_settingfileString (readonly)

Returns サイト固有設定ファイルの絶対パス.

Returns:

  • (String)

    サイト固有設定ファイルの絶対パス



29
30
31
# File 'lib/md2site/env.rb', line 29

def absolutepath_root_settingfile
  @absolutepath_root_settingfile
end

#alias_htmlfile_indexInteger (readonly)

Returns エイリアスHTMLファイル名のインデックス.

Returns:

  • (Integer)

    エイリアスHTMLファイル名のインデックス



25
26
27
# File 'lib/md2site/env.rb', line 25

def alias_htmlfile_index
  @alias_htmlfile_index
end

#category_targetHash (readonly)

ターゲット名引きカテゴリ・ターゲットストラクトハッシュ

Returns:

  • (Hash)

    ターゲット名をキーとして、カテゴリ・ターゲットストラクトを値とするハッシュ



21
22
23
# File 'lib/md2site/env.rb', line 21

def category_target
  @category_target
end

#commandsHash (readonly)

ターゲットコマンド名引きコマンドストラクトハッシュ

Returns:

  • (Hash)

    ターゲットコマンド名をキー、コマンドストラクトを値とするハッシュ



17
18
19
# File 'lib/md2site/env.rb', line 17

def commands
  @commands
end

#conf_hsHash (readonly)

構成ハッシュ

Returns:

  • (Hash)

    構成ファイルの変数名をキー、変数の値を値とするハッシュ



13
14
15
# File 'lib/md2site/env.rb', line 13

def conf_hs
  @conf_hs
end

#htmlfile_indexInteger (readonly)

Returns HTMLファイル名のインデックス.

Returns:

  • (Integer)

    HTMLファイル名のインデックス



23
24
25
# File 'lib/md2site/env.rb', line 23

def htmlfile_index
  @htmlfile_index
end

Instance Method Details

#check_conf_hsvoid

This method returns an undefined value.

構成ファイルから変換したハッシュに有効な値が指定されているか調べる(無効であればexitする)



148
149
150
# File 'lib/md2site/env.rb', line 148

def check_conf_hs
  @sitefile_path = @envcheck.check_conf_hs(@conf_hs, @absolutepath_root, @root_output_dir)
end

#check_conf_hs_and_setvoid

This method returns an undefined value.

構成ファイルから変換したハッシュに指定されている値が有効であれば、インスタンス変数で参照できるようにする(無効であればexitする)



156
157
158
# File 'lib/md2site/env.rb', line 156

def check_conf_hs_and_set # rubocop:disable Metrics/MethodLength
  @category_conf_prefix, @root_output_dir, @src_dir, @data_dir, @work_dir, @material_dir, @target_command_index, @subtarget_command_index, @key_index, @htmlfile_index, @alias_htmlfile_index = @envcheck.check_conf_hs_and_set(@conf_hs)
end

#check_conf_hs_for_attributevoid

This method returns an undefined value.

Envクラスのattributeとして有効な値が構成ファイル中に指定されているか調べる(無効であればexitする)



140
141
142
# File 'lib/md2site/env.rb', line 140

def check_conf_hs_for_attribute
  @absolute_path_root_conf, @absolutepath_root_settingfile = @envcheck.check_conf_hs_for_attribute(@conf_hs)
end

#check_site_tsv_and_category_conf(category_target_struct, obj) ⇒ void

This method returns an undefined value.

サイト構成ファイルとカテゴリ構成ファイルの検査(異常があればデバッグ用エラーメッセージ出力)

Parameters:

  • category_target_struct (Struct)

    検査対象のカテゴリ・ターゲットストラクト

  • obj (Hash)

    カテゴリ構成設定ファイル(YAML形式)を変換したハッシュ



454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/md2site/env.rb', line 454

def check_site_tsv_and_category_conf(category_target_struct, obj)
  category_subtarget_names = category_target_struct.subTargets.keys
  target_conf_subtarget_names = obj.keys

  ctkeys = category_subtarget_names - target_conf_subtarget_names
  unless ctkeys.empty?
    puts "target name=#{category_target_struct.target.name} category_only=#{ctkeys}"
  end
  tckeys = target_conf_subtarget_names - category_subtarget_names
  unless tckeys.empty?
    puts "target name=#{category_target_struct.target.name} site_only=#{tckeys}"
  end
  puts "==============" unless ctkeys.empty? || tckeys.empty?
end

#expand_variable(value, hash, subhs = {}) ⇒ String

変数展開 イコールの右辺にある変数名をhash,subhsのどちらかに含まれる、該当変数名をキーとしたハッシュの値に置き換える

Parameters:

  • value (String)

    展開元の変数の値

  • hash (Hash)

    置換用ハッシュ

  • subhs (Hash) (defaults to: {})

    第2置換用ハッシュ

Returns:

  • (String)

    展開された変数の値



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/md2site/env.rb', line 231

def expand_variable(value, hash, subhs={})
  @mes.output_debug("value=#{value}")
  if (m = /(\${([^}]+)})/.match(value))
    pattern = m[1]
    var_name = m[2]
    @mes.output_debug("var_name=#{var_name}")
    expand = hash[var_name]
    expand ||= subhs[var_name]
    @mes.output_debug("expand=#{expand}")
    expand ||= ENV[var_name]
    if expand
      value[pattern] = expand
      expand_variable(value, hash, subhs) if value.index("$")
    end
  end
  value
end

#get_filepath(path) ⇒ String

パスを絶対パスに変換

Parameters:

  • path (String, nil)

    nilでなければ引数pathの絶対パス

Returns:

  • (String)

    絶対パス



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/md2site/env.rb', line 546

def get_filepath(path)
  if path
    @mes.output_debug("0 path=#{path}")
    if File.exist?(path)
      abs_path = File.expand_path(path)
      @mes.output_debug("1 absPath=#{abs_path}")
    else
      abs_path = nil
    end
  else
    abs_path = nil
    @mes.output_debug("4 absPath=#{abs_path}")
  end
  abs_path
end

#get_sub_target(target_name, subtarget_name) ⇒ Struct

ターゲット名、サブターゲット名を指定してサブターゲットストラクト得る

Parameters:

  • target_name (String)

    ターゲット名

  • subtarget_name (String)

    サブターゲット名

Returns:

  • (Struct)

    指定されたサブターゲットストラクト



183
184
185
# File 'lib/md2site/env.rb', line 183

def get_sub_target(target_name, subtarget_name)
  @category_target[target_name].subTargets[subtarget_name]
end

#get_subtarget_by_htmlfile(target_name, htmlfpath) ⇒ Struct

ターゲット名と出力HTMLファイルから、サブターゲットストラクトを得る

Parameters:

  • target_name (String)

    ターゲット名

  • htmlfpath (String)

    出力HTMLファイルへのパス

Returns:

  • (Struct)

    指定されたサブターゲットストラクト



193
194
195
# File 'lib/md2site/env.rb', line 193

def get_subtarget_by_htmlfile(target_name, htmlfpath)
  @category_target[target_name].subTargetsByHtmlfile[htmlfpath]
end

#get_subtarget_commands(target_command) ⇒ Array<Struct>

指定ターゲットに属する全サブターゲットコマンド名を得る

Parameters:

  • target_command (String)

    ターゲットコマンド名

Returns:

  • (Array<Struct>)

    指定ターゲットに属する全サブターゲットコマンド名の配列



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/md2site/env.rb', line 165

def get_subtarget_commands(target_command)
  if @commands[target_command]
    if @commands[target_command][:subtargets]
      @commands[target_command][:subtargets].keys
    else
      []
    end
  else
    []
  end
end

#get_target_and_subtarget(target_command, subtarget_command) ⇒ Array

ターゲットコマンド名とサブターゲットコマンド名から、サブターゲットストラクトを得る

Parameters:

  • target_command (String)

    ターゲットコマンド名

  • subtarget_command (String)

    サブターゲットコマンド名

Returns:

  • (Array)

    第0要素 ターゲットストラクト、第1要素 サブターゲットストラクト



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/md2site/env.rb', line 203

def get_target_and_subtarget(target_command, subtarget_command)
  current_target = nil
  current_subtarget = nil
  @mes.output_info("Env.get_target_and_subtarget")
  @mes.output_info("target_command=#{target_command}")
  @mes.output_info("subtarget_command=#{subtarget_command}")
  if @commands[target_command]
    current_target = @commands[target_command][:target]
    if @commands[target_command][:subtargets]
      current_subtarget = @commands[target_command][:subtargets][subtarget_command]
    else
      @mes.output_info("@commands[target_command][:subtargets]")
    end
  else
    @mes.output_info("@commands[target_command]=nil")
    @mes.output_error("Not specified legal target command 1")
    exit(@mes.ec("EXIT_CODE_NOT_SPECIFIED_LEGAL_TARGET_COMMAND"))
  end
  [current_target, current_subtarget]
end

#make_anchor_tag(subtarget) ⇒ String

HTMLのアンカータグを生成

Parameters:

  • subtarget (Struct)

    サブターゲットストラクト

Returns:

  • (String)

    HTMLのアンカータグ



575
576
577
# File 'lib/md2site/env.rb', line 575

def make_anchor_tag(subtarget)
  %Q(<li><a href="#{subtarget.htmlfile}">#{subtarget.htmlfile}}</a></li>)
end

#make_html_firstString

HTMLの先頭部分の作成

Returns:

  • (String)

    HTMLの先頭部分



583
584
585
586
587
588
589
590
591
# File 'lib/md2site/env.rb', line 583

def make_html_first
  <<~_HTML_HEAD
    <html>
    <head>
    </head>
    <body>
    <ul>
  _HTML_HEAD
end

#make_html_lastString

HTMLの末尾部分の作成

Returns:

  • (String)

    HTMLの末尾部分



597
598
599
600
601
602
603
# File 'lib/md2site/env.rb', line 597

def make_html_last
  <<~_HTML_BODY_TAIL
    </ul>
    </body>
    </html>
  _HTML_BODY_TAIL
end

#make_template_struct(line, subtarget) ⇒ Strunct

templateストラクトの作成

Parameters:

  • line (String)

    サブコンポーネント指定

  • subtarget (Struct)

    サブターゲットストラクト

Returns:

  • (Strunct)

    templateストラクト



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/md2site/env.rb', line 475

def make_template_struct(line, subtarget)
  name, template, misc = line.split(",")
  macroname = name
  name_x = name.dup
  name_x[OUTPUT_DIR] = "" if name_x.index(OUTPUT_DIR)

  outputfname = File.join(subtarget.workDir, %Q(#{name_x}.md))

  src_subtarget_name = nil
  if template == INCLUDE_INDICATOR
    kind = :INCLUDE
    datafname = File.join(misc, %Q(#{name_x}.md))
    src_subtarget_name = name
  else
    kind = :NORMAL
    datafname = File.join(subtarget.dataDir, %Q(#{name_x}.yml))
  end
  @template_struct.new(datafname, template, outputfname, macroname, kind, src_subtarget_name)
end

#make_zindex_htmlvoid

This method returns an undefined value.

リンクの一覧のHTMLファイル作成



609
610
611
612
613
614
615
616
617
618
619
# File 'lib/md2site/env.rb', line 609

def make_zindex_html
  fname = File.join(@absolutepath_root, @root_output_dir, ZINDEX_HTML_FILE)
  @mes.exc_file_write(fname) do
    f = File.open(fname, "w")
    f.puts(make_html_first)
    anchors = @commands.map {|_, command_sturct| command_sturct[:subtargets].map {|_, subtarget| make_anchor_tag(subtarget) } }
    f.puts(anchors.flatten.join("\n"))
    f.puts(make_html_last)
    f.close
  end
end

#make_zlistString

makeサブコマンドの指定可能なターゲットコマンド名とサブターゲットコマンド名のオプション指定の組み合わせを返す

Returns:

  • (String)

    makeサブコマンドの指定可能なターゲットコマンド名とサブターゲットコマンド名のオプション指定の組み合わせ



566
567
568
# File 'lib/md2site/env.rb', line 566

def make_zlist
  @commands.map {|t_name, command_struct| command_struct[:subtargets].map {|_, s_hash| %Q(-t #{t_name} -s #{s_hash['command']}) } }.flatten
end

#normalize_alias_htmlpath(array) ⇒ Array

エイリアス指定をディレクトリ指定と、ファイル名指定に分解する

Parameters:

  • array (Array)

    カテゴリ別設定ファイルでのサブコンポーネント指定のフィールドの配列

Returns:

  • (Array)

    第0要素:エイリアスディレクトリ指定、第1要素:エイリアスファイル名指定



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/md2site/env.rb', line 281

def normalize_alias_htmlpath(array)
  if array.size >= (@alias_htmlfile_index + 1)
    alias_htmlfname = array[@alias_htmlfile_index]
    alias_dir = File.dirname(alias_htmlfname)
    alias_basename = File.basename(alias_htmlfname, ".html")
    if alias_dir == "."
      alias_html_dir = ""
    end
    alias_htmlfname_x = [alias_basename, "html"].join(".")
  else
    alias_html_dir = ""
    alias_htmlfname_x = ""
  end

  [alias_html_dir, alias_htmlfname_x]
end

#normalize_htmlpath(htmlfname) ⇒ Array

HTMLファイル名指定からディレクトリ指定と、ファイル名指定、サブターゲット名、Makrdownファイル名を得る

Parameters:

  • htmlfname (String)

    HTMLファイル名指定

Returns:

  • (Array)

    第0要素:サブターゲット名、第1要素:HTMLファイル名指定、第2要素:HTMLディレクトリ指定、第3要素:Markdownファイル名指定



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/md2site/env.rb', line 303

def normalize_htmlpath(htmlfname)
  dir = File.dirname(htmlfname)
  basename = File.basename(htmlfname)
  basename_no_ext = File.basename(htmlfname, ".html")
  if dir == "."
    subtarget_name = basename_no_ext
    htmldir = ""
  else
    subtarget_name = File.join(dir, basename_no_ext)
    htmldir = dir
  end
  htmlfname_x = basename
  mdfname = [basename_no_ext, "md"].join(".")

  [subtarget_name, htmlfname_x, htmldir, mdfname]
end

#register_exit_codesvoid

This method returns an undefined value.

終了ステータスの登録



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/md2site/env.rb', line 101

def register_exit_codes # rubocop:disable Metrics/MethodLength
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_CONFFILE")
  @mes.add_exitcode("EXIT_CODE_NOT_SPECIFIED_CONFFILE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ABSOLUTE_PATH_ROOT_CONF")
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_ROOTCONFFILE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_DEFAULT_TABLE_TEMPLATE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ABSOLUTE_PATH_ROOT_SETTINGFILE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ABSOLUTE_PATH_SITE_FILE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_TEPLATE_DIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_CONF_DIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_SRC_DIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_URL")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ROOT_TEMPLATE_FUNCTIONS_VARIABLE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ABSOLUTE_PATH_STATUS_FILE")
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_SITEFILEPATH")
  @mes.add_exitcode("EXIT_CODE_CANNOT_MAKE_ABSOLUTE_PATH_ROOT")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_TARGET_COMMAND_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_SUBTARGET_COMMAND_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_KEY_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_HTMLFILE_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ALIAS_HTMLFILE_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ABSOLUTE_PATH_ROOT")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_CATEGORY_CONF_PREFIX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_ROOTOUTPUTDIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_ROOTOUTPUTDIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_READ_CONFFNAME")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_DATA_DIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_WORK_DIR")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_MATERIAL_DIR")
  @mes.add_exitcode("EXIT_CODE_INVALID_INDEX")
  @mes.add_exitcode("EXIT_CODE_CANNOT_GET_TARGET")
  @mes.add_exitcode("EXIT_CODE_CANNOT_FIND_TARGETCONFYAMLPATH")
  @mes.add_exitcode("EXIT_CODE_NOT_SPECIFIED_LEGAL_TARGET_COMMAND")
end

#setup_category(file_path) ⇒ void

This method returns an undefined value.

サイト構成ファイルからターゲット名引きカテゴリ・ターゲットストラクトハッシュの設定(無効な指定があればexitする)

Parameters:

  • file_path (String)

    サイト構成ファイルへのパス



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/md2site/env.rb', line 421

def setup_category(file_path)
  @mes.exc_file_gets(file_path) do
    f = File.open(file_path)
    while (l = f.gets)
      l.chomp!
      next if /^#/.match?(l)
      next if l.strip.empty?
      array = l.split("\t")
      size = array.size
      if @target_command_index >= size
        @mes.output_fatal("Invalid targetCommandIndex(=#{@target_command_index})")
        exit(@mes.ec("EXIT_CODE_INVALID_INDEX"))
      end
      if @subtarget_command_index >= size
        @mes.output_fatal("Invalid subTargetCommandIndex(=#{@subtarget_command_index})")
        exit(@mes.ec("EXIT_CODE_INVALID_INDEX"))
      end
      if @htmlfile_index >= size
        @mes.output_fatal("Invalid htmlfileIndex(=#{@htmlfile_index})")
        exit(@mes.ec("EXIT_CODE_INVALID_INDEX"))
      end
      setup_category_oneline(array, file_path)
    end
    f.close
  end
end

#setup_category_oneline(fields, file_path) ⇒ void

This method returns an undefined value.

カテゴリ別設定ファイル内の1つのサブコンポーネント指定でのターゲット名引きカテゴリ・ターゲットストラクトハッシュ、

ターゲットコマンド名引きコマンドストラクトハッシュの設定

Parameters:

  • fields (Array)

    サイト固有設定ファイルでのサブカテゴリ指定のフィールドの配列

  • file_path (String)

    カテゴリ別設定ファイルへのパス



402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/md2site/env.rb', line 402

def setup_category_oneline(fields, file_path)
  target_command = fields[@target_command_index]
  subtarget_command = fields[@subtarget_command_index]
  target_name = fields[@key_index]
  if target_name.strip.empty?
    @mes.output_fatal("Cannot get target from #{file_path}")
    exit(@mes.ec("EXIT_CODE_CANNOT_GET_TARGET"))
  end

  stds, subtarget, htmlfname = setup_category_oneline_sub(fields, target_name, target_command, subtarget_command)

  setup_category_oneline_x(target_command, subtarget_command, stds, target_name, subtarget, htmlfname)
end

#setup_category_oneline_sub(fields, target_name, target_command, subtarget_command) ⇒ Array

サブコンポーネント指定のフィールドの値からサブターゲットストラクト生成

Parameters:

  • fields (Array)

    カテゴリ別設定ファイルでのサブコンポーネント指定のフィールドの配列

  • target_name (String)

    ターゲット名

  • target_command (String)

    ターゲットコマンド名

  • subtarget_command (String)

    サブターゲットコマンド名

Returns:

  • (Array)

    第0要素: サブターゲットストラクト 第1要素: サブターゲット名 第2要素: HTMLファイル名



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/md2site/env.rb', line 359

def setup_category_oneline_sub(fields, target_name, target_command, subtarget_command)
  if fields.size >= (@htmlfile_index + 1)
    htmlfname = fields[@htmlfile_index]
  else
    htmlfname = nil
  end
  alias_htmldir, alias_htmlfname_x = normalize_alias_htmlpath(fields)

  @mes.output_debug("htmlfname=#{htmlfname}")
  @mes.output_debug("alias_htmlfname_x=#{alias_htmlfname_x}")

  misc = fields
  target_dir = File.join(@src_dir, target_name)

  unless @category_target[target_name]
    tds = @target_struct.new(target_name, target_dir, nil, nil, nil, nil, nil, nil, nil, nil, target_command, nil, nil, [])
    @category_target[target_name] = @category_target_struct.new(tds, misc, {}, {})
  end
  unless @commands[target_command]
    @commands[target_command] ||= @command_struct.new(@category_target[target_name].target, {})
  end
  except = htmlfname.index("/") ? true : false

  subtarget_name, htmlfname_x, htmldir, mdfname = normalize_htmlpath(htmlfname)
  subtarget_name_x = subtarget_name.dup

  subtarget_dir = File.join(target_dir, subtarget_name_x)

  subtarget_data_dir = File.join(subtarget_dir, @data_dir)
  subtarget_work_dir = File.join(subtarget_dir, @work_dir)
  subtarget_material_dir = File.join(subtarget_dir, @material_dir)

  stds = @target_struct.new(subtarget_name, subtarget_dir, subtarget_data_dir, subtarget_work_dir, subtarget_material_dir, htmldir, htmlfname_x, mdfname, nil, except, subtarget_command, alias_htmldir, alias_htmlfname_x, [])
  [stds, subtarget_name, htmlfname]
end

#setup_category_oneline_x(target_command, subtarget_command, stds, target, subtarget, htmlfname) ⇒ void

This method returns an undefined value.

ターゲット名引きカテゴリ・ターゲットストラクトハッシュ、ターゲットコマンド名引きコマンドストラクトハッシュの設定

(適切なコマンド名でなければexitする)

Parameters:

  • target_command (String)

    ターゲットコマンド名

  • subtarget_command (String)

    サブターゲットコマンド名

  • stds (String)

    サブターゲットストラクト

  • target (String)

    ターゲット名

  • subtarget (String)

    サブターゲット名

  • htmlfname (String)

    HTMLファイル名



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/md2site/env.rb', line 331

def setup_category_oneline_x(target_command, subtarget_command, stds, target, subtarget, htmlfname)
  # ターゲット名引きカテゴリ・ターゲットストラクトハッシュに、ターゲット名、サブターゲット名に対応するサブターゲットストラクトを設定
  @category_target[target].subTargets[subtarget] = stds
  # ターゲット名引きカテゴリ・ターゲットハッシュに、ターゲット名、HTMLファイル名に対応するサブターゲットストラクトを設定
  @category_target[target].subTargetsByHtmlfile[htmlfname] = stds

  # ターゲットコマンド名引きコマンドストラクトハッシュに、ターゲットコマンド名、サブターゲットコマンド名に対応するサブターゲットストラクトを設定
  if @commands[target_command]
    if @commands[target_command][:subtargets]
      @commands[target_command][:subtargets][subtarget_command] = stds
    else
      @mes.output_error("Not specified legal target command 2")
      exit(@mes.ec("EXIT_CODE_NOT_SPECIFIED_LEGAL_TARGET_COMMAND"))
    end
  else
    @mes.output_error("Not specified legal target command 3")
    exit(@mes.ec("EXIT_CODE_NOT_SPECIFIED_LEGAL_TARGET_COMMAND"))
  end
end

#setup_configvoid

This method returns an undefined value.

全カテゴリに対して、対応するカテゴリ別設定ファイルの内容を反映する



526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/md2site/env.rb', line 526

def setup_config
  @category_target.each do |name, category_target_struct|
    target = name
    targetconf_yamlfile = %Q(#{@category_conf_prefix}#{target}.yml)
    targetconf_yamlpath = File.join(@absolute_path_root_conf, targetconf_yamlfile)
    unless File.exist?(targetconf_yamlpath)
      @mes.output_error("Can't find targetconf_yamlpath(=#{targetconf_yamlpath})")
      exit(@mes.ec("EXIT_CODE_CANNOT_FIND_TARGETCONFYAMLPATH"))
    end
    obj = Filex::Filex.check_and_load_yamlfile(targetconf_yamlpath, @mes)
    next unless obj
    setup_target_config(category_target_struct, obj)
  end
end

#setup_from_conf(conf_fname, hash, subhs = {}) ⇒ void

This method returns an undefined value.

構成ファイルを(変数展開しつつ)ハッシュに変換する

Parameters:

  • conf_fname (String)

    構成ファイル名

  • hash (Hash)

    ハッシュ(構成ファイルの内容が追加される)

  • subhs (Hash) (defaults to: {})

    第2ハッシュ



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/md2site/env.rb', line 256

def setup_from_conf(conf_fname, hash, subhs={})
  @mes.exc_file_gets(conf_fname) do
    File.open(conf_fname) do |f|
      while (l = f.gets)
        l = l.chomp
        next if /^\s*#/ =~ l
        next if /^\s*$/ =~ l
        if (m = /\s*([^=]+)=([^=]+)\s*$/.match(l))
          hash[m[1]] ||= m[2]
        end
      end
    end
  end

  keys = hash.keys
  keys.each do |key|
    hash[key] = expand_variable(hash[key], hash, subhs)
  end
end

#setup_target_config(category_target_struct, obj) ⇒ void

This method returns an undefined value.

カテゴリ構成ファイルの内容をカテゴリ・ターゲットストラクトに反映する

Parameters:

  • category_target_struct (Struct)

    カテゴリ・ターゲットストラクト

  • obj (Hash)

    カテゴリ構成ファイル(YAML形式)を変換したハッシュ



501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/md2site/env.rb', line 501

def setup_target_config(category_target_struct, obj)
  check_site_tsv_and_category_conf(category_target_struct, obj)

  category_target_struct.subTargets.each do |_k, subtarget|
    subtarget.filedir = @filedir_struct.new(File.join(@root_output_dir, subtarget.htmldir, subtarget.htmlfile).to_s,
                                            File.join(subtarget.materialDir, subtarget.htmlfile).to_s,
                                            File.join(subtarget.materialDir, "0.html").to_s,
                                            File.join(subtarget.materialDir, "2.html").to_s,
                                            File.join(subtarget.dataDir, subtarget.mdfile).to_s,
                                            File.join(subtarget.workDir, subtarget.mdfile).to_s,
                                            File.join(@root_output_dir, subtarget.htmldir, subtarget.mdfile).to_s,
                                            subtarget.dataDir.to_s)
    subtarget_name = subtarget.name
    next unless obj && obj[subtarget_name]

    obj[subtarget_name].each do |line|
      subtarget.templates << make_template_struct(line, subtarget)
    end
  end
end