Class: Vivlio::Starter::CLI::TocCommands::SupplementEntryProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/toc.rb

Overview

前書き/後書きのエントリを生成する

前書き(00-preface)や後書き(99-postface)は、通常の章とは異なる扱いをする。

  • 章番号を表示しない(CSS: toc-chapter-no-number)

  • ビルド対象に含まれている場合のみ、目次に追加する

  • 通常の見出し抽出ロジック(HeadingExtractor)は使用せず、h1 のみを抽出

Constant Summary collapse

CSS_CLASS =
'toc-chapter-no-number'

Instance Method Summary collapse

Constructor Details

#initialize(targets:, base_dir:, file_name:) ⇒ SupplementEntryProvider

Returns a new instance of SupplementEntryProvider.



269
270
271
272
273
# File 'lib/vivlio/starter/cli/toc.rb', line 269

def initialize(targets:, base_dir:, file_name:)
  @targets = targets      # ビルド対象の HTML ファイルリスト
  @base_dir = Pathname.new(base_dir)
  @file_name = file_name  # 対象ファイル名(例: '00-preface.html')
end

Instance Method Details

#callObject

指定された補助 HTML から TOC 項目を生成する返り値: TOC エントリの HTML 文字列、または nil(対象外の場合)



277
278
279
280
281
282
283
284
285
# File 'lib/vivlio/starter/cli/toc.rb', line 277

def call
  # targets に含まれていない場合は追加しない(chapters 設定で除外されている場合)
  return unless included_in_targets?
  return unless File.exist?(html_path)

  build_entry(html_path)
rescue StandardError
  nil
end