Module: VivlioStarter::CLI::Build::VivliostyleConfigWriter
- Defined in:
- lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb
Overview
用途別 entries / vivliostyle config の生成モジュール
Class Method Summary collapse
-
.config_content(entries_basename:, output:) ⇒ Object
config 全文を組み立てる。メタデータの解決(resolve_title/author/language・ EpubBuilder.resolve_page_size)は EPUB config(P3-4 §2.6 で EpubBuilder.generate_epub_config! が本モジュールのリゾルバを呼ぶ)と共通。.
-
.resolve_author ⇒ Object
vivliostyle 11 の config スキーマは author / language に 1 文字以上を 要求するため、未設定はプレースホルダへ寄せる(EPUB 経路と同一規則)。.
- .resolve_language ⇒ Object
-
.resolve_title ⇒ Object
main_title + subtitle 合成 → プレースホルダ。.
-
.write!(name:, entry_htmls:, output:, dir: Common::BUILD_PDF_DIR) ⇒ String
entries と config をペアで生成する。.
-
.write_config_only!(name:, entries_name:, output:, dir: Common::BUILD_PDF_DIR) ⇒ String
既存の entries.<entries_name>.js を共用し、config だけを生成する (入稿用: 本文 entries を共用して出力ファイル名だけ差し替える・P4 §3.2)。.
-
.write_entries!(path, entry_htmls) ⇒ Object
entries ファイルを書き出す(EntriesCommands の ESM 形式と同一)。 path は cwd 相対のまま './' を前置する(E1: entry は cwd 基準で解決される)。.
Class Method Details
.config_content(entries_basename:, output:) ⇒ Object
config 全文を組み立てる。メタデータの解決(resolve_title/author/language・ EpubBuilder.resolve_page_size)は EPUB config(P3-4 §2.6 で EpubBuilder.generate_epub_config! が本モジュールのリゾルバを呼ぶ)と共通。
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 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 90 def config_content(entries_basename:, output:) # JS 単一引用符文字列向けエスケープ。ブロック形で返すことで gsub の置換文字列 # 内バックリファレンス(\' = 後方一致)解釈を避け、\ と ' を確実に \ で退避する。 esc = ->(s) { s.to_s.gsub(/[\\']/) { |c| "\\#{c}" } } <<~JS import entries from './#{entries_basename}'; // @ts-check // ビルドパイプライン専用設定ファイル(自動生成・編集不要) /** @type {import('@vivliostyle/cli').VivliostyleConfigSchema} */ const vivliostyleConfig = { title: '#{esc.call(resolve_title)}', author: '#{esc.call()}', language: '#{esc.call(resolve_language)}', size: '#{esc.call(EpubBuilder.resolve_page_size(Common::CONFIG))}', readingProgression: 'ltr', workspaceDir: '#{Common::BUILD_VIVLIOSTYLE_PDF_DIR}', entry: entries, output: [ './#{output}' ] }; export default vivliostyleConfig; JS end |
.resolve_author ⇒ Object
vivliostyle 11 の config スキーマは author / language に 1 文字以上を 要求するため、未設定はプレースホルダへ寄せる(EPUB 経路と同一規則)。
127 128 129 130 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 127 def = Common::CONFIG.book..to_s.strip .empty? ? '著者名' : end |
.resolve_language ⇒ Object
132 133 134 135 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 132 def resolve_language language = Common::CONFIG.book.language.to_s.strip language.empty? ? 'ja' : language end |
.resolve_title ⇒ Object
main_title + subtitle 合成 → プレースホルダ。
119 120 121 122 123 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 119 def resolve_title book = Common::CONFIG.book combined = [book.main_title, book.subtitle].compact.map { it.to_s.strip }.reject(&:empty?).join(' ') combined.empty? ? '書籍タイトル' : combined end |
.write!(name:, entry_htmls:, output:, dir: Common::BUILD_PDF_DIR) ⇒ String
entries と config をペアで生成する。
51 52 53 54 55 56 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 51 def write!(name:, entry_htmls:, output:, dir: Common::BUILD_PDF_DIR) FileUtils.mkdir_p(dir) entries_file = File.join(dir, "entries.#{name}.js") write_entries!(entries_file, entry_htmls) write_config_only!(name:, entries_name: name, output:, dir:) end |
.write_config_only!(name:, entries_name:, output:, dir: Common::BUILD_PDF_DIR) ⇒ String
既存の entries.<entries_name>.js を共用し、config だけを生成する (入稿用: 本文 entries を共用して出力ファイル名だけ差し替える・P4 §3.2)。
61 62 63 64 65 66 67 68 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 61 def write_config_only!(name:, entries_name:, output:, dir: Common::BUILD_PDF_DIR) FileUtils.mkdir_p(dir) config_file = File.join(dir, "vivliostyle.config.#{name}.js") File.write(config_file, config_content(entries_basename: "entries.#{entries_name}.js", output:), encoding: 'utf-8') Common.log_info("[config-writer] #{config_file} を生成しました") config_file end |
.write_entries!(path, entry_htmls) ⇒ Object
entries ファイルを書き出す(EntriesCommands の ESM 形式と同一)。 path は cwd 相対のまま './' を前置する(E1: entry は cwd 基準で解決される)。
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vivlio_starter/cli/build/vivliostyle_config_writer.rb', line 72 def write_entries!(path, entry_htmls) entries = entry_htmls.map { EntriesCommands.build_entry(it) } File.open(path, 'w') do |f| f.puts 'export default [' entries.each_with_index do |entry, i| f.puts ' {' f.puts %( "path": "#{entry[:path]}",) f.puts %( "title": "#{entry[:title]}") f.puts " }#{',' if i < entries.length - 1}" end f.puts ']' end path end |