Class: Ligarb::Config
- Inherits:
-
Object
- Object
- Ligarb::Config
- Defined in:
- lib/ligarb/config.rb
Defined Under Namespace
Classes: Source, StructEntry, TranslationEntry
Constant Summary collapse
- REQUIRED_KEYS =
%w[title chapters].freeze
- INHERITABLE_KEYS =
Keys that can be inherited from a parent (translations hub) config. output_dir is intentionally excluded — it always comes from the config file that was directly passed to ‘ligarb build`.
%w[author language chapter_numbers style repository ai_generated footer bibliography github_review].freeze
Instance Attribute Summary collapse
-
#ai_generated ⇒ Object
readonly
Returns the value of attribute ai_generated.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
-
#bibliography ⇒ Object
readonly
Returns the value of attribute bibliography.
-
#chapter_numbers ⇒ Object
readonly
Returns the value of attribute chapter_numbers.
-
#footer ⇒ Object
readonly
Returns the value of attribute footer.
-
#github_review ⇒ Object
readonly
Returns the value of attribute github_review.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#structure ⇒ Object
readonly
Returns the value of attribute structure.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
-
#all_file_paths ⇒ Object
Returns all file paths including part title pages.
- #appendix_label ⇒ Object
- #bibliography_path ⇒ Object
-
#chapter_paths ⇒ Object
Returns a flat list of all chapter file paths (excluding part title pages).
- #effective_footer ⇒ Object
-
#github_review_enabled? ⇒ Boolean
Whether the reader’s “Report as issue” feedback UI is requested in book.yml.
- #github_review_issue_template ⇒ Object
- #github_review_labels ⇒ Object
-
#initialize(path, parent_data: nil) ⇒ Config
constructor
A new instance of Config.
- #output_path ⇒ Object
- #style_path ⇒ Object
- #translations_hub? ⇒ Boolean
Constructor Details
#initialize(path, parent_data: nil) ⇒ Config
Returns a new instance of Config.
31 32 33 34 35 36 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 |
# File 'lib/ligarb/config.rb', line 31 def initialize(path, parent_data: nil) @base_dir = File.dirname(File.(path)) data = YAML.safe_load_file(path) # If this is a translations hub (has translations but no chapters), skip normal validation if data.is_a?(Hash) && data.key?("translations") && !data.key?("chapters") @translations_hub = true @translations_data = data load_translations_hub(data) return end # Load inherit file if specified (for standalone builds of child configs) if !parent_data && data.is_a?(Hash) && data.key?("inherit") inherit_path = File.(data["inherit"], @base_dir) if File.exist?(inherit_path) parent_data = YAML.safe_load_file(inherit_path) else abort "Error: inherit config not found: #{inherit_path}" end end # Merge parent (inheritable) keys as defaults if parent_data INHERITABLE_KEYS.each do |key| data[key] = parent_data[key] if parent_data.key?(key) && !data.key?(key) end end validate!(data) @title = data["title"] @author = data.fetch("author", "") @language = data.fetch("language", "en") @output_dir = data.fetch("output_dir", "build") @chapter_numbers = data.fetch("chapter_numbers", true) @style = data.fetch("style", nil) @repository = data.fetch("repository", nil) @ai_generated = data.fetch("ai_generated", false) @footer = data.fetch("footer", nil) @bibliography = data.fetch("bibliography", nil) @github_review = data.fetch("github_review", nil) @sources = parse_sources(data.fetch("sources", [])) @structure = parse_structure(data["chapters"]) @translations = [] load_translations(data, path) if data.key?("translations") end |
Instance Attribute Details
#ai_generated ⇒ Object (readonly)
Returns the value of attribute ai_generated.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def ai_generated @ai_generated end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def @author end |
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def base_dir @base_dir end |
#bibliography ⇒ Object (readonly)
Returns the value of attribute bibliography.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def bibliography @bibliography end |
#chapter_numbers ⇒ Object (readonly)
Returns the value of attribute chapter_numbers.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def chapter_numbers @chapter_numbers end |
#footer ⇒ Object (readonly)
Returns the value of attribute footer.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def @footer end |
#github_review ⇒ Object (readonly)
Returns the value of attribute github_review.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def github_review @github_review end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def language @language end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def output_dir @output_dir end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def repository @repository end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def sources @sources end |
#structure ⇒ Object (readonly)
Returns the value of attribute structure.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def structure @structure end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def style @style end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def title @title end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
26 27 28 |
# File 'lib/ligarb/config.rb', line 26 def translations @translations end |
Instance Method Details
#all_file_paths ⇒ Object
Returns all file paths including part title pages
134 135 136 |
# File 'lib/ligarb/config.rb', line 134 def all_file_paths collect_all_paths(@structure) end |
#appendix_label ⇒ Object
96 97 98 |
# File 'lib/ligarb/config.rb', line 96 def appendix_label @language == "ja" ? "付録" : "Appendix" end |
#bibliography_path ⇒ Object
92 93 94 |
# File 'lib/ligarb/config.rb', line 92 def bibliography_path @bibliography ? File.join(@base_dir, @bibliography) : nil end |
#chapter_paths ⇒ Object
Returns a flat list of all chapter file paths (excluding part title pages)
129 130 131 |
# File 'lib/ligarb/config.rb', line 129 def chapter_paths collect_chapter_paths(@structure) end |
#effective_footer ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ligarb/config.rb', line 117 def return @footer if @footer return nil unless @ai_generated if @language == "ja" "この章の内容は AI によって生成されました。正確性は保証されません。" else "This chapter was generated by AI. Accuracy is not guaranteed." end end |
#github_review_enabled? ⇒ Boolean
Whether the reader’s “Report as issue” feedback UI is requested in book.yml. This reflects intent only; actual injection also requires ‘repository` (the issues/new base) — the builder warns and skips when it is missing.
103 104 105 |
# File 'lib/ligarb/config.rb', line 103 def github_review_enabled? @github_review.is_a?(Hash) && @github_review.fetch("enabled", false) == true end |
#github_review_issue_template ⇒ Object
107 108 109 110 |
# File 'lib/ligarb/config.rb', line 107 def github_review_issue_template tmpl = @github_review.is_a?(Hash) ? @github_review["issue_template"] : nil tmpl && !tmpl.to_s.empty? ? tmpl.to_s : "book-feedback.yml" end |
#github_review_labels ⇒ Object
112 113 114 115 |
# File 'lib/ligarb/config.rb', line 112 def github_review_labels labels = @github_review.is_a?(Hash) ? @github_review["labels"] : nil Array(labels || ["feedback"]).map(&:to_s) end |
#output_path ⇒ Object
84 85 86 |
# File 'lib/ligarb/config.rb', line 84 def output_path File.join(@base_dir, @output_dir) end |
#style_path ⇒ Object
88 89 90 |
# File 'lib/ligarb/config.rb', line 88 def style_path @style ? File.join(@base_dir, @style) : nil end |
#translations_hub? ⇒ Boolean
80 81 82 |
# File 'lib/ligarb/config.rb', line 80 def translations_hub? @translations_hub == true end |