Class: Vivlio::Starter::CLI::IndexCommands::UnifiedPageBuilder
- Inherits:
-
Object
- Object
- Vivlio::Starter::CLI::IndexCommands::UnifiedPageBuilder
- Defined in:
- lib/vivlio/starter/cli/index/unified_page_builder.rb
Constant Summary collapse
- KANA_ROWS =
五十音の行判定用マッピング(ひらがな・カタカナ両対応)
{ 'あ' => /^[あ-おぁ-ぉア-オァ-ォ]/, 'か' => /^[か-ごゕゖカ-ゴヵヶ]/, 'さ' => /^[さ-ぞサ-ゾ]/, 'た' => /^[た-どタ-ド]/, 'な' => /^[な-のナ-ノ]/, 'は' => /^[は-ぽハ-ポ]/, 'ま' => /^[ま-もマ-モ]/, 'や' => /^[や-よゃゅょヤ-ヨャュョ]/, 'ら' => /^[ら-ろラ-ロ]/, 'わ' => /^[わ-んゎワ-ンヮ]/ }.freeze
- SYMBOL_ROW_LABEL =
'記号'- NUMBER_ROW_LABEL =
'数字'- DIGIT_REGEX =
/\A[0-90-9]\z/- ALPHA_ROWS =
('A'..'Z').to_h do |letter| [letter, /^[#{letter.downcase}#{letter}]/] end.freeze
- INDEX_MATCH_FILE =
'_index_matches.yml'- INDEX_OUTPUT_FILE =
'_indexpage.html'- GLOSSARY_OUTPUT_FILE =
'_glossarypage.html'
Instance Attribute Summary collapse
-
#hierarchical_index ⇒ Object
readonly
Returns the value of attribute hierarchical_index.
-
#index_data ⇒ Object
readonly
Returns the value of attribute index_data.
Instance Method Summary collapse
-
#build_glossary!(terms) ⇒ String?
用語集ページを生成.
-
#build_index! ⇒ String?
索引ページを生成.
-
#cleanup_stale_file!(file) ⇒ Object
以前のビルドで残ったファイルを削除.
-
#initialize(glossary_config: {}) ⇒ UnifiedPageBuilder
constructor
A new instance of UnifiedPageBuilder.
Constructor Details
#initialize(glossary_config: {}) ⇒ UnifiedPageBuilder
Returns a new instance of UnifiedPageBuilder.
59 60 61 62 63 |
# File 'lib/vivlio/starter/cli/index/unified_page_builder.rb', line 59 def initialize(glossary_config: {}) @index_data = {} @hierarchical_index = HierarchicalIndex.new @glossary_config = glossary_config end |
Instance Attribute Details
#hierarchical_index ⇒ Object (readonly)
Returns the value of attribute hierarchical_index.
57 58 59 |
# File 'lib/vivlio/starter/cli/index/unified_page_builder.rb', line 57 def hierarchical_index @hierarchical_index end |
#index_data ⇒ Object (readonly)
Returns the value of attribute index_data.
57 58 59 |
# File 'lib/vivlio/starter/cli/index/unified_page_builder.rb', line 57 def index_data @index_data end |
Instance Method Details
#build_glossary!(terms) ⇒ String?
用語集ページを生成
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vivlio/starter/cli/index/unified_page_builder.rb', line 94 def build_glossary!(terms) if terms.nil? || terms.empty? Common.log_info('用語集に登録された用語がありません') cleanup_stale_file!(GLOSSARY_OUTPUT_FILE) return nil end sorted_terms = terms.sort_by { it['yomi'] || it['term'] } html = generate_glossary_html(sorted_terms) File.write(GLOSSARY_OUTPUT_FILE, html, encoding: 'utf-8') Common.log_success("用語集ページを生成しました: #{GLOSSARY_OUTPUT_FILE}") GLOSSARY_OUTPUT_FILE end |
#build_index! ⇒ String?
索引ページを生成
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vivlio/starter/cli/index/unified_page_builder.rb', line 69 def build_index! unless File.exist?(INDEX_MATCH_FILE) Common.log_warn("索引データが見つかりません: #{INDEX_MATCH_FILE}") return nil end load_index_data! if @index_data.empty? Common.log_info('索引に登録された用語がありません') cleanup_stale_file!(INDEX_OUTPUT_FILE) return nil end html = generate_index_html File.write(INDEX_OUTPUT_FILE, html, encoding: 'utf-8') Common.log_success("索引ページを生成しました: #{INDEX_OUTPUT_FILE}") INDEX_OUTPUT_FILE end |