Skip to content

Commit

Permalink
Merge pull request #476 from kdmsnr/ref-column-in-anoher-chapter
Browse files Browse the repository at this point in the history
Refer to column in another chapter
  • Loading branch information
kdmsnr committed Jan 3, 2016
2 parents 5852d90 + 740be6f commit a13826a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
24 changes: 20 additions & 4 deletions lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,33 @@ 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]
return inline_hd_chap(chapter, m[2]) if chapter
return inline_hd_chap(@chapter, id)
if chapter
inline_hd_chap(chapter, m[2])
else
inline_hd_chap(@chapter, id)
end
rescue KeyError
error "unknown hd: #{id}"
nofunc_text("[UnknownHeader:#{id}]")
end

def inline_column(id)
@chapter.column(id).caption
rescue
m = /\A([^|]+)\|(.+)/.match(id)
chapter = @book.chapters.detect{|chap| chap.id == m[1]} if m && m[1]
if chapter
inline_column_chap(chapter, m[2])
else
inline_column_chap(@chapter, id)
end
rescue KeyError
error "unknown column: #{id}"
nofunc_text("[UnknownColumn:#{id}]")
end

def inline_column_chap(chapter, id)
chapter.column(id).caption
end

def raw(str)
if matched = str.match(/\|(.*?)\|(.*)/)
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
Expand Down
9 changes: 3 additions & 6 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,12 @@ def column_label(id)
end
private :column_label

def inline_column(id)
def inline_column_chap(chapter, id)
if @book.config["chapterlink"]
%Q(<a href="\##{column_label(id)}" class="columnref">#{I18n.t("column", escape_html(@chapter.column(id).caption))}</a>)
%Q(<a href="\##{column_label(id)}" class="columnref">#{I18n.t("column", escape_html(chapter.column(id).caption))}</a>)
else
I18n.t("column", escape_html(@chapter.column(id).caption))
I18n.t("column", escape_html(chapter.column(id).caption))
end
rescue KeyError
error "unknown column: #{id}"
nofunc_text("[UnknownColumn:#{id}]")
end

def inline_list(id)
Expand Down
9 changes: 3 additions & 6 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,12 @@ def column_label(id)
end
private :column_label

def inline_column(id)
def inline_column_chap(chapter, id)
if @book.config["chapterlink"]
%Q(<link href="#{column_label(id)}">#{escape_html(@chapter.column(id).caption)}</link>)
%Q(<link href="#{column_label(id)}">#{escape_html(chapter.column(id).caption)}</link>)
else
escape_html(@chapter.column(id).caption)
escape_html(chapter.column(id).caption)
end
rescue KeyError
error "unknown column: #{id}"
nofunc_text("[UnknownColumn:#{id}]")
end

def inline_list(id)
Expand Down
4 changes: 2 additions & 2 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ def inline_hd_chap(chap, id)
end
end

def inline_column(id)
macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
def inline_column_chap(chapter, id)
macro('reviewcolumnref', "#{chapter.column(id).caption}", column_label(id))
end

def inline_raw(str)
Expand Down
15 changes: 11 additions & 4 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# encoding: utf-8

require 'test_helper'
require 'review/compiler'
require 'review/book'
require 'review/htmlbuilder'
require 'review/i18n'
require 'review'

class HTMLBuidlerTest < Test::Unit::TestCase
include ReVIEW
Expand Down Expand Up @@ -792,6 +789,16 @@ def test_column_ref
assert_equal expected, column_helper(review)
end

def test_column_in_aother_chapter_ref
def @chapter.column_index
items = [Book::ColumnIndex::Item.new("chap1|column", 1, "column_cap")]
Book::ColumnIndex.new(items)
end

actual = compile_inline("test @<column>{chap1|column} test2")
expected = "test コラム「column_cap」 test2"
assert_equal expected, actual
end

def test_ul
src =<<-EOS
Expand Down

0 comments on commit a13826a

Please sign in to comment.