lib/review/book/base.rb in review-2.1.0 vs lib/review/book/base.rb in review-2.2.0
- old
+ new
@@ -13,10 +13,13 @@
module ReVIEW
module Book
class Base
attr_writer :config
+ attr_writer :parts
+ attr_writer :catalog
+ attr_reader :basedir
def self.load_default
warn 'Book::Base.load_default() is obsoleted. Use Book::Base.load().'
load()
end
@@ -49,10 +52,11 @@
@parts = nil
@chapter_index = nil
@config = ReVIEW::Configure.values
@catalog = nil
@read_part = nil
+ @warn_old_files = {} # XXX for checking CHAPS, PREDEF, POSTDEF
end
def bib_file
config["bib_file"]
end
@@ -97,14 +101,10 @@
def parts
@parts ||= read_parts()
end
- def parts=(parts)
- @parts = parts
- end
-
def parts_in_file
parts.find_all{|part|
part if part.present? and part.file?
}
end
@@ -196,14 +196,10 @@
end
@catalog
end
- def catalog=(catalog)
- @catalog = catalog
- end
-
def read_CHAPS
if catalog
catalog.chaps
else
read_FILE(config["chapter_file"])
@@ -296,14 +292,10 @@
if catalog
mkpart_from_namelist(catalog.postdef.split("\n"))
end
end
- def basedir
- @basedir
- end
-
private
def read_parts
list = parse_chapters
if pre = prefaces
@@ -342,13 +334,13 @@
Part.new(self, nil, [chap])
end
end
end
- chap = read_CHAPS()\
- .strip.lines.map {|line| line.strip }.join("\n").split(/\n{2,}/)\
- .map {|part_chunk|
+ chap = read_CHAPS().
+ strip.lines.map {|line| line.strip }.join("\n").split(/\n{2,}/).
+ map {|part_chunk|
chaps = part_chunk.split.map {|chapid|
Chapter.new(self, (num += 1), chapid, "#{@basedir}/#{chapid}")
}
if part_exist? && read_PART.split("\n").size > part
Part.new(self, (part += 1), chaps, read_PART.split("\n")[part-1])
@@ -394,9 +386,15 @@
Chapter.new(self, idx, name, path)
end
end
def read_FILE(filename)
+ if !@warn_old_files[filename]
+ @warn_old_files[filename] = true
+ if !caller().any?{|item| item =~ %r|/review/test/test_|}
+ warn "!!! #{filename} is obsoleted. please use catalog.yml."
+ end
+ end
res = ""
File.open("#{@basedir}/#{filename}", 'r:BOM|utf-8') do |f|
while line = f.gets
if /\A#/ =~ line
next