From 960c3088bc88f2db879154053280b06c160d4d70 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 21 Apr 2015 14:45:52 -0400 Subject: lib/sisu/*, single libs directory (c&d gone) (7) * removed lib/sisu/{current,develop} dir branches v7 (v5 & v6 retired) * simplify dir structure, offer single version per snapshot * have enjoyed carrying stable and development versions v5 & v6 in a single tarball, may return to this structure --- lib/sisu/xml_docbook5.rb | 376 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100644 lib/sisu/xml_docbook5.rb (limited to 'lib/sisu/xml_docbook5.rb') diff --git a/lib/sisu/xml_docbook5.rb b/lib/sisu/xml_docbook5.rb new file mode 100644 index 00000000..3164be08 --- /dev/null +++ b/lib/sisu/xml_docbook5.rb @@ -0,0 +1,376 @@ +# encoding: utf-8 +=begin + +* Name: SiSU + +** Description: documents, structuring, processing, publishing, search +*** Docbook book XML rendition + +** Author: Ralph Amissah + + + +** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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: + + + +** Git + + + +=end +module SiSU_XML_Docbook_Book + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.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 + require_relative 'shared_metadata' # shared_metadata.rb + 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.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + #SiSU_Env::CreateSite.new(@opt.selections.str).cp_css + #SiSU_Env::CreateSite.new(@opt.selections.str).cp_base_images + Dir.chdir(@opt.f_pth[:pth]) + 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 0 + #tail + end + def document_images + img_pth={ + src: @md.opt.image_src_path, + dest: @md.env.path.webserv + '/_sisu/image', + } + unless FileTest.directory?(img_pth[:dest]) + #mkdir? + end + if FileTest.directory?(img_pth[:dest]) + @md.ec[:image].each do |x| + img={ + src: "#{img_pth[:src]}/#{x}", + dest: "#{img_pth[:dest]}/#{x}", + } + if FileTest.file?(img[:src]) + FileUtils::cp(img[:src],img[:dest]) + else p "Not Found: #{img[:src]}/#{x}" + end + end + end + end + def spaces + Ax[:spaces] + end + def tags + # collapsed --> + def collapsed + %w[ 0 1 2 3 4 5 ] + end + def docbook_tag(lc,chlv='') + case lc + when 0 then 'book' + when 1 then lc==chlv ? 'chapter' : 'section' + when 2 then lc==chlv ? 'chapter' : 'section' + when 3 then lc==chlv ? 'chapter' : 'section' + when 4 then 'section' + when 5 then 'section' + when 6 then '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 + rdf=SiSU_XML_Tags::RDF.new(@md) + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_docbook').stylesheet + <<-WOK + +#{stylesheet.css_head_xml} +#{rdf.comment_xml} + + WOK + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading \ + || o.is ==:para \ + || o.of ==:block \ + || o.is ==:open_close_tags + o=@trans.markup_docbook(o) #unless o.obj==nil + end + end + data + end + def tail + tail=<<-WOK + + WOK + put(tail) + end + def output(o,comment='') + puts o.lc == (0..6) \ + ? "#{spaces*o.lc}<#{o.lc}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{o.lc}>[#{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) + end + end + end + #def chapterlevel + #end + def xml_head + [ + '', + SiSU_Metadata::Summary.new(@md).xml_docbook.metadata, + '' + ].flatten + end + def code_output(o,ocn,filename_docbook) + filename_docbook.puts o.obj.gsub(/\n?(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\n?/m,"\n") + end + def adjust_output(o,ocn,filename_docbook,splv) + if o.obj =~/#{Xx[:split]}/ + outs=o.obj.split(/#{Xx[:split]}/) + outs.each do |out| + if out =~/
" + : '' + id=%{ id="o#{o.ocn}" } + else + ocn,id='','' + end + if (o.is ==:heading || o.is ==:heading_insert) + chlv=(o.lv.to_i == 1) \ + ? @chlv=o.lc.to_i + : 0 + @splv=o.lc + tag_id=o.tags[0] ? %{ id="#{o.tags[0]}" } : '' + if doc_position ==:head + filename_docbook.puts %{#{spaces*o.lc}} + doc_position=:body_and_tail + else + filename_docbook.puts structure_build_tag_close(o.lc,h) + filename_docbook.puts %{#{spaces*(o.lc)}<#{tags.docbook_tag(o.lc,chlv)}#{tag_id}> +#{spaces*o.lc} +} + end + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts %{#{spaces*o.lc}} + h=o.lc + elsif o.of ==:layout \ + and o.is ==:open_close_tags + xml_tag=case o.sym + when :quote_open then '
' + when :quote_close then '
' + else '' + end + unless xml_tag.empty? + filename_docbook.puts "#{spaces*(@splv)}#{xml_tag}" + end + elsif o.of ==:block + if o.is ==:table + filename_docbook.puts SiSU_Tables::TableXMLdocbook.new(o,id).table.obj + elsif o.is ==:code + filename_docbook.puts "#{spaces*(@splv)}" + filename_docbook.puts "#{spaces*(@splv+1)}" + code_output(o,ocn,filename_docbook) + filename_docbook.puts "#{spaces*(@splv+1)}" + filename_docbook.puts "#{spaces*(@splv)}" + else + filename_docbook.puts "#{spaces*(@splv)}" + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts "#{spaces*(@splv)}" + end + elsif o.of ==:para + filename_docbook.puts "#{spaces*(@splv)}" + adjust_output(o,ocn,filename_docbook,@splv) + filename_docbook.puts "#{spaces*(@splv)}" + end + end + filename_docbook.puts structure_build_tag_close(0,h) + filename_docbook.close + end + def structure_build_tag_close(lc,h) + x=[] + case h + when 0 + x << "#{spaces*0}" if (lc <= 0) + when 1 + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 2 + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 3 + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 4 + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 5 + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*5}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + when 6 + x << "#{spaces*6}" if (lc <= 6) + x << "#{spaces*5}" if (lc <= 5) + x << "#{spaces*4}" if (lc <= 4) + x << "#{spaces*3}" if (lc <= 3) + x << "#{spaces*2}" if (lc <= 2) + x << "#{spaces*1}" if (lc <= 1) + x << "#{spaces*0}" if (lc <= 0) + end + x.join("\n") + end + end + end +end +__END__ -- cgit v1.2.3