diff options
author | Ralph Amissah <ralph@amissah.com> | 2009-07-04 11:57:29 -0400 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2009-07-04 11:57:29 -0400 |
commit | 7372f56054259457f77c64cbdb34e736531cfc0e (patch) | |
tree | e46b3ff01bd379cfb476dc8333b397765aef9681 /lib/sisu/v1/shared_html_lite.rb | |
parent | changelog, update (diff) |
move lib to version 1 directory, (lib/sisu/v1) and make related changes
Diffstat (limited to 'lib/sisu/v1/shared_html_lite.rb')
-rw-r--r-- | lib/sisu/v1/shared_html_lite.rb | 276 |
1 files changed, 276 insertions, 0 deletions
diff --git a/lib/sisu/v1/shared_html_lite.rb b/lib/sisu/v1/shared_html_lite.rb new file mode 100644 index 00000000..7fe77e0b --- /dev/null +++ b/lib/sisu/v1/shared_html_lite.rb @@ -0,0 +1,276 @@ +# 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 <http://www.gnu.org/licenses/>. + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + <http://www.fsf.org/licensing/licenses/gpl.html> + <http://www.gnu.org/licenses/gpl.html> + + <http://www.jus.uio.no/sisu/gpl.fsf/toc.html> + <http://www.jus.uio.no/sisu/gpl.fsf/doc.html> + <http://www.jus.uio.no/sisu/gpl.fsf/plain.txt> + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + <http://www.jus.uio.no/sisu> + <http://www.sisudoc.org> + + * Download: + <http://www.jus.uio.no/sisu/SiSU/download.html> + + * Ralph Amissah + <ralph@amissah.com> + <ralph.amissah@gmail.com> + + ** Description: modules shared by db and flatfile output generators, mostly + xml/xhtml/html formatting + +=end +module SiSU_Format_Shared + require "#{SiSU_lib}/defaults" + include SiSU_Viz + class CSS_Format + require "#{SiSU_lib}/defaults" + @@fns=nil + def initialize(md,t_o) + @md,@t_o=md,t_o + if t_o.class==Hash + @txt =t_o[:txt] #|| nil #s/@content/@txt/ + @col =t_o[:col] #|| nil + @notenumber =t_o[:endnote_nr] || nil + #elsif t_o.class == Array + # @txt =txt[0] + #elsif t_o.class == String + # @txt =txt + else + #content.gsub!(/<:i[1-9]>/,'') + #@md,@content=md,content + p t_o.class + p caller + end + @txt.gsub!(/#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/,'') + @id=@ocn=@col[:ocn] + @ocnd,@ocns=@col[:ocnd],@col[:ocns] + @lv=@col[:lev].to_s + @@hname=if @md.fns != @@fns + @@fns=@md.fns + '' + end + @hname=if @col[:seg] \ + and not @col[:seg].to_s.empty? + @@hname=@col[:seg].to_s + else @@hname + end + @tab="\t" + @url_brace=SiSU_Viz::Skin.new.url_decoration + # lots introduced to do html tables in db + @@tablehead,@@tablefoot=[],[] + @vz=SiSU_Env::Get_init.instance.skin + @env=SiSU_Env::Info_env.new(@md.fns) + @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" + end + def urls(data) + @words=[] + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)/ + if word =~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)([;.,](?:\s|$))/ + m,u,d=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)([;.,](?:\s|$))/.match(word).captures + else m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)/.match(word).captures + d='' + end + word=case m + when /\.png|\.jpg|\.gif|c=|\d+x\d+/ + w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/ + w=%{width="#{w}"} if w + h=%{height="#{h}"} if h + c=m[/"(.+?)"/m,1] + caption=%{<br /><p class="caption">#{c}</p>} if c + png=m.scan(/\S+/)[0] + #image_path=if @md.fns =~/\.-ss[tm]$/; @env.url.images_external + #else @env.url.images_local + #end + ins=if u \ + and u.strip !~/^image$/ + %{<a href="#{u}">[#{png}]</a>#{caption}} + else %{[#{png}] #{caption}} + end + word.gsub!(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)/,ins) + else + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + ins=%{<a href="#{u}">#{link}</a>#{d}} + #ins=%{#{link} <a href="#{u}">[link]</a>#{d}} + word.gsub!(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:https?|file|ftp)\S+/,ins) + end + else word + end + word + end + @words=@words.join(' ') + end + def markup(para) + if para !~/^#{Mx[:gr_o]}:code#{Mx[:gr_c]}/ + if para =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}((?:https?|file|ftp)\S+|image)/ + wm=para.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:(?:https?|file|ftp)\S+|image)|\S+/) + words=urls(wm) + para.gsub!(/.+/m,words) + end + para.gsub!(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;') + para.gsub!(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;') + para.gsub!(/#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/m,'') + para.gsub!(/\b[_\\]((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'<a href="\1" target="_top">\1</a>\2') #http ftp matches escaped, no decoration + para.gsub!(/((?:^|\s)#{Mx[:lnk_c]})((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?:\s|$))/,'\1<a href="\2" target="_top">\2</a>\3') #special case \{ e.g. \}http://url + para.gsub!(/(^|#{Mx[:gl_c]}|\s)((?:https?|file|ftp):\/\/\S+?\.[^'"><\s]+?)([;.,]?(?=\s|$))/,%{\\1#{@url_brace.xml_open}<a href="\\2" target="_top">\\2</a>#{@url_brace.xml_close}\\3}) #http ftp matches with decoration + else + para.gsub!(/(^|[^}])_</m,'\1<'); para.gsub!(/(^|[^}])_>/m,'\1>') #code-block: angle brackets special characters + para.gsub!(/(^|[^}])_</m,'\1<'); para.gsub!(/(^|[^}])_>/m,'\1>') + end + para + end + def paragraph + %{#{@tab*1}<p class="h#{@lv}" id="#{@ocn}" type="substantive" header="#{@hname}">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} << "\n" + end + def endnote #used only by db + @txt=markup(@txt) + <<GSUB +#{@tab*1}<p class="endnote" name="note_#{@notenumber}" from="#{@ocn}"> +#{@tab*2}<a href="#{@base_url}#-#{@notenumber}" name="_#{@notenumber}">#{@notenumber}.</a> <note>#{@txt}</note> +#{@tab*1}</p> +GSUB + end + def lev_toc_hname + %{#{@tab*1}<p class="toc#{@lv}" header="#{@hname}"><a href="##{@ocn}">\n#{@tab*2}#{@txt}\n#{@tab*1}</a></p>\n} << "\n" + end + def lev_toc + %{#{@tab*1}<p class="toc#{@lv}"><a href="##{@ocn}">\n#{@tab*2}#{@txt}\n#{@tab*1}</a></p>\n} << "\n" + end + def lev4_plus + %{#{@tab*1}<p class="h#{@lv}" id="#{@ocn}" type="substantive" header="#{@hname}">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} << "\n" + end + def lev4_minus + %{#{@tab*1}<p class="h#{@lv}" id="#{@ocn}" type="substantive">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} << "\n" + end + def norm_comment + %{#{@tab*1}<p class="norm" id="none" type="comment">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} + end + def norm + @txt=markup(@txt) + %{#{@tab*1}<p class="norm" id="#{@ocn}" type="substantive">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} + end + def indent(t) + @txt=markup(@txt) + %{#{@tab*1}<p class="indent#{t}" id="#{@ocn}" type="substantive">\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} + end + def para_table + %{<p class="norm" align="left"><font #{@vz.font_small} #{@vz.font_color} #{@vz.font_face}>} + end + def ocn + %{#{@tab*1}<label class="ocn">#{@ocn}</label>} << "\n" + end + def html_table # get rid of use html_table + @new_content=[] + @txt.split(/\n/).each do |parablock| + m=parablock[/<!f(.+?)!>/,1] + @@tablefoot<<m if m + parablock.gsub!(/<!f.+?!>/,'') + @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u + parablock.gsub!(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/, + #%{<table summary="normal text css" width="100%" border="0" bgcolor="white" cellpadding="2" align="center"><tr><td valign="top" align="justify"><p class="norm" id="\\1"> </p> </td><td>\n} + + %{<table summary="normal text css" width="100%" border="0" bgcolor="white" cellpadding="2" align="center">}) + if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + tablefoot=[] + @@tablefoot.each {|x| tablefoot << %{<p align="center"><font size=2><i>#{x}</i></font></p>\n}} + @@tablefoot=[] + parablock.gsub!(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/, + %{#{@vz.table_close}\n}) # + + #%{#{tablefoot}}) + end + if @@tablehead == 1 + if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u + parablock.gsub!(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n<tr>} + + %{\n<td width="\\1%" valign="top">} + + %{#{para_table}<b>}) + parablock.gsub!(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{</b></td><td width="\\1%" valign="top">} + + %{#{para_table}<b>}) + parablock.gsub!(/#{Mx[:tc_c]}/, '</b></td></tr>') + @@tablehead=0 + end + parablock + else + parablock.gsub!(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n<tr>} + + %{\n<td width="\\1%" valign="top">} + + %{#{para_table}}) + parablock.gsub!(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{</td><td width="\\1%" valign="top">} + + %{#{para_table}}) + parablock.gsub!(/#{Mx[:tc_c]}/, '</td></tr>') + parablock + end + @new_content << parablock + end + @new_content.join + end + end + class CSS_Format_generic #does CSS_Format in one definition, needs to be told about attrib, despite brevity of generic, easier to see structure with CSS_Format + def initialize(attrib='',txt='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) + @tab="\t" + @attrib=attrib + @txt=txt + @lv=@notenumber=lv.to_s + #{@ocn}=ocn.to_s + @hname=hname.to_s + @id=@ocn=id + end + def paragraph + attrib=%{class="#{@attrib}" } + if @ocn + id=%{id="#{@ocn}" } + type=%{type="substantive" } + else + id=%{id="none" } + type=%{type="comment" } + end + header=%{header="#{@hname}" } if @hname + %{#{@tab*1}<p #{attrib}#{id}#{type}#{header}>\n#{@tab*2}#{@txt}\n#{@tab*1}</p>\n} << "\n" + end + def para + paragraph + end + end +end +__END__ |