d: html, segments, reorganize, introduce new file
[software/sisu] / lib / sisu / develop / html.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html generation, processing
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/html.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML
58 begin
59 require 'pstore'
60 rescue LoadError
61 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
62 error('pstore NOT FOUND (LoadError)')
63 end
64 require_relative 'se_hub_particulars' # se_hub_particulars.rb
65 include SiSU_Particulars
66 require_relative 'html_table' # html_table.rb
67 require_relative 'html_parts' # html_parts.rb
68 require_relative 'html_format' # html_format.rb
69 include SiSU_HTML_Format
70 require_relative 'html_segments' # html_segments.rb
71 include SiSU_HTML_Seg
72 require_relative 'html_scroll' # html_scroll.rb
73 require_relative 'html_promo' # html_promo.rb
74 include SiSU_HTML_Promo
75 require_relative 'html_tune' # html_tune.rb
76 include SiSU_HTML_Tune
77 class Source
78 def initialize(opt)
79 @opt=opt
80 @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt)
81 end
82 def read
83 begin
84 songsheet
85 ensure
86 SiSU_Env::CreateSite.new(@opt).cp_css
87 SiSU_Env::CreateSite.new(@opt).cp_base_images
88 Dir.chdir(@opt.f_pth[:pth])
89 end
90 end
91 def songsheet
92 begin
93 @md=@particulars.md
94 @fnb=@md.fnb
95 @env=@particulars.env
96 primary_output_file=(@opt.act[:html_seg][:set]==:on) \
97 ? (@md.file.output_path.html_seg.dir + '/' + @md.file.base_filename.html_segtoc)
98 : (@md.file.output_path.html_scroll.dir + '/' + @md.file.base_filename.html_scroll)
99 unless @opt.act[:quiet][:set]==:on
100 tool=(@opt.act[:verbose][:set]==:on \
101 || @opt.act[:verbose_plus][:set]==:on \
102 || @opt.act[:maintenance][:set]==:on) \
103 ? ("#{@env.program.web_browser} file://#{primary_output_file}")
104 : ("[#{@opt.f_pth[:lng_is]}] #{@opt.fno}")
105 (@opt.act[:verbose][:set]==:on \
106 || @opt.act[:verbose_plus][:set]==:on \
107 || @opt.act[:maintenance][:set]==:on) \
108 ? SiSU_Screen::Ansi.new(
109 @opt.act[:color_state][:set],
110 'HTML',
111 tool
112 ).green_hi_blue
113 : SiSU_Screen::Ansi.new(
114 @opt.act[:color_state][:set],
115 'HTML',
116 tool
117 ).green_title_hi
118 if (@opt.act[:verbose_plus][:set]==:on \
119 || @opt.act[:maintenance][:set]==:on)
120 SiSU_Screen::Ansi.new(
121 @opt.act[:color_state][:set],
122 @opt.fns,
123 "file://#{primary_output_file}"
124 ).flow
125 end
126 end
127 data=nil
128 tuned_file_array=SiSU_HTML::Source::HTML_Environment.new(@particulars).tuned_file_instructions
129 data=tuned_file_array
130 if @opt.act[:html_scroll][:set]==:on
131 scr_endnotes=SiSU_HTML::Source::Endnotes.new(data,@md).scroll
132 end
133 toc=SiSU_HTML::Source::Toc.new(@md,data).songsheet
134 links_guide=SiSU_HTML::Source::LinksGuide.new(data,@md).toc
135 data=tuned_file_array
136 scr_toc=SiSU_HTML::Source::ScrollHeadAndSegToc.new(@md,toc,links_guide).in_common #watch
137 if @opt.act[:html_seg][:set]==:on
138 SiSU_HTML::Source::Seg.new(@md,data).songsheet
139 end
140 data=tuned_file_array
141 if @opt.act[:html_scroll][:set]==:on
142 scr=SiSU_HTML::Source::Scroll.new(@md,data,scr_endnotes).songsheet
143 scroll=SiSU_HTML::Source::ScrollOutput.new(
144 scr_toc,
145 scr[:body],
146 scr[:metadata],
147 scr[:owner_details],
148 scr[:tails],
149 @md
150 ).publish
151 SiSU_HTML::Source::Output.new(scroll,@md).scroll
152 end
153 rescue
154 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
155 __LINE__.to_s + ':' + __FILE__
156 end
157 ensure
158 unless (@opt.act[:verbose_plus][:set]==:on \
159 || @opt.act[:maintenance][:set]==:on)
160 texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"]
161 texfiles.each do |f|
162 if FileTest.file?(f)
163 File.unlink(f)
164 end
165 end
166 end
167 SiSU_Env::Clear.new(@opt.selections.str,@opt.fns,@md).param_instantiate
168 @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc={},{},{},{},{}
169 @@tracker=0
170 @@seg_name,@@seg_name_x,@@seg_subtoc_array,@@seg_endnotes_array,@@tablefoot=Array.new(5){[]}
171 @@filename_seg,@@seg_url,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','',''
172 end
173 end
174 private
175 class HTML_Environment
176 def initialize(particulars)
177 @particulars=particulars
178 @md,@env=particulars.md,particulars.env
179 @env,@css=particulars.env,SiSU_Style::CSS.new
180 end
181 def tuned_file_instructions
182 @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set])
183 ao_array=@particulars.ao_array # ao file drawn here
184 tuned_file_array=SiSU_HTML_Tune::Tune.new(ao_array,@md).songsheet
185 tuned_file_array
186 end
187 end
188 class LinksGuide
189 @links_guide_toc=[]
190 def initialize(data,md)
191 @data,@md=data,md
192 @links_guide_=SiSU_Env::CreateSite.new(@md.opt).html_quick_ref?
193 end
194 def toc
195 @links_guide_toc=[]
196 if @links_guide_
197 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
198 guide_type='horzontal' #values: horizontal or vertical
199 @links_guide_toc << format_head_toc.links_guide_open(guide_type)
200 if defined? @md.lnk \
201 and @md.lnk
202 @md.lnk.each do |l|
203 if defined? l[:say]
204 target=(l[:url] !~/^\.(\.)?\//) \
205 ? 'external'
206 : '_top'
207 s_lnk_url,s_lnk_lnk=l[:url],l[:say]
208 txt_obj={
209 lnk_url: s_lnk_url,
210 lnk_txt: s_lnk_lnk,
211 target: target,
212 }
213 lev_dob_ocn=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
214 @links_guide_toc << lev_dob_ocn.links_guide if s_lnk_lnk
215 end
216 end
217 end
218 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
219 @links_guide_toc << format_head_toc.links_guide_close #(guide_type)
220 @links_guide_toc
221 else ''
222 end
223 end
224 end
225 class Endnotes
226 include SiSU_HTML_Format
227 def initialize(data,md)
228 @data,@md=data,md
229 end
230 def scroll
231 @scr_endnotes=[]
232 SiSU_HTML_Format::HeadScroll.new(@md)
233 @data.each do |dob|
234 pg=dob.dup
235 unless pg.is ==:code
236 if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ /
237 endnote_array=[]
238 if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m
239 endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m)
240 end
241 if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m
242 endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m)
243 end
244 if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m
245 endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m)
246 end
247 endnote_array.flatten.each do |note|
248 txt_obj={ txt: note }
249 format_scroll=SiSU_HTML_Format::FormatScroll.new(@md,txt_obj)
250 @scr_endnotes << format_scroll.endnote_body
251 end
252 end
253 end
254 end
255 @scr_endnotes
256 end
257 end
258 class Toc <LinksGuide
259 @@toc={ seg: [], seg_mini: [], scr: [] }
260 @@seg_url=''
261 @@firstseg=nil
262 def initialize(md=nil,data='')
263 @data,@md=data,md
264 @ocn_html_identifier=
265 SiSU_Env::ProcessingSettings.new(@md).ocn_html_identifier
266 @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md
267 end
268 def songsheet #extracts toc for scroll & seg
269 if (@md.opt.act[:verbose][:set]==:on \
270 || @md.opt.act[:verbose_plus][:set]==:on \
271 || @md.opt.act[:maintenance][:set]==:on)
272 SiSU_Screen::Ansi.new(
273 @md.opt.act[:color_state][:set],
274 'Toc'
275 ).txt_grey
276 end
277 toc=nil
278 @@firstseg=nil
279 @@toc={ seg: [], seg_mini: [], scr: [] }
280 @data.each do |dob|
281 if dob.is==:heading \
282 || dob.is==:heading_insert
283 dob_toc=dob.dup
284 toc=if dob_toc.is ==:heading \
285 || dob.is==:heading_insert
286 toc=case dob_toc.ln
287 when 0 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_0
288 when 1 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_1
289 when 2 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_2
290 when 3 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_3
291 when 4 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_4
292 when 5 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_5
293 when 6 then SiSU_HTML::Source::Toc.new(@md,dob_toc).level_6
294 else nil
295 end
296 end
297 toc.each do |k,d|
298 d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
299 end if toc
300 if @@firstseg.nil? \
301 and dob.ln==4 \
302 and dob.name =~/\S+/
303 @@firstseg=dob.name
304 end
305 if toc
306 begin
307 @@toc[:seg] << toc[:seg] if toc[:seg]
308 @@toc[:seg_mini] << toc[:seg_mini] if toc[:seg_mini]
309 @@toc[:scr] << toc[:scr] if toc[:scr]
310 rescue
311 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
312 __LINE__.to_s + ':' + __FILE__
313 end
314 end
315 end
316 end
317 end
318 @md.firstseg=@@firstseg
319 @@toc
320 end
321 def minitoc
322 minitoc=@@toc[:seg_mini].join("\n")
323 '<div class="toc">' + minitoc + '</div>'
324 end
325 protected
326 def rss #sort all wrong, disabled but kept
327 @@toc[:seg] <<<<WOK
328 <center>
329 <table><tr><td>
330 <p><font color="#222222" #{the_font.set_face} size="2">
331 (relatively static) RSS feeds for DOCUMENTS:<br>
332 <a href="../rssfeed/documents.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/documents.xml<br>
333 <a href="../rssfeed/tradelaw.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/tradelaw.xml<br>
334 <a href="../rssfeed/environmental.xml"><img border="0" height="14" width="36" src="../_sisu/image/rss.png" alt="RSS feed"></a>&nbsp;http://www.jus.uio.no/lm/rssfeed/environmental.xml<br>
335 <center><a href="mailto:info@address.com" target="_top">info@address.com</a></center>
336 </font></p>
337 </td></tr></table>
338 WOK
339 end
340 #not used -->
341 def level_endnotes
342 if @md.flag_endnotes
343 format_head_scroll=SiSU_HTML_Format::HeadScroll.new(@md)
344 @@toc[:scr] << format_head_scroll.toc_endnote
345 end
346 end
347 def level_concordance
348 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
349 @@toc[:seg_mini] << format_head_toc.mini_seg_concordance
350 end
351 def level_metadata
352 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
353 @@toc[:scr] << format_head_toc.metadata
354 @@toc[:seg] << format_head_toc.seg_metadata
355 @@toc[:seg_mini] << format_head_toc.mini_seg_metadata
356 end
357 def level_word_index
358 format_head_toc=SiSU_HTML_Format::HeadToc.new(@d0c)
359 @@toc[:scr] << format_head_toc.concordance
360 @@toc[:seg] << format_head_toc.concordance
361 @@toc[:seg_mini] << format_head_toc.mini_concordance
362 end
363 # <-- not used
364 def level_0
365 dob=@data
366 linkname,link=dob.obj.strip,dob.ocn
367 if link \
368 and link !~/#/ #% keep eye on link
369 SiSU_HTML_Format::ParagraphNumber.new(@md,link)
370 end
371 title=linkname
372 toc={}
373 txt_obj={ txt: title }
374 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
375 toc[:seg]=format_toc.lev0
376 toc[:seg_mini]=format_toc.mini_lev0
377 title=if dob.ocn ==0 then linkname
378 else
379 @@toc[:scr] << '<br>'
380 %{<b><a href="##{@ocn_html_identifier}#{dob.ocn}">#{linkname}</a></b>}
381 end
382 txt_obj={ txt: title }
383 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
384 toc[:scr]=format_toc.lev0
385 toc
386 end
387 def level_1
388 dob=@data
389 linkname,link=dob.obj.strip,dob.ocn
390 if link \
391 and link !~/#/ #% keep eye on link
392 SiSU_HTML_Format::ParagraphNumber.new(@md,link)
393 end
394 title=if dob.obj !~/^Metadata$/ then linkname
395 else
396 link='metadata'
397 %{<b><a href="#{link}#{@md.lang_code_insert}#{Sfx[:html]}">#{linkname}</a></b>}
398 end
399 toc={}
400 txt_obj={ txt: title }
401 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
402 toc[:seg]=if dob.name =~/^meta/ \
403 and dob.obj =~/Document Information/
404 format_toc.lev0
405 else format_toc.lev1
406 end
407 toc[:seg_mini]=if dob.name =~/^meta/ \
408 and dob.obj =~/Document Information/
409 @md.concord_make \
410 ? format_toc.mini_concord_tail
411 : format_toc.mini_tail
412 else format_toc.mini_lev1
413 end
414 title=if dob.ocn ==0
415 if dob.name =~/^meta/ \
416 and dob.obj =~/Document Information/
417 %{<a href="#docinfo">#{linkname}</a>}
418 else linkname
419 end
420 else
421 @@toc[:scr] << '<br>'
422 %{<b><a href="##{@ocn_html_identifier}#{dob.ocn}">#{linkname}</a></b>}
423 end
424 txt_obj={ txt: title }
425 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
426 toc[:scr]=if dob.obj =~/^Metadata$/ then ''
427 elsif txt_obj[:txt] =~/<a href="#">/
428 format_toc.lev1.gsub(/<a href="#">|<\/a>/,'')
429 else format_toc.lev1
430 end
431 toc
432 end
433 def level_2
434 dob=@data
435 linkname,ocn=dob.obj.strip,dob.ocn
436 p_num=if ocn \
437 and ocn !~/#/
438 SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
439 else nil
440 end
441 txt_obj={ txt: linkname }
442 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
443 toc={}
444 toc[:seg]=format_toc.lev2
445 toc[:seg_mini]=format_toc.mini_lev2
446 if p_num
447 title=%{#{p_num.goto}#{linkname}</a>}
448 txt_obj={ txt: title }
449 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
450 toc[:scr]=if txt_obj[:txt] =~/<a href="#">/
451 format_toc.lev2.gsub(/<a href="#">|<\/a>/,'')
452 else format_toc.lev2
453 end
454 end
455 toc
456 end
457 def level_3
458 dob=@data
459 linkname,ocn=dob.obj.strip,dob.ocn
460 p_num=if ocn \
461 and ocn !~/#/
462 SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
463 else nil
464 end
465 txt_obj={ txt: linkname }
466 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
467 toc={}
468 toc[:seg]=format_toc.lev3
469 toc[:seg_mini]=format_toc.mini_lev3
470 if p_num
471 title=%{#{p_num.goto}#{linkname}</a>}
472 txt_obj={ txt: title }
473 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
474 toc[:scr]=if txt_obj[:txt] =~/<a href="#">/
475 format_toc.lev3.gsub(/<a href="#">|<\/a>/,'')
476 else format_toc.lev3
477 end
478 end
479 toc
480 end
481 def level_4
482 dob=@data
483 linkname,ocn=dob.obj.strip,dob.ocn
484 p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn) if ocn
485 if dob.ln ==4
486 fnh={
487 fn: dob.name,
488 }
489 f=@md.file.base_filename.html_seg(fnh)
490 seg_link=%{ <a href="#{f}" target="_top">
491 #{dob.obj}
492 </a> }
493 @@seg_url=dob.name
494 elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/
495 fn,hd=/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/.match(dob.obj)[1,2]
496 fnh={
497 fn: fn,
498 }
499 f=@md.file.base_filename.html_seg(fnh)
500 seg_link=%{<a href="#{f}" target="_top">#{fn} #{hd}</a> }
501 end
502 p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn) if ocn
503 @file=SiSU_Env::FileOp.new(@md) if @md
504 txt_obj=if seg_link=~/sisu_manifest\.html/
505 man_link=if @file.output_dir_structure.by_language_code? \
506 or @file.output_dir_structure.by_filetype?
507 seg_link.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
508 else seg_link
509 end
510 { txt: man_link }
511 else { txt: seg_link }
512 end
513 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
514 toc={}
515 toc[:seg]=format_toc.lev4
516 toc[:seg_mini]=format_toc.mini_lev4
517 title=%{#{p_num.goto}#{linkname}</a>} if p_num
518 txt_obj=if title=~/sisu_manifest.html/
519 man_link=title.gsub(/sisu_manifest.html/,"../manifest/#{@file.base_filename.manifest}")
520 { txt: man_link }
521 else { txt: title }
522 end
523 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
524 toc[:scr]=format_toc.lev4
525 toc
526 #end
527 end
528 def level_5
529 dob=@data
530 linkname,ocn=dob.obj.strip,dob.ocn
531 toc={}
532 if ocn \
533 and ocn !~/#/
534 fnh={
535 fn: @@seg_url,
536 }
537 f=@md.file.base_filename.html_seg(fnh)
538 p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
539 lnk_n_txt=%{ <a href="#{f}##{@ocn_html_identifier}#{ocn}">
540 #{linkname}
541 </a>}
542 txt_obj={ txt: lnk_n_txt }
543 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
544 toc[:seg]=format_toc.lev5
545 toc[:seg_mini]=format_toc.mini_lev5
546 title=%{#{p_num.goto}#{linkname}</a>}
547 txt_obj={ txt: title }
548 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
549 toc[:scr]=format_toc.lev5
550 end
551 toc
552 end
553 def level_6
554 dob=@data
555 linkname,ocn=dob.obj.strip,dob.ocn
556 toc={}
557 if ocn \
558 and ocn !~/#/
559 fnh={
560 fn: @@seg_url,
561 }
562 f=@md.file.base_filename.html_seg(fnh)
563 p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
564 lnk_n_txt=%{ <a href="#{f}##{@ocn_html_identifier}#{ocn}">
565 #{linkname}
566 </a>}
567 txt_obj={ txt: lnk_n_txt }
568 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
569 toc[:seg]=format_toc.lev6
570 toc[:seg_mini]=format_toc.mini_lev6
571 title=%{#{p_num.goto}#{linkname}</a>}
572 txt_obj={ txt: title }
573 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
574 toc[:scr]=format_toc.lev6
575 end
576 toc
577 end
578 def level_crosslink
579 dob=@data
580 dob=if dob !~/^4~!/
581 dob.gsub(/^4~!\s+(\S+)\s+(.+)/,
582 %{<table><tr><td width =\"80\"></td>
583 <td><a href="http://\\1" target="_top">
584 #{@png.crosslink_ext}
585 &nbsp;&nbsp;\\2
586 <\/a>
587 </td></tr></table>
588 })
589 else
590 dob.gsub(/^4~!\s+(\S+)\s+(.+)/,
591 %{<table><tr><td width ="80">
592 </td><td>
593 <a href="\\1" target="_top">
594 #{@png.crosslink}
595 &nbsp;&nbsp;\\2
596 <\/a>
597 </td></tr></table>
598 })
599 end
600 end
601 end
602 class ScrollHeadAndSegToc < Toc
603 include SiSU_Parts_HTML
604 def initialize(md='',toc='',links_guide_toc='')
605 @md,@toc,@links_guide_toc=md,toc,links_guide_toc
606 @make=SiSU_Env::ProcessingSettings.new(@md)
607 end
608 def in_common
609 toc_shared=[]
610 @segtoc=[]
611 if (@md.opt.act[:verbose][:set]==:on \
612 || @md.opt.act[:verbose_plus][:set]==:on \
613 || @md.opt.act[:maintenance][:set]==:on)
614 SiSU_Screen::Ansi.new(
615 @md.opt.act[:color_state][:set],
616 'Scroll & Segtoc'
617 ).txt_grey
618 end
619 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
620 dochead=format_head_toc.head
621 dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge
622 toc_shared << dochead
623 @segtoc << format_head_toc.head
624 if @make.build.html_top_band?
625 toc_shared << format_head_toc.scroll_head_navigation_band
626 end
627 if defined? @md.rights.all
628 rights=format_head_toc.rights.all
629 rights=SiSU_HTML_Tune::CleanHTML.new(rights).clean
630 end
631 if @md.prefix_b
632 prefix_b=format_head_toc.notes.prefix_b
633 prefix_b=SiSU_HTML_Tune::CleanHTML.new(prefix_b).clean
634 end
635 if @make.build.html_top_band?
636 @segtoc << format_head_toc.seg_head_navigation_band
637 end
638 toc_shared << format_head_toc.scroll_head_title_banner_open
639 @segtoc << format_head_toc.seg_head_title_banner_open
640 tmp_head=nil
641 doc_title_endnote=@md.title.full.gsub(/(\*+)/,
642 '<sup><a href="#endnotes">\1</a></sup>')
643 tmp_head=doc_title_endnote + "\n"
644 txt_obj={ txt: tmp_head }
645 format_txt_obj=SiSU_HTML_Format::FormatTextObject.new(@md,txt_obj)
646 toc_shared << format_txt_obj.center_bold
647 @segtoc << format_txt_obj.center_bold
648 if defined? @md.creator.author
649 creator=SiSU_HTML_Tune::CleanHTML.new(@md.creator.author).clean_for_html
650 creator_endnote=creator.gsub(/(\*+)/,
651 %{&nbsp;<sup><a href="#notes">\\1</a></sup>})
652 tmp_head=creator_endnote + "\n"
653 txt_obj={ txt: tmp_head }
654 format_txt_obj=SiSU_HTML_Format::FormatTextObject.new(@md,txt_obj)
655 toc_shared << format_txt_obj.center_bold
656 @segtoc << format_txt_obj.center_bold
657 end
658 toc_shared << "#{the_table_close*1}\n"
659 @segtoc << "#{the_table_close*1}\n"
660 tmp_head=nil
661 if @md.prefix_a
662 tmp_head ||= %{<p>#{@md.prefix_a}\n}
663 toc_shared << tmp_head.dup
664 @segtoc << tmp_head.dup
665 end
666 tmp_head=nil
667 toc_shared << @links_guide_toc
668 if defined? @md.rights.all #and ? @md.rights.all
669 toc_shared << rights
670 end
671 if defined? @md.prefix_b
672 toc_shared << prefix_b
673 end
674 if @make.build.toc? #Table of Contents added/appended here
675 toc_shared << @toc[:scr]
676 end
677 @segtoc << @links_guide_toc
678 @segtoc << @toc[:seg]
679 if defined? @md.rights.all \
680 and not @md.rights.all.empty?
681 @segtoc << rights
682 end
683 @segtoc << prefix_b if @md.prefix_b
684 #Segtoc tail added here
685 @segtoc << "</p>\n" #bugfix sort later DEBUGNOW
686 @segtoc << @seg_toc_band_bottom
687 @segtoc << format_head_toc.seg_navigation_tail << format_head_toc.html_close
688 @segtoc=@segtoc.flatten.compact #watch
689 if @md.opt.act[:html_seg][:set]==:on
690 SiSU_HTML::Source::Output.new(@segtoc,@md).segtoc
691 end
692 @segtoc=[]
693 @toc[:scr],@toc[:seg]=[],[]
694 toc_shared
695 end
696 end
697 class Table < SiSU_HTML_Table::TableHTML
698 end
699 class Scroll < SiSU_HTML_Scroll::Scroll
700 end
701 class ScrollOutput
702 def initialize(scr_toc,scr_body,scr_metadata,scr_owner_details,scr_tails,md)
703 @scr_toc,@scr_body,@scr_metadata,@scr_owner_details,@scr_tails,@md=scr_toc,scr_body,scr_metadata,scr_owner_details,scr_tails,md
704 end
705 def publish
706 scroll=[]
707 scroll << @scr_toc << '<div class="scroll">' << @scr_body << @scr_endnotes << @scr_owner_details << '</div>' << @scr_tails
708 scroll=scroll.flatten.compact #watch
709 end
710 end
711 class Seg < SiSU_HTML_Seg::Seg
712 end
713 class Output
714 def initialize(data='',md='')
715 @data,@md=data,md
716 @file=SiSU_Env::FileOp.new(md)
717 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
718 end
719 def scroll
720 if @md.opt.act[:html_scroll][:set]==:on
721 begin
722 @filename_html_scroll=@file.write_file.html_scroll
723 @data.each do |para|
724 para=para.strip.
725 gsub(/<:.+?>/,'').
726 gsub(Xx[:html_relative2],@file.path_rel_links.html_scroll_2).
727 gsub(Xx[:html_relative1],@file.path_rel_links.html_scroll_1).
728 #gsub(/#{Xx[:html_relative]}/,@file.path_rel_links.html_scroll).
729 gsub(/#{Rx[:mx_fa_clean]}/,'')
730 unless para =~/\A\s*\Z/
731 @filename_html_scroll.puts para,"\n"
732 end
733 end
734 rescue
735 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
736 __LINE__.to_s + ':' + __FILE__
737 end
738 ensure
739 @filename_html_scroll.close
740 end
741 end
742 end
743 def segtoc
744 if @md.opt.act[:html_seg][:set]==:on
745 begin
746 @filename_html_segtoc=@file.write_file.html_segtoc
747 @data.each do |para|
748 para=para.strip.
749 gsub(/<!.+?!>/,'').
750 gsub(Xx[:html_relative2],@file.path_rel_links.html_seg_2).
751 gsub(Xx[:html_relative1],@file.path_rel_links.html_seg_1)
752 unless para =~/\A\s*\Z/
753 @filename_html_segtoc.puts para,"\n"
754 end
755 end
756 rescue
757 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
758 __LINE__.to_s + ':' + __FILE__
759 end
760 ensure
761 @filename_html_segtoc.close
762 pwd_set=Dir.pwd
763 idx_lnk=(@o_str.dump_or_redirect?) \
764 ? @file.base_filename.manifest
765 : @file.base_filename.html_segtoc
766 mlnk=@file.base_filename.html_seg_index
767 Dir.chdir(@file.output_path.html_seg.dir)
768 FileUtils::rm_f(mlnk)
769 FileUtils::ln_s(idx_lnk,mlnk)
770 Dir.chdir(pwd_set)
771 end
772 end
773 end
774 end
775 end
776 end
777 __END__