From c7f7a26587c9ae9e569eb46b4d90f93ff63984d6 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:28:11 -0500 Subject: v5: xml, docbook --- data/doc/sisu/CHANGELOG_v5 | 2 + lib/sisu/v5/constants.rb | 3 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 14 +++ lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 99 ++++++++++++++++ lib/sisu/v5/urls.rb | 8 ++ lib/sisu/v5/xml_docbook5.rb | 271 ++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/xml_shared.rb | 5 +- 9 files changed, 410 insertions(+), 2 deletions(-) create mode 100644 lib/sisu/v5/xml_docbook5.rb diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5 index e91e2cc3..742a6e70 100644 --- a/data/doc/sisu/CHANGELOG_v5 +++ b/data/doc/sisu/CHANGELOG_v5 @@ -58,6 +58,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.1.0.orig.tar.xz * asciidoc * markdown * rst + * xml + * docbook, book * sisu.gemspec diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 1b97b67f..1f96f0aa 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -76,6 +76,9 @@ Sfx={ xml_scaffold: '.scaffold.xml', xml_scaffold_structure_sisu: '.scaffold.sisu.xml', xml_scaffold_structure_collapse: '.scaffold.collapse.xml', + xml_docbook: '.docbook.xml', + xml_docbook_article: '.article.docbook.xml', + xml_docbook_book: '.book.docbook.xml', epub: '.epub', epub_xhtml: '.xhtml', odt: '.odt', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 755a13dd..08147d96 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -355,6 +355,10 @@ module SiSU require_relative 'xml_scaffold_structure_collapsed' # xml_scaffold_structure_collapsed.rb SiSU_XML_Scaffold_Structure_Collapse::Source.new(@opt).read end + if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook + require_relative 'xml_docbook5' # xml_docbook5.rb + SiSU_XML_Docbook_Book::Source.new(@opt).read + end if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type require_relative 'xml_sax' # xml_sax.rb SiSU_XML_SAX::Source.new(@opt).read @@ -668,6 +672,7 @@ module SiSU || @opt.act[:xml_dom][:set]==:on \ || @opt.act[:xml_scaffold_structure_sisu][:set]==:on \ || @opt.act[:xml_scaffold_structure_collapse][:set]==:on \ + || @opt.act[:xml_docbook_book][:set]==:on \ || @opt.act[:pdf][:set]==:on \ || @opt.act[:pdf_p][:set]==:on \ || @opt.act[:pdf_l][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index 61da6080..42755151 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -396,6 +396,20 @@ module SiSU_Manifest id,file='XML DOM',@f.base_filename.xml_dom summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.xml_docbook_article.dir)==true + pth=@f.output_path.xml_docbook_article.dir + rel=@f.output_path.xml_docbook_article.rel_sm + url=@f.output_path.xml_docbook_article.url + id,file='XML Docbook Book',@f.base_filename.xml_docbook_article + summarize(id,file,pth,rel,url) + end + if FileTest.file?(@f.place_file.xml_docbook_book.dir)==true + pth=@f.output_path.xml_docbook_book.dir + rel=@f.output_path.xml_docbook_book.rel_sm + url=@f.output_path.xml_docbook_book.url + id,file='XML Docbook Book',@f.base_filename.xml_docbook_book + summarize(id,file,pth,rel,url) + end if FileTest.file?(@f.place_file.xml_scaffold_structure_sisu.dir)==true pth=@f.output_path.xml_scaffold_structure_sisu.dir rel=@f.output_path.xml_scaffold_structure_sisu.rel_sm diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 2f6b9a0b..1e11b711 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -861,6 +861,9 @@ module SiSU_Commandline || mod.inspect =~/"--xml-dom"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:xml_docbook_book]=mod.inspect =~/"--docbook"|"--docbook-book"|"--xml-docbook"|"--xml-docbook_book"/ \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:xml_scaffold_structure_sisu]=mod.inspect =~/"--xml-scaffold"|"--xml-scaffold-sisu"/ \ ? { bool: true, set: :on } : { bool: false, set: :na } @@ -998,6 +1001,7 @@ module SiSU_Commandline || act[:concordance][:set]==:on \ || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ + || act[:xml_docbook_book][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } @@ -1046,6 +1050,7 @@ module SiSU_Commandline || act[:concordance][:set]==:on \ || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ + || act[:xml_docbook_book][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 094df7fd..f25cd027 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1478,6 +1478,12 @@ module SiSU_Env ? @rc['odt']['ocn'] : true end + def xml_docbook_ocn? + ((defined? @rc['xml_docbook']['ocn']) \ + && @rc['xml_docbook']['ocn']==false) \ + ? @rc['xml_docbook']['ocn'] + : true + end def xml_scaffold_ocn? ((defined? @rc['xml_scaffold']['ocn']) \ && @rc['xml_scaffold']['ocn']==false) \ @@ -2760,6 +2766,12 @@ WOK ? @rc['program_select']['xml_viewer'] : text_editor end + def docbook_viewer + ((defined? @rc['program_select']['xml_viewer']) \ + && @rc['program_select']['xml_viewer'] =~/\S\S+/) \ + ? @rc['program_select']['xml_viewer'] + : text_editor + end def xml_editor xml_viewer end @@ -3061,6 +3073,9 @@ WOK if @md.opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << @md.fn[:dom] end + if @md.opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book + ft << @md.fn[:xml_docbook_book] + end if @md.opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << @md.fn[:xml_scaffold_structure_sisu] end @@ -3123,6 +3138,9 @@ WOK if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml' end + if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book + ft << 'docbook.xml' << '??.docbook.xml' << 'docbook.??.xml' + end if @opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << 'scaffold.xml' << '??.scaffold.xml' << 'scaffold.??.xml' end @@ -4487,6 +4505,12 @@ WOK fn=base_filename.xml_dom make_file(path,fn) end + def xml_docbook_book + path=output_path.xml_docbook_book.dir + make_path(path) + fn=base_filename.xml_docbook_book + make_file(path,fn) + end def xml_scaffold_structure_sisu path=output_path.xml_scaffold_structure_sisu.dir make_path(path) @@ -4697,6 +4721,15 @@ WOK end self end + def xml_docbook_book + def dir + output_path.xml_docbook.dir + '/' + base_filename.xml_docbook_book + end + def rel + output_path.xml_docbook.rel + '/' + base_filename.xml_docbook_book + end + self + end def xml_scaffold_structure_sisu def dir output_path.xml.dir + '/' + base_filename.xml_scaffold_structure_sisu @@ -5132,6 +5165,24 @@ WOK end i18n(fnh) end + def xml_docbook_book(fh=nil) + fh=default_hash_build(fh,Sfx[:xml_docbook_book]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def xml_scaffold_structure_sisu(fh=nil) fh=default_hash_build(fh,Sfx[:xml_scaffold_structure_sisu]) fh[:lng]=lang_code?(fh[:lng]) @@ -6023,6 +6074,54 @@ WOK xml self end + def xml_docbook + def ft + 'docbook_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end + def xml_docbook_book + def ft + 'docbook_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end def xml_scaffold_structure_sisu def ft 'sisu.scaffold.xml' diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 43ecd6cb..bdd66a59 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -118,6 +118,7 @@ module SiSU_Urls ' --asciidoc (asciidoc txt)'=>@fn[:txt_asciidoc], ' --markdown (markdown txt)'=>@fn[:txt_markdown], ' --rst (rST restructured-text)'=>@fn[:txt_rst], + ' --docbook-book (DocBook Book)'=>@fn[:xml_docbook_book], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -227,6 +228,9 @@ module SiSU_Urls def dom(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_dom.dir}/#{@md.file.base_filename.xml_dom}").result end + def docbook_book(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}").result + end def scaffold_structure_sisu(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_scaffold_structure_sisu.dir}/#{@md.file.base_filename.xml_scaffold_structure_sisu}").result end @@ -438,6 +442,10 @@ module SiSU_Urls and @opt.act[:xml_sax][:set]==:on show.xml.sax(x) end + if x=~/--docbook-book\b/ \ + and @opt.act[:xml_docbook_book][:set]==:on + show.xml.docbook_book(x) + end if x=~/--xml-scaffold-sisu\b/ \ and @opt.act[:xml_scaffold_structure_sisu][:set]==:on show.xml.scaffold_structure_sisu(x) diff --git a/lib/sisu/v5/xml_docbook5.rb b/lib/sisu/v5/xml_docbook5.rb new file mode 100644 index 00000000..d3840d18 --- /dev/null +++ b/lib/sisu/v5/xml_docbook5.rb @@ -0,0 +1,271 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: Docbook book XML rendition + +=end +module SiSU_XML_Docbook_Book + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + @env=@particulars.env + report + SiSU_XML_Docbook_Book::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + def report + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.docbook_viewer} #{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'DocBook',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'DocBook',tool).green_title_hi + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}").flow + end + end + end + class Scroll + def collapsed + %w[ 0 1 2 3 4 5 6 ] + end + def docbook(lc,chlv='') + case lc + when 1 + 'book' + when 2 + lc==chlv ? 'chapter' : 'section' + when 3 + lc==chlv ? 'chapter' : 'section' + when 4 + lc==chlv ? 'chapter' : 'section' + when 5 + 'section' + when 6 + 'section' + end + end + self + end + def put(line) + #@file_docbook.puts line #look into and use perhaps + puts line if @md.opt.act[:verbose_plus][:set]==:on + end + def head + <<-WOK + + + WOK + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading || o.is ==:para + o=@trans.markup_docbook(o) #unless o.obj==nil + end + end + data + end + def tail + tail=<<-WOK + + WOK + put(tail) + end + def output(o,lev=nil,comment='') + puts lev == 0..6 \ + ? "#{space*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{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) + end + end + end + #def chapterlevel + #end + def structure_build_collapsed(data) + #output_file=@md.file.output_path.xml_docbook_book.dir + '/' + @md.file.base_filename.xml_docbook_book + file=SiSU_Env::FileOp.new(@md) + filename_docbook=file.write_file.xml_docbook_book + h=0 + @chlv=chlv=0 + doc_position=:head + filename_docbook.puts head + data.each_with_index do |o,i| + if (defined? o.ocn and not o.ocn.nil?) + ocn="\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" + id=%{ id="o#{o.ocn}" } + else + 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 + unless doc_position==:head + filename_docbook.puts structure_build_tag_close(lev,h) + end + doc_position=:body_and_tail + filename_docbook.puts %{#{space*(lev-1)}<#{tags.docbook(lev,chlv)}> +#{space*lev} +} + filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap + filename_docbook.puts %{#{space*lev}} + h=lev + elsif (o.of ==:para or o.of ==:block) + filename_docbook.puts "#{space*(@splv)}" + filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap + filename_docbook.puts "#{space*(@splv)}" + end + end + filename_docbook.puts structure_build_tag_close(0,h) + filename_docbook.close + end + def structure_build_tag_close(lev,h) + x=[] + case h + when 1 + x << "#{space*0}" if (lev <= 1) + when 2 + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 3 + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 4 + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 5 + x << "#{space*4}" if (lev <= 5) + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 6 + x << "#{space*5}" if (lev <= 6) + x << "#{space*4}" if (lev <= 5) + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + end + x.join("\n") + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xml_shared.rb b/lib/sisu/v5/xml_shared.rb index caad8be0..688e34c3 100644 --- a/lib/sisu/v5/xml_shared.rb +++ b/lib/sisu/v5/xml_shared.rb @@ -474,10 +474,11 @@ module SiSU_XML_Munge gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). #taken unmodified except path from fictionbook gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/m,'●  '). - gsub(/#{Mx[:nbsp]}/,' '). + gsub(/#{Mx[:gl_bullet]}/m,'● '). #  not available + gsub(/#{Mx[:nbsp]}/,' '). #  not available gsub(/<(p|br)>/,'<\1 />') dob.obj=clean(dob.obj) dob -- cgit v1.2.3