diff options
Diffstat (limited to 'lib/sisu/v5/xml_docbook5.rb')
-rw-r--r-- | lib/sisu/v5/xml_docbook5.rb | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/lib/sisu/v5/xml_docbook5.rb b/lib/sisu/v5/xml_docbook5.rb index 9e02af39..0dddf264 100644 --- a/lib/sisu/v5/xml_docbook5.rb +++ b/lib/sisu/v5/xml_docbook5.rb @@ -8,7 +8,8 @@ * Author: Ralph Amissah * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013 Ralph Amissah, All Rights Reserved. + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah, + All Rights Reserved. * License: GPL 3 or later: @@ -131,18 +132,20 @@ module SiSU_XML_Docbook_Book def tags # collapsed --> def collapsed - %w[ 0 1 2 3 4 5 6 ] + %w[ 0 1 2 3 4 5 ] end def docbook(lc,chlv='') case lc - when 1 + when 0 'book' + when 1 + lc==chlv ? 'chapter' : 'section' when 2 lc==chlv ? 'chapter' : 'section' when 3 lc==chlv ? 'chapter' : 'section' when 4 - lc==chlv ? 'chapter' : 'section' + 'section' when 5 'section' when 6 @@ -177,16 +180,16 @@ module SiSU_XML_Docbook_Book WOK put(tail) end - def output(o,lev=nil,comment='') - puts lev == 0..6 \ - ? "#{space*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}</#{lev}>#{comment}" - : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}</#{lev}>#{comment}" + def output(o,comment='') + puts o.lc == 0..6 \ + ? "#{space*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}" + : "<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}</#{o.lc}>#{comment}" end def structure_collapsed(data) puts "\ncollapsed structure, heading outline --->\n\n" data.each_with_index do |o,i| if (o.is ==:heading || o.is ==:heading_insert) - output(o,o.lc) + output(o) end end end @@ -208,24 +211,23 @@ module SiSU_XML_Docbook_Book ocn,id='','' end if (o.is ==:heading || o.is ==:heading_insert) - lev=o.lc chlv=(o.lv.to_i == 1) \ ? @chlv=o.lc.to_i : 0 - @splv=lev + @splv=o.lc tag_id=o.tags[0] ? %{ id="#{o.tags[0]}" } : '' if doc_position ==:head - filename_docbook.puts %{#{space*lev}<title#{id}>} + filename_docbook.puts %{#{space*o.lc}<title#{id}>} doc_position=:body_and_tail else - filename_docbook.puts structure_build_tag_close(lev,h) - filename_docbook.puts %{#{space*(lev-1)}<#{tags.docbook(lev,chlv)}#{tag_id}> -#{space*lev}<title#{id}> + filename_docbook.puts structure_build_tag_close(o.lc,h) + filename_docbook.puts %{#{space*(o.lc)}<#{tags.docbook(o.lc,chlv)}#{tag_id}> +#{space*o.lc}<title#{id}> } end filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap - filename_docbook.puts %{#{space*lev}</title>} - h=lev + filename_docbook.puts %{#{space*o.lc}</title>} + h=o.lc elsif (o.of ==:para or o.of ==:block) filename_docbook.puts "#{space*(@splv)}<para#{id}>" filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap @@ -235,36 +237,44 @@ module SiSU_XML_Docbook_Book filename_docbook.puts structure_build_tag_close(0,h) filename_docbook.close end - def structure_build_tag_close(lev,h) + def structure_build_tag_close(lc,h) x=[] case h + when 0 + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 1 - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 2 - x << "#{space*1}</#{tags.docbook(2,@chlv)}>" if (lev <= 2) - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*2}</#{tags.docbook(2,@chlv)}>" if (lc <= 2) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 3 - x << "#{space*2}</#{tags.docbook(3,@chlv)}>" if (lev <= 3) - x << "#{space*1}</#{tags.docbook(2,@chlv)}>" if (lev <= 2) - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*3}</#{tags.docbook(3,@chlv)}>" if (lc <= 3) + x << "#{space*2}</#{tags.docbook(2,@chlv)}>" if (lc <= 2) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 4 - x << "#{space*3}</#{tags.docbook(4,@chlv)}>" if (lev <= 4) - x << "#{space*2}</#{tags.docbook(3,@chlv)}>" if (lev <= 3) - x << "#{space*1}</#{tags.docbook(2,@chlv)}>" if (lev <= 2) - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*4}</#{tags.docbook(4,@chlv)}>" if (lc <= 4) + x << "#{space*3}</#{tags.docbook(3,@chlv)}>" if (lc <= 3) + x << "#{space*2}</#{tags.docbook(2,@chlv)}>" if (lc <= 2) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 5 - x << "#{space*4}</#{tags.docbook(5)}>" if (lev <= 5) - x << "#{space*3}</#{tags.docbook(4,@chlv)}>" if (lev <= 4) - x << "#{space*2}</#{tags.docbook(3,@chlv)}>" if (lev <= 3) - x << "#{space*1}</#{tags.docbook(2,@chlv)}>" if (lev <= 2) - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*5}</#{tags.docbook(5)}>" if (lc <= 5) + x << "#{space*4}</#{tags.docbook(4,@chlv)}>" if (lc <= 4) + x << "#{space*5}</#{tags.docbook(3,@chlv)}>" if (lc <= 3) + x << "#{space*2}</#{tags.docbook(2,@chlv)}>" if (lc <= 2) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) when 6 - x << "#{space*5}</#{tags.docbook(6)}>" if (lev <= 6) - x << "#{space*4}</#{tags.docbook(5)}>" if (lev <= 5) - x << "#{space*3}</#{tags.docbook(4,@chlv)}>" if (lev <= 4) - x << "#{space*2}</#{tags.docbook(3,@chlv)}>" if (lev <= 3) - x << "#{space*1}</#{tags.docbook(2,@chlv)}>" if (lev <= 2) - x << "#{space*0}</#{tags.docbook(1)}>" if (lev <= 1) + x << "#{space*6}</#{tags.docbook(6)}>" if (lc <= 6) + x << "#{space*5}</#{tags.docbook(5)}>" if (lc <= 5) + x << "#{space*4}</#{tags.docbook(4,@chlv)}>" if (lc <= 4) + x << "#{space*3}</#{tags.docbook(3,@chlv)}>" if (lc <= 3) + x << "#{space*2}</#{tags.docbook(2,@chlv)}>" if (lc <= 2) + x << "#{space*1}</#{tags.docbook(1,@chlv)}>" if (lc <= 1) + x << "#{space*0}</#{tags.docbook(0)}>" if (lc <= 0) end x.join("\n") end |