From 7c3384897795d94a05ab42b9777427c1ba5dc4d1 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 12 Apr 2014 17:19:59 +0900 Subject: [PATCH] add inline @{} to refer column --- lib/review/book/compilable.rb | 8 ++++++++ lib/review/book/index.rb | 30 ++++++++++++++++++++++++++++++ lib/review/compiler.rb | 1 + lib/review/htmlbuilder.rb | 11 +++++++++++ test/test_book_chapter.rb | 12 ++++++++++++ 5 files changed, 62 insertions(+) diff --git a/lib/review/book/compilable.rb b/lib/review/book/compilable.rb index a2070b9f6..d09c3d683 100644 --- a/lib/review/book/compilable.rb +++ b/lib/review/book/compilable.rb @@ -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 diff --git a/lib/review/book/index.rb b/lib/review/book/index.rb index f6295fb19..9cb7af85a 100644 --- a/lib/review/book/index.rb +++ b/lib/review/book/index.rb @@ -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 diff --git a/lib/review/compiler.rb b/lib/review/compiler.rb index c6315e930..3b5ce016a 100644 --- a/lib/review/compiler.rb +++ b/lib/review/compiler.rb @@ -187,6 +187,7 @@ def inline_defined?(name) definline :hd definline :href definline :recipe + definline :column definline :abbr definline :acronym diff --git a/lib/review/htmlbuilder.rb b/lib/review/htmlbuilder.rb index 9c08a7d19..0e6a7674f 100644 --- a/lib/review/htmlbuilder.rb +++ b/lib/review/htmlbuilder.rb @@ -917,6 +917,17 @@ def inline_hd_chap(chap, id) end end + def inline_column(id) + if ReVIEW.book.param["chapterlink"] + %Q(#{@chapter.column(id).caption}) + 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? diff --git a/test/test_book_chapter.rb b/test/test_book_chapter.rb index c6206634f..174d159ff 100644 --- a/test/test_book_chapter.rb +++ b/test/test_book_chapter.rb @@ -354,6 +354,18 @@ def test_headline_index_nullsection E end + + def test_column_index + ReVIEW.book.param = {"inencoding" => "utf-8"} + do_test_index(< false) += dummy1 +===[column]{abc} aaaa += dummy2 +===[column] def +== dummy3 +E + end + def test_image do_test_index(<