Skip to content

Commit

Permalink
add inline @<column>{} to refer column
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Apr 12, 2014
1 parent 8c27ba4 commit 7c33848
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/review/book/compilable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ def headline(caption)
def headline_index
@headline_index ||= HeadlineIndex.parse(lines(), self)
end

def column(id)
column_index()[id]
end

def column_index
@column_index ||= ColumnIndex.parse(lines())
end
end
end
end
Expand Down
30 changes: 30 additions & 0 deletions lib/review/book/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,5 +359,35 @@ def number(id)
return ([@chap.number] + @index.fetch(id).number).join(".")
end
end

class ColumnIndex < Index
COLUMN_PATTERN = /\A(=+)\[column\](?:\{(.+?)\})?(.*)/
Item = Struct.new(:id, :number, :caption)

def ColumnIndex.parse(src, *args)
items = []
seq = 1
src.each do |line|
if m = COLUMN_PATTERN.match(line)
level = m[1] ## not use it yet
id = m[2]
caption = m[3].strip
if !id || id == ""
id = caption
end

items.push item_class().new(id, seq, caption)
seq += 1
end
end
new(items)
end

def number(id)
""
end

end

end
end
1 change: 1 addition & 0 deletions lib/review/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def inline_defined?(name)
definline :hd
definline :href
definline :recipe
definline :column

definline :abbr
definline :acronym
Expand Down
11 changes: 11 additions & 0 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,17 @@ def inline_hd_chap(chap, id)
end
end

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

def inline_list(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
Expand Down
12 changes: 12 additions & 0 deletions test/test_book_chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,18 @@ def test_headline_index_nullsection
E
end


def test_column_index
ReVIEW.book.param = {"inencoding" => "utf-8"}
do_test_index(<<E, Book::ColumnIndex, :column_index, :column, :propagate => false)
= dummy1
===[column]{abc} aaaa
= dummy2
===[column] def
== dummy3
E
end

def test_image
do_test_index(<<E, Book::ImageIndex, :image_index, :image)
//image
Expand Down

0 comments on commit 7c33848

Please sign in to comment.