Class: ReVIEW::Book::Base
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #appendix ⇒ Object
- #basedir ⇒ Object
- #bib_exist? ⇒ Boolean
- #bib_file ⇒ Object
- #catalog ⇒ Object
- #catalog=(catalog) ⇒ Object
- #chapter(id) ⇒ Object
- #chapter_index ⇒ Object
- #chapters ⇒ Object
- #contents ⇒ Object
- #each_chapter(&block) ⇒ Object
- #each_chapter_r(&block) ⇒ Object
- #each_part(&block) ⇒ Object
- #ext ⇒ Object
- #htmlversion ⇒ Object
- #image_dir ⇒ Object
- #image_types ⇒ Object
- #image_types=(types) ⇒ Object
-
#initialize(basedir) ⇒ Base
constructor
A new instance of Base.
- #load_config(filename) ⇒ Object
- #next_chapter(chapter) ⇒ Object
- #page_metric ⇒ Object
- #part(n) ⇒ Object
- #part_exist? ⇒ Boolean
- #parts ⇒ Object
- #parts=(parts) ⇒ Object
- #parts_in_file ⇒ Object
- #postscripts ⇒ Object
- #prefaces ⇒ Object
- #prev_chapter(chapter) ⇒ Object
- #read_APPENDIX ⇒ Object
- #read_bib ⇒ Object
- #read_CHAPS ⇒ Object
- #read_PART ⇒ Object
- #read_POSTDEF ⇒ Object
- #read_PREDEF ⇒ Object
- #reject_file ⇒ Object
- #volume ⇒ Object
Constructor Details
Instance Attribute Details
Class Method Details
.load(dir = ".") ⇒ Object
24 25 26 27 |
# File 'lib/review/book/base.rb', line 24 def self.load(dir = ".") update_rubyenv dir new(dir) end |
.load_default ⇒ Object
19 20 21 22 |
# File 'lib/review/book/base.rb', line 19 def self.load_default warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().' load() end |
.update_rubyenv(dir) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/review/book/base.rb', line 31 def self.update_rubyenv(dir) return if @basedir_seen.key?(dir) if File.file?("#{dir}/review-ext.rb") if ENV["REVIEW_SAFE_MODE"].to_i & 2 > 0 warn "review-ext.rb is prohibited in safe mode. ignored." else Kernel.load File.("#{dir}/review-ext.rb") end end @basedir_seen[dir] = true end |
Instance Method Details
#appendix ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/review/book/base.rb', line 273 def appendix if catalog names = catalog.appendix.split("\n") chaps = names.each_with_index.map {|n, idx| mkchap_ifexist(n, idx) }.compact return mkpart(chaps) end if File.file?("#{@basedir}/#{config["postdef_file"]}") begin return mkpart_from_namelistfile("#{@basedir}/#{config["postdef_file"]}") rescue FileNotFound => err raise FileNotFound, "postscript #{err.}" end end end |
#basedir ⇒ Object
297 298 299 |
# File 'lib/review/book/base.rb', line 297 def basedir @basedir end |
#bib_exist? ⇒ Boolean
255 256 257 |
# File 'lib/review/book/base.rb', line 255 def bib_exist? File.exist?("#{@basedir}/#{bib_file}") end |
#bib_file ⇒ Object
52 53 54 |
# File 'lib/review/book/base.rb', line 52 def bib_file config["bib_file"] end |
#catalog ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/review/book/base.rb', line 186 def catalog return @catalog if @catalog.present? catalogfile_path = "#{basedir}/#{config["catalogfile"]}" if File.file? catalogfile_path @catalog = File.open(catalogfile_path){|f| Catalog.new(f) } end @catalog end |
#catalog=(catalog) ⇒ Object
197 198 199 |
# File 'lib/review/book/base.rb', line 197 def catalog=(catalog) @catalog = catalog end |
#chapter(id) ⇒ Object
149 150 151 |
# File 'lib/review/book/base.rb', line 149 def chapter(id) chapter_index()[id] end |
#chapter_index ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/review/book/base.rb', line 137 def chapter_index return @chapter_index if @chapter_index contents = chapters() parts().each do |prt| if prt.id.present? contents << prt end end @chapter_index = ChapterIndex.new(contents) end |
#chapters ⇒ Object
125 126 127 |
# File 'lib/review/book/base.rb', line 125 def chapters parts().map {|p| p.chapters }.flatten end |
#contents ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/review/book/base.rb', line 116 def contents # TODO: includes predef, appendix, postdef if parts.present? chapters + parts else chapters end end |
#each_chapter(&block) ⇒ Object
129 130 131 |
# File 'lib/review/book/base.rb', line 129 def each_chapter(&block) chapters.each(&block) end |
#each_chapter_r(&block) ⇒ Object
133 134 135 |
# File 'lib/review/book/base.rb', line 133 def each_chapter_r(&block) chapters.reverse_each(&block) end |
#each_part(&block) ⇒ Object
112 113 114 |
# File 'lib/review/book/base.rb', line 112 def each_part(&block) parts.each(&block) end |
#ext ⇒ Object
60 61 62 |
# File 'lib/review/book/base.rb', line 60 def ext config["ext"] end |
#htmlversion ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/review/book/base.rb', line 86 def htmlversion if config["htmlversion"].blank? nil else config["htmlversion"].to_i end end |
#image_dir ⇒ Object
64 65 66 |
# File 'lib/review/book/base.rb', line 64 def image_dir config["image_dir"] end |
#image_types ⇒ Object
68 69 70 |
# File 'lib/review/book/base.rb', line 68 def image_types config["image_types"] end |
#image_types=(types) ⇒ Object
72 73 74 |
# File 'lib/review/book/base.rb', line 72 def image_types=(types) config["image_types"] = types end |
#load_config(filename) ⇒ Object
181 182 183 184 |
# File 'lib/review/book/base.rb', line 181 def load_config(filename) new_conf = YAML.load_file(filename) @config.merge!(new_conf) end |
#next_chapter(chapter) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/review/book/base.rb', line 153 def next_chapter(chapter) finded = false each_chapter do |c| return c if finded finded = true if c == chapter end nil # not found end |
#page_metric ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/review/book/base.rb', line 76 def page_metric if config["page_metric"].respond_to?(:downcase) && config["page_metric"].upcase =~ /^[A-Z0-9_]+$/ ReVIEW::Book::PageMetric.const_get(config["page_metric"].upcase) elsif config["page_metric"].kind_of?(Array) && config["page_metric"].size == 5 ReVIEW::Book::PageMetric.new(*config["page_metric"]) else config["page_metric"] end end |
#part(n) ⇒ Object
108 109 110 |
# File 'lib/review/book/base.rb', line 108 def part(n) parts.detect {|part| part.number == n } end |
#part_exist? ⇒ Boolean
243 244 245 246 247 248 249 |
# File 'lib/review/book/base.rb', line 243 def part_exist? if catalog catalog.parts.present? else File.exist?("#{@basedir}/#{config["part_file"]}") end end |
#parts ⇒ Object
94 95 96 |
# File 'lib/review/book/base.rb', line 94 def parts @parts ||= read_parts() end |
#parts=(parts) ⇒ Object
98 99 100 |
# File 'lib/review/book/base.rb', line 98 def parts=(parts) @parts = parts end |
#parts_in_file ⇒ Object
102 103 104 105 106 |
# File 'lib/review/book/base.rb', line 102 def parts_in_file parts.find_all{|part| part if part.present? and part.file? } end |
#postscripts ⇒ Object
291 292 293 294 295 |
# File 'lib/review/book/base.rb', line 291 def postscripts if catalog mkpart_from_namelist(catalog.postdef.split("\n")) end end |
#prefaces ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/review/book/base.rb', line 259 def prefaces if catalog return mkpart_from_namelist(catalog.predef.split("\n")) end if File.file?("#{@basedir}/#{config["predef_file"]}") begin return mkpart_from_namelistfile("#{@basedir}/#{config["predef_file"]}") rescue FileNotFound => err raise FileNotFound, "preface #{err.}" end end end |
#prev_chapter(chapter) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/review/book/base.rb', line 162 def prev_chapter(chapter) finded = false each_chapter_r do |c| return c if finded finded = true if c == chapter end nil # not found end |
#read_APPENDIX ⇒ Object
217 218 219 220 221 222 223 |
# File 'lib/review/book/base.rb', line 217 def read_APPENDIX if catalog catalog.appendix else read_FILE(config["postdef_file"]) # for backward compatibility end end |
#read_bib ⇒ Object
251 252 253 |
# File 'lib/review/book/base.rb', line 251 def read_bib File.read("#{@basedir}/#{bib_file}") end |
#read_CHAPS ⇒ Object
201 202 203 204 205 206 207 |
# File 'lib/review/book/base.rb', line 201 def read_CHAPS if catalog catalog.chaps else read_FILE(config["chapter_file"]) end end |
#read_PART ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/review/book/base.rb', line 233 def read_PART return @read_part if @read_part if catalog @read_part = catalog.parts else @read_part = File.read("#{@basedir}/#{config["part_file"]}") end end |
#read_POSTDEF ⇒ Object
225 226 227 228 229 230 231 |
# File 'lib/review/book/base.rb', line 225 def read_POSTDEF if catalog catalog.postdef else "" end end |
#read_PREDEF ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/review/book/base.rb', line 209 def read_PREDEF if catalog catalog.predef else read_FILE(config["predef_file"]) end end |
#reject_file ⇒ Object
56 57 58 |
# File 'lib/review/book/base.rb', line 56 def reject_file config["reject_file"] end |