From 306aed5b8a559aad2fb944a946ffdda9713f07ec Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 6 Mar 2010 09:47:55 -0500 Subject: introducing version 2, major patch, (version 1 libraries retained) --- lib/sisu/v2/html.rb | 630 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 630 insertions(+) create mode 100644 lib/sisu/v2/html.rb (limited to 'lib/sisu/v2/html.rb') diff --git a/lib/sisu/v2/html.rb b/lib/sisu/v2/html.rb new file mode 100644 index 00000000..4959d683 --- /dev/null +++ b/lib/sisu/v2/html.rb @@ -0,0 +1,630 @@ +# coding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2010, 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: html generation, processing + +=end +module SiSU_HTML + require 'pstore' + require "#{SiSU_lib}/particulars" # particulars.rb + include SiSU_Particulars + require "#{SiSU_lib}/defaults" # defaults.rb + include SiSU_Viz + require "#{SiSU_lib}/html_table" # html_table.rb + require "#{SiSU_lib}/html_format" # html_format.rb + include SiSU_HTML_Format + require "#{SiSU_lib}/html_segments" # html_segments.rb + include SiSU_HTML_seg + require "#{SiSU_lib}/html_scroll" # html_scroll.rb + require "#{SiSU_lib}/html_promo" # html_promo.rb + include SiSU_HTML_promo + require "#{SiSU_lib}/html_tune" # html_tune.rb + include SiSU_HTML_Tune + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::Combined_singleton.instance.get_all(opt) + end + def read + songsheet + end + def songsheet + begin + @md=@particulars.md + @fnb=@md.fnb + @env=@particulars.env + loc=@env.url.output_tell + tool=if @opt.cmd =~/z/; "#{@env.program.web_browser} #{loc}/#{@fnb}/#{@md.fn[:index]}" + elsif @opt.cmd =~/[MVv]/; "#{@env.program.web_browser} #{loc}/#{@fnb}/#{@md.fn[:index]}" + else '' + end + SiSU_Screen::Ansi.new(@opt.cmd,'HTML',tool).green_hi_blue unless @opt.cmd =~/q/ + SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.path.output_tell}/#{@fnb}/#{@md.fn[:index]}").flow if @opt.cmd =~/[MV]/ + SiSU_Env::Info_skin.new(@md).select + data=nil + my_make=SiSU_Env::Create_file.new(@opt.cmd,@opt.fns,@md) #Beware #FIX opt and md, both not necessary + SiSU_Env::SiSU_file.new(@md).mkdir + @tuned_file_array=SiSU_HTML::Source::Html_environment.new(@particulars).tuned_file_instructions + data=@tuned_file_array + scr_endnotes=SiSU_HTML::Source::Endnotes.new(data,@md).scroll + toc=SiSU_HTML::Source::Toc.new(@md,data).songsheet + links_guide=SiSU_HTML::Source::Links_guide.new(data,@md).toc + data=@tuned_file_array + scr_toc=SiSU_HTML::Source::Scroll_head_and_segtoc.new(@md,toc,links_guide).in_common #watch + SiSU_HTML::Source::Seg.new(@md,data).songsheet + data=@tuned_file_array + scr=SiSU_HTML::Source::Scroll.new(@md,data,scr_endnotes).songsheet + scroll=SiSU_HTML::Source::Scroll_output.new(scr_toc,scr[:body],scr[:metadata],scr[:owner_details],scr[:tails],@md).publish + SiSU_HTML::Source::Output.new(scroll,@md).scroll + rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error + ensure + unless @opt.cmd =~/[MV]/ #check maintenance flag + texfiles=Dir["#{@env.path.tune}/#{@opt.fns}*"] + texfiles.each do |f| + if FileTest.file?(f) + File.unlink(f) + end + end + end + SiSU_Env::Create_file.new(@opt.cmd,@opt.fns).param_instantiate + @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} + @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 + @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} + @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' + @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 + end + end + private + class Html_environment + def initialize(particulars) + @particulars=particulars + @md,@env=particulars.md,particulars.env + @vz=SiSU_Env::Get_init.instance.skin + @env,@css,@symlnk=particulars.env,SiSU_Style::CSS.new,SiSU_Env::Create_system_link.new #home + end + def link_images + @symlnk.images + end + def directories + my_make=SiSU_Env::Create_file.new(@md.cmd,@md.fns) + @path={ :root=>my_make.html_root } + title=File.basename(@md.fns,'.rb') + SiSU_Env::SiSU_file.new(@md).mkdir + end + def tuned_file_instructions + @tell=SiSU_Screen::Ansi.new(@md.cmd) + @md.cmd=@md.cmd.gsub(/H/,'h') + @md.file_type='html' if @md.cmd =~/[hon]/ + directories + newfilename=%{#{@env.path.output}/#{@md.fnb}/#{@md.fn[:index]}} if @md.file_type =~/html/ + dal_array=@particulars.dal_array # dal file drawn here + @tuned_file_array=SiSU_HTML_Tune::Tune.new(dal_array,@md).songsheet + @tuned_file_array + end + end + class Links_guide + @links_guide_toc=[] + def initialize(data,md) + @data,@md=data,md + end + def toc + @links_guide_toc=[] + format_head_toc=SiSU_HTML_Format::Head_toc.new(@md) + guide_type='horzontal' #values: horizontal or vertical + @links_guide_toc << format_head_toc.links_guide_open(guide_type) + if defined? @md.lnk \ + and @md.lnk + @md.lnk.each do |l| + if defined? l[:say] + target=if l[:url] !~/^\.(\.)?\//; 'external' + else '_top' + end + s_lnk_url,s_lnk_lnk=l[:url],l[:say] + txt_obj={:lnk_url =>s_lnk_url,:lnk_txt =>s_lnk_lnk,:target =>target} + lev_dob_ocn=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + @links_guide_toc << lev_dob_ocn.links_guide if s_lnk_lnk + end + end + end + format_head_toc=SiSU_HTML_Format::Head_toc.new(@md) + @links_guide_toc << format_head_toc.links_guide_close #(guide_type) + @links_guide_toc + end + end + class Endnotes + include SiSU_HTML_Format + def initialize(data,md) + @data,@md=data,md + end + def scroll + @scr_endnotes=[] + format_head_scroll=SiSU_HTML_Format::Head_scroll.new(@md) + @data.each do |dob| + pg=dob.dup + unless pg.is =~/^code/ + if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / + endnote_array=[] + if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) + end + endnote_array.flatten.each do |note| + txt_obj={:txt =>note} + format_scroll=SiSU_HTML_Format::Format_scroll.new(@md,txt_obj) + @scr_endnotes << format_scroll.endnote_body + end + end + end + end + @scr_endnotes + end + end + class Toc [],:seg_mini=>[],:scr=>[] } + @@seg_url='' + @@firstseg=nil + def initialize(md=nil,data='') + @data,@md=data,md + @vz=SiSU_Env::Get_init.instance.skin + @tell=SiSU_Screen::Ansi.new(@md.cmd) if @md + end + def songsheet #extracts toc for scroll & seg + SiSU_Screen::Ansi.new(@md.cmd,'Toc').txt_grey unless @md.cmd =~/q/ + toc=nil + @@firstseg=nil + @@toc={ :seg=>[],:seg_mini=>[],:scr=>[] } + @data.each do |dob| + if dob.is=='heading' \ + or dob.is=='heading_insert' + dob_toc=dob.dup + toc=if dob_toc.is =='heading' \ + or dob.is=='heading_insert' + toc=case dob_toc.ln + when 1; Toc.new(@md,dob_toc).level_1 + when 2; Toc.new(@md,dob_toc).level_2 + when 3; Toc.new(@md,dob_toc).level_3 + when 4; Toc.new(@md,dob_toc).level_4 + when 5; Toc.new(@md,dob_toc).level_5 + when 6; Toc.new(@md,dob_toc).level_6 + else nil + end + end + toc.each do |k,d| + d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + end if toc + if @@firstseg.nil? \ + and dob.ln==4 \ + and dob.name =~/\S+/ + @@firstseg=dob.name + end + if toc + begin + @@toc[:seg] << toc[:seg] if toc[:seg] + @@toc[:seg_mini] << toc[:seg_mini] if toc[:seg_mini] + @@toc[:scr] << toc[:scr] if toc[:scr] + rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error + end + end + end + end + @md.firstseg=@@firstseg + @@toc + end + def minitoc + minitoc=@@toc[:seg_mini].join("\n") + '
' + minitoc + '
' + end + protected + def rss #sort all wrong, disabled but kept + @@toc[:seg] <<< +
+

+(relatively static) RSS feeds for DOCUMENTS:
+RSS feed http://www.jus.uio.no/lm/rssfeed/documents.xml
+RSS feed http://www.jus.uio.no/lm/rssfeed/tradelaw.xml
+RSS feed http://www.jus.uio.no/lm/rssfeed/environmental.xml
+

info@address.com
+

+
+WOK + end +#not used --> + def level_endnotes + if @md.flag_endnotes + format_head_scroll=SiSU_HTML_Format::Head_scroll.new(@md) + @@toc[:scr] << format_head_scroll.toc_endnote + end + end + def level_concordance + format_head_toc=SiSU_HTML_Format::Head_toc.new(@md) + @@toc[:seg_mini] << format_head_toc.mini_seg_concordance + end + def level_metadata + format_head_toc=SiSU_HTML_Format::Head_toc.new(@md) + @@toc[:scr] << format_head_toc.metadata + @@toc[:seg] << format_head_toc.seg_metadata + @@toc[:seg_mini] << format_head_toc.mini_seg_metadata + end + def level_word_index + format_head_toc=SiSU_HTML_Format::Head_toc.new(@d0c) + @@toc[:scr] << format_head_toc.concordance + @@toc[:seg] << format_head_toc.concordance + @@toc[:seg_mini] << format_head_toc.mini_concordance + end +# <-- not used + def level_1 + dob=@data + linkname,link=dob.obj.strip,dob.ocn + if link \ + and link !~/#/ #% keep eye on link + p_num=SiSU_HTML_Format::Paragraph_number.new(@md,link) + end + title=if dob.obj !~/Metadata/; linkname + else + link='metadata' + %{#{linkname}} + end + toc={} + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:seg]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + format_toc.lev0 + else format_toc.lev1 + end + toc[:seg_mini]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + x=if @md.concord_make + format_toc.mini_concord_tail + else format_toc.mini_tail + end + else format_toc.mini_lev1 + end + title=if dob.ocn ==0 + if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + %{#{linkname}} + else linkname + end + else + @@toc[:scr] << '
' + link=if dob.ln; dob.ln + else '' + end + %{#{linkname}} + end + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + format_toc.lev0 + else format_toc.lev1 + end + toc + end + def level_2 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + p_num=if ocn \ + and ocn !~/#/ + SiSU_HTML_Format::Paragraph_number.new(@md,ocn) + else nil + end + txt_obj={:txt =>linkname} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev2 + toc[:seg_mini]=format_toc.mini_lev2 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=format_toc.lev2 + end + toc + end + def level_3 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + p_num=if ocn \ + and ocn !~/#/ + SiSU_HTML_Format::Paragraph_number.new(@md,ocn) + else nil + end + txt_obj={:txt =>linkname} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev3 + toc[:seg_mini]=format_toc.mini_lev3 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=format_toc.lev3 + end + toc + end + def level_4 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + p_num=SiSU_HTML_Format::Paragraph_number.new(@md,ocn) if ocn + if dob.ln ==4 + seg_link=%{ + #{dob.obj} + } + @@seg_url=dob.name + elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/ + seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/, + %{\\1 \\2 }) + end + p_num=SiSU_HTML_Format::Paragraph_number.new(@md,ocn) if ocn + txt_obj={:txt =>seg_link} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev4 + toc[:seg_mini]=format_toc.mini_lev4 + title=%{#{p_num.goto}#{linkname}} if p_num + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=format_toc.lev4 + toc + #end + end + def level_5 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_HTML_Format::Paragraph_number.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} + } + txt_obj={:txt =>lnk_n_txt} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:seg]=format_toc.lev5 + toc[:seg_mini]=format_toc.mini_lev5 + title=%{#{p_num.goto}#{linkname}} + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=format_toc.lev5 + end + toc + end + def level_6 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_HTML_Format::Paragraph_number.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} +} + txt_obj={:txt =>lnk_n_txt} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:seg]=format_toc.lev6 + toc[:seg_mini]=format_toc.mini_lev6 + title=%{#{p_num.goto}#{linkname}} + txt_obj={:txt =>title} + format_toc=SiSU_HTML_Format::Format_toc.new(@md,txt_obj) + toc[:scr]=format_toc.lev6 + end + toc + end + def level_crosslink + dob=@data + if dob !~/^4~!/ + dob.gsub!(/^4~!\s+(\S+)\s+(.+)/, + %{ +
+ #{@png.crosslink_ext} +   \\2 + <\/a> +
+}) + else + dob.gsub!(/^4~!\s+(\S+)\s+(.+)/, + %{
+ + + #{@png.crosslink} +   \\2 + <\/a> +
+}) + end + end + end + class Scroll_head_and_segtoc < Toc + def initialize(md='',toc='',links_guide_toc='') + @md,@toc,@links_guide_toc=md,toc,links_guide_toc + @vz=SiSU_Env::Get_init.instance.skin + end + def in_common + toc_shared=[] + @segtoc=[] + SiSU_Screen::Ansi.new(@md.cmd,'Scroll & Segtoc').txt_grey unless @md.cmd =~/q/ + format_head_toc=SiSU_HTML_Format::Head_toc.new(@md) + dochead=format_head_toc.head + dochead.gsub!(/toc\.(html)/,'doc.\1') #kludge + ads=SiSU_HTML_promo::Ad.new(@md) + toc_shared << dochead << ads.div.major + @segtoc << format_head_toc.head << ads.div.major + toc_shared << format_head_toc.toc_head_escript if SiSU_HTML_Format::Head_toc.method_defined? :toc_head_escript + @segtoc << format_head_toc.toc_head_escript if SiSU_HTML_Format::Head_toc.method_defined? :toc_head_escript + toc_shared << format_head_toc.scroll_head_navigation_band + if defined? @md.rights.all + rights=format_head_toc.rights.all + rights=SiSU_HTML_Tune::Clean_html.new(rights).clean + end + if @md.prefix_b + prefix_b=format_head_toc.notes.prefix_b + prefix_b=SiSU_HTML_Tune::Clean_html.new(prefix_b).clean + end + @seg_toc_band=format_head_toc.seg_head_navigation_band('pdf') #bug, vary depending on type of doc !! examine + @seg_toc_band_bottom=format_head_toc.seg_head_navigation_band_bottom('pdf') #bug, vary depending on type of doc !! examine + @segtoc << @seg_toc_band + toc_shared << format_head_toc.scroll_head_title_banner_open + @segtoc << format_head_toc.seg_head_title_banner_open + tmp_head=nil + doc_title_endnote=@md.title.full.gsub(/(\*+)/,'\1') + tmp_head=doc_title_endnote + "\n" + txt_obj={:txt =>tmp_head} + format_txt_obj=SiSU_HTML_Format::Format_text_object.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + @segtoc << format_txt_obj.center_bold + if @md.creator.author + creator_endnote=@md.creator.author.gsub(/(\*+)/,%{ \\1}) + tmp_head=creator_endnote + "\n" + txt_obj={:txt =>tmp_head} + format_txt_obj=SiSU_HTML_Format::Format_text_object.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + @segtoc << format_txt_obj.center_bold + end + toc_shared << format_head_toc.copyat + @segtoc << format_head_toc.copyat + toc_shared << "#{@vz.table_close*1}\n" + @segtoc << "#{@vz.table_close*1}\n" + tmp_head=nil + if @md.prefix_a + tmp_head ||= %{

#{@md.prefix_a}\n} + toc_shared << tmp_head.dup + @segtoc << tmp_head.dup + end + tmp_head=nil + toc_shared << @links_guide_toc + toc_shared << rights if @md.rights.all + toc_shared << prefix_b if @md.prefix_b + #Table of Contents added/appended here + toc_shared << @toc[:scr] + @segtoc << @links_guide_toc + @segtoc << @toc[:seg] + @segtoc << rights if @md.rights.all + @segtoc << prefix_b if @md.prefix_b + #Segtoc tail added here + @segtoc << "

\n" #bugfix sort later DEBUGNOW + @segtoc << @seg_toc_band_bottom + ads=SiSU_HTML_promo::Ad.new(@md) + @segtoc << format_head_toc.seg_navigation_tail << ads.div.close << ads.display << format_head_toc.html_close + @segtoc.flatten!.compact! + Output.new(@segtoc,@md).segtoc + @segtoc=[] + @toc[:scr],@toc[:seg]=[],[] + toc_shared + end + end + class Table < SiSU_HTML_table::Table_html + end + class Scroll < SiSU_HTML_scroll::Scroll + end + class Scroll_output + def initialize(scr_toc,scr_body,scr_metadata,scr_owner_details,scr_tails,md) + @scr_toc,@scr_body,@scr_metadata,@scr_owner_details,@scr_tails,@md=scr_toc,scr_body,scr_metadata,scr_owner_details,scr_tails,md + end + def publish + scroll=[] + hr='

' + scroll << @scr_toc << '
' << hr << @scr_body << @scr_endnotes << hr << @scr_owner_details << '
' << @scr_tails + scroll.flatten!.compact! + end + end + class Seg < SiSU_HTML_seg::Seg + end + class Output + def initialize(data='',md='') + @data,@md=data,md + @my_make=SiSU_Env::Create_file.new(@md.cmd,@md.fns,@md) + end + def scroll + begin + @filename_html_scroll=@my_make.file_html_scroll(@md) + @data.each do |para| + para.strip! + para.gsub!(/<:.+?>/,'') + para.gsub!(/#{Rx[:mx_fa_clean]}/,'') + unless para =~/\A\s*\Z/ + @filename_html_scroll.puts para,"\n" + end + end + rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error + end + end + def segtoc + begin + @filename_html_segtoc=@my_make.file_html_segtoc(@md) + @filename_html_index=@my_make.file_html_index(@md) + @data.each do |para| + para.strip! + para.gsub!(//,'') + unless para =~/\A\s*\Z/ + @filename_html_segtoc.puts para,"\n" + @filename_html_index.puts para,"\n" + end + end + rescue; SiSU_Errors::Info_error.new($!,$@,@md.cmd,@md.fns).error + end + end + end + end +end +__END__ -- cgit v1.2.3