Skip to content

Commit

Permalink
Merge pull request #490 from kdmsnr/refer-to-parts
Browse files Browse the repository at this point in the history
Reference to parts from `img` and `hd`
  • Loading branch information
takahashim committed Mar 4, 2016
2 parents 22436df + 227043d commit aaaa19c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/review/book/base.rb
Expand Up @@ -110,6 +110,15 @@ def each_part(&block)
parts.each(&block)
end

def contents
# TODO: includes predef, appendix, postdef
if parts.present?
chapters + parts
else
chapters
end
end

def chapters
parts().map {|p| p.chapters }.flatten
end
Expand Down
6 changes: 4 additions & 2 deletions lib/review/builder.rb
Expand Up @@ -278,7 +278,9 @@ def bibpaper(lines, id, caption)

def inline_hd(id)
m = /\A([^|]+)\|(.+)/.match(id)
chapter = @book.chapters.detect{|chap| chap.id == m[1]} if m && m[1]
if m && m[1]
chapter = @book.contents.detect{|chap| chap.id == m[1]}
end
if chapter
inline_hd_chap(chapter, m[2])
else
Expand Down Expand Up @@ -364,7 +366,7 @@ def get_chap(chapter = @chapter)
def extract_chapter_id(chap_ref)
m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
if m
return [@book.chapters.detect{|chap| chap.id == m[1]}, m[2]]
return [@book.contents.detect{|chap| chap.id == m[1]}, m[2]]
else
return [@chapter, chap_ref]
end
Expand Down

0 comments on commit aaaa19c

Please sign in to comment.