From 7372f56054259457f77c64cbdb34e736531cfc0e Mon Sep 17 00:00:00 2001
From: Ralph Amissah
Date: Sat, 4 Jul 2009 11:57:29 -0400
Subject: move lib to version 1 directory, (lib/sisu/v1) and make related
changes
---
lib/sisu/v1/xhtml.rb | 465 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 465 insertions(+)
create mode 100644 lib/sisu/v1/xhtml.rb
(limited to 'lib/sisu/v1/xhtml.rb')
diff --git a/lib/sisu/v1/xhtml.rb b/lib/sisu/v1/xhtml.rb
new file mode 100644
index 00000000..e83943af
--- /dev/null
+++ b/lib/sisu/v1/xhtml.rb
@@ -0,0 +1,465 @@
+# coding: utf-8
+=begin
+
+ * Name: SiSU
+
+ * Description: a framework for document structuring, publishing and search
+
+ * Author: Ralph Amissah
+
+ * Copyright: (C) 1997 - 2009 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:
+
+
+ * Ralph Amissah
+
+
+
+ ** Description: xhtml output logic, flow
+ ** Notes: tidy -xml scroll.xhtml >> index.tidy
+=end
+module SiSU_XHTML
+ require "#{SiSU_lib}/defaults"
+ include SiSU_Viz
+ require "#{SiSU_lib}/particulars"
+ include SiSU_Particulars
+ require "#{SiSU_lib}/sysenv"
+ include SiSU_Env
+ require "#{SiSU_lib}/shared_xml"
+ require "#{SiSU_lib}/xml_format"
+ include SiSU_XML_format
+ include SiSU_XML_munge
+ require "#{SiSU_lib}/rexml"
+ include SiSU_Rexml
+ @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0
+ @@tablefoot=''
+ class Source
+ def initialize(opt)
+ @opt=opt
+ @particulars=SiSU_Particulars::Combined_singleton.instance.get_all(opt)
+ end
+ def read
+ begin
+ @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array
+ path=@env.path.output_tell
+ loc=@env.url.output_tell
+ tool=if @opt.cmd =~/[MV]/; "#{@env.program.web_browser} #{loc}/#{@md.fnb}/#{@md.fn[:xhtml]}\n\t#{@env.program.xml_viewer} #{path}/#{@md.fnb}/#{@md.fn[:xhtml]}"
+ elsif @opt.cmd =~/v/; "#{@env.program.web_browser} #{loc}/#{@md.fnb}/#{@md.fn[:xhtml]}"
+ else ''
+ end
+ SiSU_Screen::Ansi.new(@opt.cmd,'invert','XHTML',tool).colorize unless @opt.cmd =~/q/
+ SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:xhtml]}").flow if @opt.cmd =~/[MV]/
+ SiSU_XHTML::Source::Songsheet.new(@particulars).songsheet
+ rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error
+ ensure
+ #file closed in songsheet
+ end
+ end
+ private
+ class Songsheet
+ def initialize(particulars)
+ @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars
+ end
+ def songsheet
+ begin
+ SiSU_XHTML::Source::Scroll.new(@particulars).songsheet
+ SiSU_XHTML::Source::Tidy.new(@md,@env).xml if @md.cmd =~/[vVM]/ # test wellformedness, comment out when not in use
+ SiSU_Rexml::Rexml.new(@md,@md.fn[:xhtml]).xml if @md.cmd =~/M/ # test rexml parsing, comment out when not in use #debug
+ rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error
+ ensure
+ end
+ end
+ end
+ class Scroll
+ require "#{SiSU_lib}/shared_txt"
+ require "#{SiSU_lib}/css"
+ include SiSU_text_utils
+ @@dp=nil
+ @@xml={ :body=>[],:sisu=>[],:open=>[],:close=>[],:head=>[] }
+ def initialize(particulars)
+ @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array
+ @vz=SiSU_Env::Get_init.instance.skin
+ @dp=@@dp ||=SiSU_Env::Info_env.new.digest.pattern
+ @regx=/^(?:(?:#{Mx[:br_page]}\s*|#{Mx[:br_page_new]}\s*)?#{Mx[:lv_o]}\d:(\S*)#{Mx[:lv_c]}\s*)?(.+?)\s*#{Mx[:id_o]}~(\d+);(?:\w|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#@dp:#@dp#{Mx[:id_c]}$/
+ @tab="\t"
+ @trans=SiSU_XML_munge::Trans.new(@md)
+ @sys=SiSU_Env::System_call.new
+ end
+ def songsheet
+ pre
+ @data=markup(@dal_array)
+ post
+ publish
+ end
+ protected
+ def embedded_endnotes(para='')
+ para.gsub!(/#{Mx[:en_a_o]}(\d+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/,
+ '\1\2 ')
+ para.gsub!(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_b_c]}/,
+ '\1\2 ')
+ para.gsub!(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/,
+ '\1\2 ')
+ end
+ def extract_endnotes(para='')
+ notes=para.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/)
+ notes.flatten.each do |e|
+ s=e.to_s
+ util=SiSU_text_utils::Wrap.new(s,70)
+ wrap=util.line_wrap
+ wrap.gsub!(/^(\d+)\s+(.+?)\s*\Z/m, <
+#{@tab*2}\\1. \\2
+#{@tab*1}
+WOK
+)
+ wrap.gsub!(/^([*+]\d+)\s+(.+?)\s*\Z/m, <
+#{@tab*2}\\1 \\2
+#{@tab*1}
+WOK
+)
+ wrap.gsub!(/^([*+]+)\s+(.+?)\s*\Z/m, <
+#{@tab*2}\\1 \\2
+#{@tab*1}
+WOK
+)
+#KEEP alternative presentation of endnotes
+# wrap.gsub!(/^(\d+)\s+(.+?)\s*\Z/m, <
+##{@tab*2}\\1. \\2
+##{@tab*1}
+#WOK
+#)
+ @endnotes << wrap
+ end
+ end
+ def xml_head(meta)
+ txt=meta.text
+ txt.gsub!(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,' ')
+ txt.gsub!(/ & /,' and ')
+ el=meta.el.gsub(/\./,'_')
+ el_txt=meta.el.gsub(/\./,' ')
+ @@xml[:head] <<= if meta.type == 'meta'
+ <#{el_txt.capitalize}:
+#{@tab}<#{el} class="#{meta.attrib}">
+#{@tab*2}#{txt}
+#{@tab}#{el}>
+#{@tab}
+WOK
+ else ''
+ end
+ end
+ def xml_structure(para='',lv='',ocn='',hname='',type='norm') #extracted endnotes
+ lv=lv.to_i
+ n=lv - 1
+ n3=lv + 2
+ lv=nil if lv == 0
+ extract_endnotes(para)
+ para.gsub!(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_a_c]}/,'\1') #footnote/endnote clean
+ para.gsub!(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)\s*#{Mx[:id_o]}#@dp#{Mx[:id_c]}#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean
+ if para[@regx]
+ paragraph="#{para[@regx,2]}"
+ util=SiSU_text_utils::Wrap.new(paragraph,70)
+ wrapped=util.line_wrap
+ end
+ @@xml[:body] << if para[@regx,3]; %{#{@tab*0}