Skip to content

Commit

Permalink
add ReVIEW::IndexBuilder
Browse files Browse the repository at this point in the history
make indexes with this builder, instead of `Index.parse()`
  • Loading branch information
takahashim committed Aug 19, 2020
1 parent bfd9346 commit b90cdec
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 8 deletions.
8 changes: 8 additions & 0 deletions lib/review/book/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def update_rubyenv
end
end

def make_indexes
return unless @catalog

parts.each do |part|
part.chapters.each(&:make_indexes)
end
end

def bib_file
config['bib_file']
end
Expand Down
23 changes: 17 additions & 6 deletions lib/review/book/book_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# For details of the GNU LGPL, see the file "COPYING".
#
require 'review/textutils'
require 'review/index_builder'

module ReVIEW
module Book
Expand All @@ -27,16 +28,26 @@ def initialize
end
end

def make_indexes
index_builder = ReVIEW::IndexBuilder.new
compiler = ReVIEW::Compiler.new(index_builder)
compiler.compile(self)
index_builder
end

def generate_indexes
return unless content

@lines = content.lines
@list_index = ListIndex.parse(lines)
@table_index = TableIndex.parse(lines)
@equation_index = EquationIndex.parse(lines)
@footnote_index = FootnoteIndex.parse(lines)
@headline_index = HeadlineIndex.parse(lines, self)
@column_index = ColumnIndex.parse(lines)

@indexes = make_indexes

@list_index = @indexes.list_index
@table_index = @indexes.table_index
@equation_index = @indexes.equation_index
@footnote_index = @indexes.footnote_index
@headline_index = @indexes.headline_index
@column_index = @indexes.column_index
end

def dirname
Expand Down
4 changes: 4 additions & 0 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def initialize
@image_finder = nil
end

def size
@index.size
end

def add_item(item)
if @index[item.id] && self.class != ReVIEW::Book::IconIndex
@logger.warn "warning: duplicate ID: #{item.id} (#{item.inspect})"
Expand Down
2 changes: 1 addition & 1 deletion lib/review/book/part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.mkpart_from_namelist(book, names)
end

def self.mkpart(chaps)
chaps.empty? ? nil : Part.new(self, nil, chaps)
chaps.empty? ? nil : Part.new(chaps[0].book, nil, chaps)
end

# if Part is dummy, `number` is nil.
Expand Down
Loading

0 comments on commit b90cdec

Please sign in to comment.