class ReVIEW::Book::Base

Attributes

basedir[R]
catalog[W]
config[W]
parts[W]

Public Class Methods

clear_rubyenv() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 46
def self.clear_rubyenv
  @basedir_seen = {}
end
load(dir = ".") click to toggle source
# File ../../../../../lib/review/book/base.rb, line 27
def self.load(dir = ".")
  update_rubyenv dir
  new(dir)
end
load_default() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 22
def self.load_default
  warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().'
  load()
end
new(basedir) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 50
def initialize(basedir)
  @basedir = basedir
  @parts = nil
  @chapter_index = nil
  @config = ReVIEW::Configure.values
  @catalog = nil
  @read_part = nil
  @warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
end
update_rubyenv(dir) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 34
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.expand_path("#{dir}/review-ext.rb")
    end
  end
  @basedir_seen[dir] = true
end

Public Instance Methods

appendix() click to toggle source
# 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.message}"
    end
  end
end
bib_exist?() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 255
def bib_exist?
  File.exist?("#{@basedir}/#{bib_file}")
end
bib_file() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 60
def bib_file
  config["bib_file"]
end
catalog() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 190
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
chapter(id) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 153
def chapter(id)
  chapter_index()[id]
end
chapter_index() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 141
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() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 129
def chapters
  parts().map {|p| p.chapters }.flatten
end
config() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 181
def config
  @config ||= Configure.values
end
contents() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 120
def contents
  # TODO: includes predef, appendix, postdef
  if parts.present?
    chapters + parts
  else
    chapters
  end
end
each_chapter(&block) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 133
def each_chapter(&block)
  chapters.each(&block)
end
each_chapter_r(&block) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 137
def each_chapter_r(&block)
  chapters.reverse_each(&block)
end
each_part(&block) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 116
def each_part(&block)
  parts.each(&block)
end
ext() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 68
def ext
  config["ext"]
end
htmlversion() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 94
def htmlversion
  if config["htmlversion"].blank?
    nil
  else
    config["htmlversion"].to_i
  end
end
image_dir() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 72
def image_dir
  config["image_dir"]
end
image_types() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 76
def image_types
  config["image_types"]
end
image_types=(types) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 80
def image_types=(types)
  config["image_types"] = types
end
load_config(filename) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 185
def load_config(filename)
  new_conf = YAML.load_file(filename)
  @config.merge!(new_conf)
end
next_chapter(chapter) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 157
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() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 84
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) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 112
def part(n)
  parts.detect {|part| part.number == n }
end
part_exist?() click to toggle source
# 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() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 102
def parts
  @parts ||= read_parts()
end
parts_in_file() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 106
def parts_in_file
  parts.find_all{|part|
    part if part.present? and part.file?
  }
end
postscripts() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 291
def postscripts
  if catalog
    mkpart_from_namelist(catalog.postdef.split("\n"))
  end
end
prefaces() click to toggle source
# 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.message}"
    end
  end
end
prev_chapter(chapter) click to toggle source
# File ../../../../../lib/review/book/base.rb, line 166
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() click to toggle source
# 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_CHAPS() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 225
def read_POSTDEF
  if catalog
    catalog.postdef
  else
    ""
  end
end
read_PREDEF() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 209
def read_PREDEF
  if catalog
    catalog.predef
  else
    read_FILE(config["predef_file"])
  end
end
read_bib() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 251
def read_bib
  File.read("#{@basedir}/#{bib_file}")
end
reject_file() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 64
def reject_file
  config["reject_file"]
end
volume() click to toggle source
# File ../../../../../lib/review/book/base.rb, line 175
def volume
  vol = Volume.sum(chapters.map {|chap| chap.volume })
  vol.page_per_kbyte = page_metric.page_per_kbyte
  vol
end