af9b9c3c0ca0f31ae8682a5b0f61f9bfd03879bb
[software/sisu] / lib / sisu / current / html_format.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html formating, css template
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/current/html_format.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_Format
58 require_relative 'html_parts' # html_parts.rb
59 class ParagraphNumber
60 def initialize(md,ocn)
61 @md,@ocn=md,ocn.to_s
62 @ocn ||=''
63 @ocn_html_identifier=SiSU_Env::ProcessingSettings.new(@md).ocn_html_identifier
64 @make=SiSU_Env::ProcessingSettings.new(@md)
65 end
66 def ocn_display
67 if @make.build.ocn?
68 if @ocn.to_i==0 \
69 or @ocn.empty?
70 ''
71 else
72 %{<label class="ocn">#{@ocn}</label>}
73 end
74 else
75 ''
76 end
77 end
78 def name
79 if @make.build.html_strict? \
80 or @ocn==(nil || @ocn.empty?)
81 ''
82 else
83 %{<a name="#{@ocn}"></a>}
84 end
85 end
86 def id #w3c? "tidy" complains about numbers as identifiers ! annoying
87 (@ocn==nil || @ocn.empty?) ? '' : %{id="#{Mx[:ocn_id_char]}#{@ocn}"}
88 end
89 def goto
90 (@ocn==nil || @ocn.empty?) ? '' : %{<a href="##{@ocn_html_identifier}#{@ocn}">}
91 end
92 end
93 class HeadInformation
94 require_relative 'css' # css.rb
95 include SiSU_Parts_HTML
96 require_relative 'xml_shared' # xml_shared.rb
97 attr_reader :md,:rdf
98 def initialize(md)
99 @md=md
100 # DublinCore 1 - title
101 @bits=SiSU_Proj_HTML::Bits.new
102 @seg_name_html=(SiSU_HTML::Source::Seg.new.seg_name_html || [])
103 @seg_name_html_tracker=(SiSU_HTML::Source::Seg.new.seg_name_html_tracker || [])
104 @tocband_scroll,@tocband_segtoc=nil,nil
105 @stylesheet=SiSU_Style::CSS_HeadInfo.new(md).stylesheet
106 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
107 @index,@metalink='index','#metadata'
108 @toc=@md.file.base_filename.html_segtoc
109 end
110 def url_path_image_sys
111 (@o_str.dump_or_redirect?) \
112 ? './image'
113 : "#{Xx[:html_relative2]}_sisu/image_sys"
114 end
115 def icon
116 def up
117 'arrow_up_red.png'
118 end
119 def next
120 'arrow_next_red.png'
121 end
122 def previous
123 'arrow_prev_red.png'
124 end
125 def dot_clear
126 'dot_clear.png'
127 end
128 def dot_white
129 'dot_white.png'
130 end
131 def dot
132 dot_white
133 end
134 self
135 end
136 def png_nav
137 def toc
138 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.up}" alt="toc" />}
139 end
140 def pre
141 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.previous}" alt="&lt;&lt;&nbsp;previous" />}
142 end
143 def nxt
144 %{<img border="0" width="22" height="22" src="#{url_path_image_sys}/#{icon.next}" alt="next&nbsp;&gt;&gt;" />}
145 end
146 def dot_toc
147 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&#094;" />}
148 end
149 def dot_pre
150 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&lt;" />}
151 end
152 def dot_nxt
153 %{<img border="0" width="100%" height="20" src="#{url_path_image_sys}/#{icon.dot}" alt="&gt;" />}
154 end
155 self
156 end
157 def doc_types(page=:seg) #used in toc & seg_nav_band
158 wgt=SiSU_HTML_Format::Widget.new(@md)
159 %{
160 <table summary="segment navigation available documents types: toc,doc,pdf,concordance" border="0" cellpadding="3" cellspacing="0">
161 <tr>
162 <td align="center" bgcolor=#{the_color.band2}>
163 #{wgt.manifest(page)}
164 #{wgt.search}
165 </tr></table>}
166 end
167 def rdf
168 SiSU_XML_Tags::RDF.new(md)
169 end
170 def button_home(page=:seg)
171 button=%{ <table summary="home button / home information" border="0" cellpadding="3" cellspacing="0">\n <tr><td align="left" bgcolor="#ffffff">\n}
172 if @md.make.home_button_image.is_a?(Hash)
173 image_path=if page==:manifest
174 @md.file.output_path.manifest.rel_image
175 elsif page==:scroll
176 @md.file.output_path.html_scroll.rel_image
177 else
178 @md.file.output_path.html_seg.rel_image
179 end
180 SiSU_Env::FileOp.new(@md)
181 button +=%{ <p class="tiny_left"><a href="#{@md.make.home_button_image[:link]}" target="_top"><img border="0" src="#{image_path}/#{@md.make.home_button_image[:home_button]}" width="#{@md.make.home_button_image[:w]}" height="#{@md.make.home_button_image[:h]}" alt="home icon --&gt;" /></a></p>\n}
182 elsif @md.home_button_links.is_a?(Array)
183 @md.home_button_links.each do |links|
184 button +=%{ <p class="tiny_left"><a href="#{links[:url]}" target="_top">\n #{links[:say]}\n </a></p>\n}
185 end
186 end
187 button +=%{ </td></tr>\n </table>}
188 button
189 end
190 def html_close #moved
191 %{</body>
192 </html>}
193 end
194 end
195 class Widget < HeadInformation
196 include SiSU_Parts_HTML
197 def initialize(md)
198 super(md)
199 @md=md
200 @cf_defaults=SiSU_Env::InfoProcessingFlag.new
201 @env=SiSU_Env::InfoEnv.new(md.fns)
202 @file=SiSU_Env::FileOp.new(md)
203 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
204 @make=SiSU_Env::ProcessingSettings.new(md)
205 end
206 def home
207 %{<td align="center" bgcolor=#{the_color.band2}>
208 <a href="../index.html" target="_top">
209 #{the_nav.txt_homepage}</a>
210 </td>
211 }
212 end
213 def scroll(text)
214 if @md.fns =~ /\.(?:-|ssm\.)?sst$/
215 %{<td align="center" bgcolor=#{the_color.band2}>
216 <a href="#{Xx[:html_relative1]}html/#{@file.base_filename.html_scroll}" target="_top">
217 #{text}
218 </a>
219 </td>
220 }
221 end
222 end
223 def seg(text)
224 %{<td align="center" bgcolor="#99CC66">
225 <a href="#{@md.file.base_filename.html_segtoc}" target="_top">
226 #{text}
227 </a>
228 </td>
229 }
230 end
231 def search
232 if @make.build.html_search_form?
233 env=SiSU_Env::InfoEnv.new(@md.fns,@md)
234 env.widget.search_form('sisusearch',nil,nil,true)
235 else ''
236 end
237 end
238 def manifest(page=:seg)
239 if @make.build.links_to_manifest? \
240 and not @o_str.dump_or_redirect?
241 manifest_lnk=if @file.output_dir_structure.by_language_code? \
242 or @file.output_dir_structure.by_filetype?
243 "#{Xx[:html_relative1]}manifest/#{@file.base_filename.manifest}"
244 else @file.base_filename.manifest
245 end
246 if page==:manifest
247 manifest_lnk="#{@md.file.output_path.manifest.url}/#{@file.base_filename.manifest}"
248 %{<td align="center" bgcolor=#{the_color.band2}>
249 <font face="#{the_font.set_fonts}" size="2">
250 #{the_url_decoration.xml_open}<a href="#{manifest_lnk}" target="_top">#{@md.file.output_path.manifest.url}/#{@file.base_filename.manifest}</a>#{the_url_decoration.xml_close}
251 </font>
252 </td>}
253 else
254 %{<td align="center" bgcolor=#{the_color.band2}>
255 <a href="#{manifest_lnk}" target="_top">
256 #{the_nav.txt_manifest}
257 </a>
258 </td>}
259 end
260 else ''
261 end
262 end
263 end
264 class XML
265 end
266 class HeadToc < HeadInformation
267 def initialize(md)
268 super(md)
269 @md=md
270 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
271 @make=SiSU_Env::ProcessingSettings.new(@md)
272 @file=SiSU_Env::FileOp.new(@md)
273 end
274 def scroll_head_navigation_band
275 if @make.build.html_top_band?
276 <<WOK
277 <td align="center" width="60%">
278 #{make_scroll_search_form_and_manifest_link}
279 </td>
280 WOK
281 %{<table summary="table of contents scroll navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
282 <tr><td width="20%">
283 #{button_home(:scroll)}
284 </td>
285 <td width="75%" align="center">
286 #{doc_types}
287 </td>
288 <td width="20%">
289 &nbsp;
290 #{the_table_close}
291 <p>}
292 else ''
293 end
294 end
295 def concordance_navigation_band
296 up_button=if @make.build.html_navigation?
297 %{</td>
298 <td width="5%" align="right">
299 &nbsp;<a href="toc.html" target="_top" alt="-&gt;">
300 #{png_nav.toc}
301 </a>&nbsp;
302 }
303 else ''
304 end
305 if @make.build.html_top_band?
306 %{<table summary="concordance navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
307 <tr><td width="20%">
308 #{button_home}
309 </td>
310 <td width="75%" align="center">
311 #{doc_types}
312 #{up_button}
313 #{the_table_close}
314 <p>}
315 else ''
316 end
317 end
318 def seg_head_navigation_band(page=:seg)
319 if @make.build.html_navigation?
320 if page==:manifest
321 nxt=(@file.output_dir_structure.by_language_code? \
322 || @file.output_dir_structure.by_filetype?) \
323 ? "../html/#{@md.fnb}/toc#{@md.lang_code_insert}#{Sfx[:html]}"
324 : "toc#{@md.lang_code_insert}#{Sfx[:html]}"
325 firstseg=%{<a href="#{nxt}" target="_top" alt="-&gt;">
326 #{png_nav.nxt}</a>}
327 elsif @md.firstseg =~/\S+/
328 firstseg=%{<a href="#{@md.firstseg}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top" alt="-&gt;">
329 #{png_nav.nxt}</a>}
330 end
331 else ''
332 end
333 if @make.build.html_top_band?
334 %{<table summary="table of contents segment navigation band" id="toc" width="100%" bgcolor=#{the_color.band1}>
335 <tr><td width="20%">
336 #{button_home(page)}
337 </td>
338 <td width="75%" align="center">
339 #{doc_types(page)}
340 </td>
341 <td width="5%" align="right">
342 &nbsp;#{firstseg}&nbsp;
343 #{the_table_close}
344 <p>}
345 else ''
346 end
347 end
348 def manifest_link(text)
349 # @file=SiSU_Env::FileOp.new(@md) if @md
350 %{<font size=2>
351 <a href="#{@md.file.base_filename.manifest}" target="_top">#{text}</a>
352 </font>}
353 end
354 def concordance_link(text)
355 if @md.concord_make
356 %{<font size=2>
357 <a href="#{@md.file.base_filename.html_concordance}" target="_top">
358 #{text}
359 </a>
360 </font>}
361 else ''
362 end
363 end
364 def make_scroll_search_form_and_manifest_link
365 wgt=SiSU_HTML_Format::Widget.new(@md)
366 %{<td align="center" bgcolor=#{the_color.band2}>
367 #{the_nav.txt_doc_link}
368 </td>
369 }
370 %{<table summary="toc segment and scroll with pdf" border="0" cellpadding="3" cellspacing="0">
371 <tr>
372 #{wgt.manifest}
373 #{wgt.search}
374 </tr></table>}
375 end
376 def make_scroll_seg_pdf
377 seg=''
378 wgt=SiSU_HTML_Format::Widget.new(@md)
379 seg=%{<td align="center" bgcolor=#{the_color.band2}>
380 #{the_nav.txt_toc_link}
381 </td>
382 }
383 %{<table summary="toc scroll and segment with pdf" border="0" cellpadding="3" cellspacing="0">
384 <tr>
385 <td align="center" bgcolor=#{the_color.band2}>
386 #{wgt.manifest}
387 #{wgt.search}
388 </tr></table>}
389 end
390 def make_concordance
391 wgt=SiSU_HTML_Format::Widget.new(@md)
392 %{<table summary="toc scroll and segment with pdf" border="0" cellpadding="3" cellspacing="0">
393 <tr>
394 <td align="center" bgcolor=#{the_color.band2}>
395 #{wgt.manifest}
396 #{wgt.search}
397 </tr></table>}
398 end
399 def head
400 rdf=SiSU_XML_Tags::RDF.new(@md)
401 %{<!DOCTYPE html>
402 <html>
403 <head>
404 <meta charset="utf-8">
405 <title>
406 #{@md.html_title}
407 </title>
408 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
409 #{rdf.metatag_html}
410 #{@stylesheet.css_head}
411 </head>
412 <body lang="#{@md.opt.lng}">
413 <a name="top" id="top"></a>}
414 end
415 def concordance
416 if @md.concord_make
417 %{#{the_margin.css}
418 <h4 class="toc">
419 <a href="./#{@md.file.base_filename.html_concordance}">
420 <i>Concordance</i>
421 </a>
422 </h4>
423 #{table_close}}
424 else
425 %{#{the_margin.css}
426 #{table_close}}
427 end
428 end
429 def links_guide_vertical_open
430 # @file=SiSU_Env::FileOp.new(@md) if @md
431 %{
432 <div id="vertical_links">
433 <ul id="vertical">
434 <li class="refbold">
435 <a href="#{the_url.home}">
436 #{the_text.txt_hp}
437 </a>
438 </li>
439 <li class="ref">
440 Quick Ref.:
441 </li>
442 <li class="ref">
443 <a href="#{@md.file.base_filename.manifest}" alt="Document Manifest" target="_top">
444 Manifest
445 </a>
446 </li>
447 <!- quick ref -!>}
448 end
449 def links_guide_horizontal_open
450 # @file=SiSU_Env::FileOp.new(@md) if @md
451 %{
452 <div id="horizontal_links">
453 <ul id="horizontal">
454 <li class="refbold">
455 <a href="#{the_url.home}">
456 #{the_text.txt_hp}
457 </a>
458 </li>
459 <li class="ref">
460 Quick Ref.:
461 </li>
462 <li class="ref">
463 <a href="#{@md.file.base_filename.manifest}" alt="Document Manifest" target="_top">
464 Manifest
465 </a>
466 </li>
467 <!- quick ref -!>}
468 end
469 def links_guide_open(type='horizontal')
470 (type=='vertical') \
471 ? links_guide_vertical_open
472 : links_guide_horizontal_open
473 end
474 def links_guide_close
475 insert=''
476 insert=if @md.sfx_src =~/s?/
477 link='http://sisudoc.org' #get from defaults
478 url='sisudoc.org'
479 name='SiSU electronic documents' #get from defaults
480 insert= %{
481 <li class="ref">
482 <a href="#{link}" alt="#{name}" target="_top">
483 #{url}
484 </a>
485 </li>
486 </ul>
487 </div>
488 }
489 end
490 %{ #{insert}
491 <!- quick ref -!>}
492 end
493 def prefix_a
494 end
495 def rights
496 def all
497 rights=SiSU_HTML_Tune::CleanHTML.new(@md.rights.all).clean_for_html
498 rights=rights.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
499 %{<p class="small_left">Rights: #{rights}</p>
500 <p>}
501 end
502 self
503 end
504 def prefix_b
505 %{<p class="small_left">Prefix: #{@md.prefix_b}<p />}
506 end
507 def scroll_head_title_banner_open
508 icon=@md.icon ? %{<center>\n#{@md.icon}\n</center>} : ''
509 %{#{icon}
510 #{the_banner.instrument_cover_band_scr}}
511 end
512 def seg_head_title_banner_open
513 icon=@md.icon ? %{<center>\n#{@md.icon}\n</center>} : ''
514 %{#{icon}
515 #{the_banner.instrument_cover_band_seg}}
516 end
517 def make_scroll
518 concord=concordance_link(the_nav.txt_concordance)
519 %{<table summary="toc scroll" border="0" cellpadding="3" cellspacing="0">
520 <tr><td align="center" bgcolor="white" border="0">
521 #{the_nav.txt_doc_link}
522 </td>
523 <td align="center" bgcolor="white">
524 #{concord}
525 #{the_table_close}}
526 end
527 def make_seg
528 concord=concordance_link(the_nav.txt_concordance)
529 %{<table summary="toc segment" border="0" cellpadding="3" cellspacing="0">
530 <tr><td align="center" bgcolor="white">
531 #{the_nav.txt_toc_link}
532 </td>
533 <td align="center" bgcolor="white">
534 <font size=2>
535 #{concord}
536 #{the_table_close}}
537 end
538 def manifest #check structure
539 if not @o_str.dump_or_redirect?
540 manifest=manifest_link(the_nav.txt_manifest)
541 %{#{the_margin.txt_3}
542 #{the_font.paragraph_font_small}
543 #{manifest}
544 </font>
545 #{the_table_close}}
546 else ''
547 end
548 end
549 def concordance #check structure
550 concord=concordance_link(the_nav.txt_concordance)
551 %{#{the_margin.txt_3}
552 #{the_font.paragraph_font_small}
553 #{concord}
554 </font>
555 #{the_table_close}}
556 end
557 def metadata
558 %{#{the_margin.css}
559 <h4 class="toc">
560 <a href="#{@metalink}">
561 <i>MetaData</i>
562 </a>
563 </h4>
564 #{the_table_close}}
565 end
566 def seg_tail
567 %{
568 <div class="main_column">
569 <p>&nbsp;<p>
570 <table summary="toc segment tail" bgcolor=#{the_color.band1}>
571 <tr><td width="20%">
572 #{the_banner.banner_band}
573 </td>
574 <td width="60%">
575 <center>
576 #{@tocband_segtoc}
577 </center>
578 </td></tr>
579 </table>
580 <p>&nbsp;</p>
581 #{@bits.credits_sisu}
582 <a name="bottom" id="bottom"></a>
583 <a name="end" id="end"></a>
584 </div>
585 </div>
586 </div>
587 }
588 end
589 def scroll_tail #debug
590 nav=scroll_head_navigation_band
591 %{
592 <div class="main_column">
593 #{nav}
594 #{@bits.credits_sisu}
595 <a name="bottom" id="bottom"></a>
596 <a name="end" id="end"></a>
597 </div>
598 }
599 end
600 def seg_navigation_tail #this is a bug area, look up and "tidy"
601 %{
602 <div class="main_column">
603 <p>&nbsp;</p>
604 #{@bits.credits_sisu}
605 <a name="bottom" id="bottom"></a>
606 <a name="end" id="end"></a>
607 </div>
608 </div>
609 </div>
610 }
611 end
612 end
613 class HeadSeg < HeadInformation
614 def initialize(md)
615 super(md)
616 end
617 def dot_control_pre_next
618 pre="#{@seg_name_html[@seg_name_html_tracker-1]}#{@md.lang_code_insert}#{Sfx[:html]}"
619 up=@toc
620 nxt="#{@seg_name_html[@seg_name_html_tracker+1]}#{@md.lang_code_insert}#{Sfx[:html]}"
621 if nxt=~/sisu_manifest\.html/
622 @file=SiSU_Env::FileOp.new(@md) if @md
623 if @file.output_dir_structure.by_language_code? \
624 or @file.output_dir_structure.by_filetype?
625 nxt=nxt.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
626 end
627 end
628 %{<table summary="segment hidden control pre and next" width="100%" border="0" cellpadding="0" bgcolor=#{the_color.grey_pale} align="center">
629 <tr><td align="left">
630 <a href="#{pre}" target="_top">
631 #{png_nav.dot_pre}
632 </a>
633 </td>
634 <td align="center">
635 <a href="#{up}" target="_top">
636 #{png_nav.dot_toc}
637 </a>
638 </td>
639 <td align="right">
640 <a href="#{nxt}" target="_top">
641 #{png_nav.dot_nxt}
642 </a>
643 #{the_table_close}}
644 end
645 def dot_control_pre
646 pre="#{@seg_name_html[@seg_name_html_tracker-2]}#{@md.lang_code_insert}#{Sfx[:html]}"
647 up=@toc
648 nxt="#{@md.file.base_filename.html_segtoc}"
649 %{<table summary="segment hidden control pre" width="100%" border="0" cellpadding="0" bgcolor=#{the_color.grey_pale} align="center">
650 <tr><td align="left">
651 <a href="#{pre}" target="_top">
652 #{png_nav.dot_pre}
653 </a>
654 </td>
655 <td align="center">
656 <a href="#{up}" target="_top">
657 #{png_nav.dot_toc}
658 </a>
659 </td>
660 <td align="right">
661 <a href="#{nxt}" target="_top">
662 #{png_nav.dot_nxt}
663 </a>
664 #{the_table_close}}
665 end
666 def toc_nav(f_pre=false,f_nxt=false,use=1)
667 pre=nxt=''
668 toc=%{<td align="center" bgcolor=#{the_color.band1}>
669 <a href="#{@toc}" target="_top">
670 #{png_nav.toc}
671 </a>
672 </td>}
673 pre=%{<td align="center" bgcolor=#{the_color.band1}>
674 <a href="#{@seg_name_html[@seg_name_html_tracker-use]}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top">
675 #{png_nav.pre}
676 </a>
677 </td>} if f_pre==true
678 nxt=%{<td align="center" bgcolor=#{the_color.band1}>
679 <a href="#{@seg_name_html[@seg_name_html_tracker+1]}#{@md.lang_code_insert}#{Sfx[:html]}" target="_top">
680 #{png_nav.nxt}
681 </a>
682 </td>} if f_nxt==true
683 if nxt =~/sisu_manifest.html/
684 @file=SiSU_Env::FileOp.new(@md) if @md
685 if @file.output_dir_structure.by_language_code? \
686 or @file.output_dir_structure.by_filetype?
687 nxt=nxt.gsub(/sisu_manifest\.html/,"../../manifest/#{@file.base_filename.manifest}")
688 end
689 end
690 %{<table summary="segment navigation pre/next" border="0" cellpadding="3" cellspacing="0">
691 <tr>
692 #{pre}
693 #{toc}
694 #{nxt}
695 <td>
696 #{the_table_close}}
697 end
698 def toc_next2
699 toc_nav(false,true).dup
700 end
701 def toc_pre_next2
702 toc_nav(true,true).dup
703 end
704 def toc_pre2
705 toc_nav(true,false,2).dup
706 end
707 def manifest_link(text)
708 %{<font size=2>
709 <a href="#{@md.file.base_filename.manifest}" target="_top">
710 #{text}
711 </a>
712 </font>}
713 end
714 def concordance_link(text)
715 if @md.concord_make
716 %{<font size=2>
717 <a href="#{@md.file.base_filename.html_concordance}" target="_top">
718 #{text}
719 </a>
720 </font>}
721 else ''
722 end
723 end
724 def navigation_table
725 %{<table summary="navigation segment table" width=#{the_width.table1} border="0" bgcolor="white" cellpadding="0">
726 <tr><th width="#{@@indent['leve_1']}" align="right">
727 </td>
728 <td valign="top">
729 <font size=2>}
730 end
731 def navigation_table1
732 %{<table summary="navigation segment table1" width=#{the_width.table1} border="0" cellpadding=#{the_table_cellpad_box} bgcolor=#{the_color.table1} align="left">
733 <tr><td valign="top">
734 <font size="2">}
735 end
736 def navigation_table2
737 %{<table summary="navigation segment table2" width=#{the_width.table2} border="0" cellpadding=#{the_table_cellpad_box} bgcolor=#{the_color.table2} align="left">
738 <tr><td valign="top">
739 <font size="2">}
740 end
741 def credit
742 %{
743 <div class="main_column">
744 #{@bits.credits_sisu}
745 <a name="bottom" id="bottom"></a>
746 <a name="end" id="end"></a>
747 </div></div>
748 }
749 end
750 def navigation_band(segtocband,seg_table_top_control) #change name to navigation_band_banner
751 %{<table summary="segment navigation band with banner" bgcolor=#{the_color.band1} width="100%"><tr>
752 <td width="20%" align="left">
753 #{button_home}
754 </td>
755 <td width="75%" align="center">
756 #{doc_types}
757 </td>
758 <td width="5%" align="right">
759 #{segtocband}
760 </td></tr>
761 </table>
762 #{seg_table_top_control}}
763 end
764 def navigation_band_bottom(segtocband,seg_table_top_control) #change name to navigation_band_bannerless
765 %{
766 <div class="main_column">
767 <table summary="segment navigation band" bgcolor=#{the_color.band1} width="100%"><tr>
768 <td width="70%" align="center">
769 #{doc_types}
770 </td>
771 <td width="5%" align="right">
772 #{segtocband}
773 </td></tr>
774 </table>
775 #{seg_table_top_control}
776 </div>
777 }
778 end
779 def endnote_mark
780 %{
781 <p class="center" id="endnotes">
782 <hr class="endnote" />
783 </p>}
784 end
785 def endnote_section_open
786 %{
787 <div class="endnote">
788 }
789 end
790 def endnote_section_close
791 %{
792 </div>
793 } #revisit
794 end
795 def head_seg
796 rdf=SiSU_XML_Tags::RDF.new(@md)
797 %{<!DOCTYPE html>
798 <html>
799 <head>
800 <meta charset="utf-8">
801 <title>
802 #{@seg_name_html[@seg_name_html_tracker]} -
803 #{@md.html_title}
804 </title>
805 <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
806 #{rdf.metatag_html}
807 #{@stylesheet.css_head_seg}
808 </head>
809 <body lang="#{@md.opt.lng}">
810 <a name="top" id="top"></a>}
811 end
812 def title_banner(title,subtitle,creator)
813 %{
814 <div class="summary">
815 <p class="tiny">
816 #{title}
817 </p>
818 <p class="tiny">
819 #{subtitle}
820 </p>
821 <p class="tiny">
822 #{creator}
823 </p>
824 <p class="tiny">
825 copy @
826 <a href="#{the_url.home}">
827 #{the_text.txt_home}
828 </a>
829 </p>
830 </div>
831 }
832 end
833 end
834 class HeadScroll < HeadToc
835 def initialize(md)
836 super(md)
837 end
838 def toc_owner_details
839 %{#{the_margin.txt_3}
840 #{the_font.paragraph_font_small}
841 <a href="#owner.details">
842 Owner Details
843 <font size="1" color="#777777">
844 &nbsp;&nbsp;&nbsp;
845 </font>
846 </a>
847 </font>
848 #{the_table_close}}
849 end
850 end
851 class FormatTextObject
852 include SiSU_Parts_HTML
853 attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url
854 def initialize(md,t_o)
855 @md,@t_o=md,t_o
856 @make=SiSU_Env::ProcessingSettings.new(@md)
857 if t_o.is_a?(Hash)
858 @txt =t_o[:txt] || nil
859 @ocn =t_o[:ocn] || nil
860 @ocn_display =t_o[:ocn_display] || nil
861 @headname =t_o[:headname] || nil
862 @trailer =t_o[:trailer] || nil
863 @endnote_part_a =t_o[:endnote_part_a] || nil
864 @endnote_part_b =t_o[:endnote_part_b] || nil
865 @lnk_url =t_o[:lnk_url] || nil
866 @lnk_txt =t_o[:lnk_txt] || nil
867 @format =t_o[:format] || nil
868 elsif t_o.class.inspect =~/^(?:#<)?SiSU_AO_DocumentStructure/
869 @dob=t_o if defined? t_o.is
870 @named=nametags_seg(@dob)
871 @txt=((defined? t_o.obj) ? t_o.obj : nil)
872 @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil)
873 @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil)
874 else
875 if @md.opt.act[:maintenance][:set]==:on
876 p t_o.class
877 p caller
878 end
879 end
880 @headnamed=(@headname ? %{<a id="h#{@headname}"></a>} : nil)
881 if @txt and not @txt.empty?
882 @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'')
883 end
884 @p_num=ParagraphNumber.new(@md,@ocn)
885 end
886 def nametags_scroll(dob)
887 tags=''
888 if defined? dob.tags \
889 and dob.tags.length > 0 # insert tags "hypertargets"
890 dob.tags.each do |t|
891 t=t.gsub(/[^a-z0-9._-]/,'') #use for all html tags? consider limiting to strict? or implementing earlier
892 tags=tags << %{<named id="#{t}" />}
893 end
894 end
895 tags
896 end
897 def nametags_seg(dob) #FIX
898 tags=''
899 if defined? dob.tags \
900 and dob.tags.length > 0 # insert tags "hypertargets"
901 dob.tags.each do |t|
902 t=t.gsub(/[^a-z0-9._-]/,'') #use for all html tags? consider limiting to strict? or implementing earlier
903 tags=(t =~/^[0-9.]+$/) \
904 ? tags #check what can be sorted in ao
905 : (tags << %{<a name="#{t}" ></a>})
906 end
907 end
908 tags
909 end
910 def headname #check whether used
911 hn=if @t_o.is ==:heading \
912 and not @t_o.name.empty? #determine use
913 hn=(@t_o.is ==:heading) \
914 ? (%{<a id="h#{@t_o.name}"></a>})
915 : (%{<a id="#{@t_o.name}"></a>})
916 else nil
917 end
918 hn
919 end
920 def endnote_body
921 %{
922 <p class="endnote">
923 #{@txt}
924 </p>
925 }
926 end
927 def endnote_body_indent
928 %{
929 <p class="endnote_indent">
930 #{@txt}
931 </p>
932 }
933 end
934 def no_paranum
935 %{
936 <div class="substance">
937 <label class="ocn">&nbsp;</label>
938 <p class="norm">
939 #{@txt}
940 </p>
941 </div>
942 }
943 end
944 def para_form_css(tag,attrib) # regular paragraphs shaped here
945 ul=ulc=''
946 if tag =~/li/
947 ul,ulc="<ul>\n ","\n </ul>"
948 end
949 %{
950 <div class="substance">
951 #{@p_num.ocn_display}
952 #{ul}<#{tag} class="#{attrib}" #{@p_num.id}>
953 #{@named}#{@txt}
954 </#{tag}>#{ulc}
955 </div>
956 }
957 end
958 def para
959 para_form_css('p','norm')
960 end
961 def block
962 para_form_css('p','block')
963 end
964 def group
965 para_form_css('p','group')
966 end
967 def alt
968 para_form_css('p','alt')
969 end
970 def verse
971 para_form_css('p','verse')
972 end
973 def code
974 para_form_css('p','code')
975 end
976 def center
977 para_form_css('p','center')
978 end
979 def bold
980 para_form_css('p','bold')
981 end
982 def bullet
983 para_form_css('li','bullet')
984 end
985 def table
986 @txt=if @t_o.obj !~/^<table\s/
987 table=SiSU_HTML_Shared::TableHTML.new(@t_o) #move, make happen earlier
988 @txt=table.table.obj
989 else @txt
990 end
991 para_form_css('p','norm')
992 end
993 def format(tag,attrib)
994 para_form_css(tag,attrib)
995 end
996 def heading_normal(tag,attrib)
997 section_break=(tag=~/h[1-5]/) \
998 ? '<br><hr width=90% /><br>'
999 : ''
1000 %{#{section_break}
1001 <div class="substance">
1002 #{@p_num.ocn_display}
1003 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name}
1004 #{@named}#{@txt}
1005 </#{tag}>
1006 </div>
1007 }
1008 end
1009 def heading_body
1010 heading_normal('p','norm')
1011 end
1012 def heading_body0
1013 heading_normal('h1','norm')
1014 end
1015 def heading_body1
1016 heading_normal('h1','norm')
1017 end
1018 def heading_body2
1019 heading_normal('h2','norm')
1020 end
1021 def heading_body3
1022 heading_normal('h3','norm')
1023 end
1024 def heading_body4
1025 heading_normal('h4','norm')
1026 end
1027 def heading_body5
1028 heading_normal('h5','norm')
1029 end
1030 def heading_body6
1031 heading_normal('h6','norm')
1032 end
1033 def heading_body7
1034 heading_normal('h7','norm')
1035 end
1036 def title_heading(tag,attrib)
1037 cl=(@make.build.html_minitoc?) \
1038 ? 'content'
1039 : 'content0'
1040 %{
1041 <div class="#{cl}">
1042 <#{tag} class="#{attrib}">
1043 #{@named}#{@txt}
1044 </#{tag}>
1045 </div>
1046 }
1047 end
1048 def title_heading0
1049 title_heading('h1','tiny')
1050 end
1051 def title_heading1
1052 title_heading('h1','tiny')
1053 end
1054 def title_heading2
1055 title_heading('h2','tiny')
1056 end
1057 def title_heading3
1058 title_heading('h3','tiny')
1059 end
1060 def title_heading4
1061 ''
1062 end
1063 def seg_heading_sub(tag,attrib)
1064 @txt=@txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1065 %{
1066 <div class="substance">
1067 #{@p_num.ocn_display}
1068 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} #{@headnamed}
1069 #{@named}#{@txt}
1070 </#{tag}>
1071 </div>
1072 }
1073 end
1074 def seg_heading4
1075 %{
1076 <div class="substance">
1077 #{@p_num.ocn_display}
1078 <h1 class="norm" #{@p_num.id}>#{@p_num.name}
1079 #{@txt}
1080 </h1>
1081 </div>
1082 }
1083 end
1084 def seg_heading5
1085 seg_heading_sub('p','bold')
1086 end
1087 def seg_heading6
1088 seg_heading_sub('p','bold')
1089 end
1090 def dl #check :trailer
1091 "<dl><b>#{@txt}</b> #{@trailer}</dl>"
1092 end
1093 def table_css_end
1094 '</table>
1095 </p>
1096 </div>'
1097 end
1098 def gsub_body #fix
1099 @txt=case @txt
1100 when /^\((i+|iv|v|vi+|ix|x|xi+)\)/
1101 @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'<b>(\1)</b>')
1102 when /^\(?(\d|[a-z])+\)/
1103 @txt.gsub(/^\((\d+|[a-z])+\)/,'<b>(\1)</b>')
1104 when /^\s*\d{1,3}\.\s/
1105 @txt.gsub(/^\s*(\d+\.)/,'<b>\1</b>')
1106 when /^\s*[A-Z]\.\s/
1107 @txt.gsub(/^\s*([A-Z]\.)/,'<b>\1</b>')
1108 else @txt
1109 end
1110 end
1111 def bold_para
1112 %{#{the_margin.txt_0}
1113 <p class="bold">
1114 #{@txt}
1115 </p>
1116 #{the_margin.num_css}
1117 &nbsp;&nbsp;&nbsp;
1118 #{the_table_close}}
1119 end
1120 def bold_heading
1121 %{<p class="bold">
1122 #{@txt}
1123 </p>
1124 #{the_margin.num_css}
1125 &nbsp;&nbsp;&nbsp;
1126 #{the_table_close}}
1127 end
1128 def toc_head_copy_at
1129 %{<p class="center">#{@txt}</p>\n}
1130 end
1131 def center
1132 %{<p class="center">#{@txt}</p>\n}
1133 end
1134 def bold
1135 %{<p class="bold">#{@txt}</p>\n}
1136 end
1137 def center_bold
1138 %{<p class="centerbold">#{@txt}</p>\n}
1139 end
1140 end
1141 class FormatScroll < FormatTextObject
1142 def initialize(md,txt)
1143 super(md,txt)
1144 end
1145 end
1146 class FormatSeg < FormatTextObject
1147 def initialize(md,txt)
1148 super(md,txt)
1149 end
1150 def endnote_seg_body(fn='')
1151 fn="../#{@md.fnb}" if fn.to_s.empty?
1152 %{
1153 <p class="endnote">
1154 #{@endnote_part_a}#{fn}#{@md.lang_code_insert}#{Sfx[:html]}#{@endnote_part_b}
1155 </p>
1156 }
1157 end
1158 def clean(txt)
1159 txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,'').
1160 gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'')
1161 end
1162 def subtoc_lev(tag,attrib)
1163 @txt=clean(@txt)
1164 @ocn_html_identifier=SiSU_Env::ProcessingSettings.new(@md).ocn_html_identifier
1165 txt=if @txt \
1166 and @txt =~/<\/?i>|<a\s+name="\S+?">/mi
1167 @txt.gsub(/<\/?i>|<a\s+name="\S+?">/mi,'') #removes name markers from subtoc, go directly to substantive text
1168 else @txt
1169 end
1170 note=''
1171 if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end
1172 note=$1
1173 note=note.gsub(/[\s]+/m,' ')
1174 txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ').
1175 gsub(/<a[\s]+name="-\d+"[\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
1176 end
1177 %{<#{tag} class="#{attrib}">
1178 <a href="##{@ocn_html_identifier}#{@ocn}"><i>#{txt}</i></a> #{note}
1179 </#{tag}>}
1180 end
1181 def subtoc_lev5
1182 subtoc_lev('h5','subtoc') if @txt
1183 end
1184 def subtoc_lev6
1185 subtoc_lev('h6','subtoc') if @txt
1186 end
1187 def subtoc_lev7
1188 subtoc_lev('h7','subtoc') if @txt
1189 end
1190 def heading_sub(tag,attrib)
1191 @txt=@txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1192 %{
1193 <div class="substance">
1194 #{@p_num.ocn_display}
1195 <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} #{@headnamed}
1196 #{@txt}
1197 </#{tag}>
1198 </div>
1199 }
1200 end
1201 def heading5
1202 heading_sub('p','bold')
1203 end
1204 def heading6
1205 heading_sub('p','bold')
1206 end
1207 def heading4
1208 %{
1209 <div class="substance">
1210 #{@p_num.ocn_display}
1211 <h1 class="norm" #{@p_num.id}>#{@p_num.name}
1212 #{@t_o[:format]}
1213 #{@txt}
1214 </h1>
1215 </div>
1216 }
1217 end
1218 def navigation_heading4
1219 %{<table summary="navigation segment heading 4" width=100% bgcolor="#08163f" border="0">
1220 <tr><td align="center">
1221 <p class="bold">
1222 #{@txt}
1223 </p>
1224 #{the_table_close}}
1225 end
1226 def navigation_heading5
1227 %{<p class="bold">
1228 #{@txt}
1229 </p>}
1230 end
1231 def navigation_heading6
1232 %{<p class="bold">
1233 #{@txt}
1234 </p>}
1235 end
1236 def navigation_center
1237 "<center>#{@txt}</center>"
1238 end
1239 end
1240 class FormatToc < FormatTextObject
1241 def initialize(md,txt)
1242 super(md,txt)
1243 end
1244 def links_guide
1245 %{ <li class="doc">
1246 <a href="#{@lnk_url}" target="_top">
1247 #{@lnk_txt}
1248 </a>
1249 </li>
1250 }
1251 end
1252 def lev(tag,attrib)
1253 if @txt
1254 %{<#{tag} class="#{attrib}">
1255 #{@txt}
1256 </#{tag}>
1257 }
1258 else ''
1259 end
1260 end
1261 def lev0 #docinfo
1262 lev('h1','toc')
1263 end
1264 def lev1
1265 lev('h1','toc')
1266 end
1267 def lev2
1268 lev('h2','toc')
1269 end
1270 def lev3
1271 lev('h3','toc')
1272 end
1273 def lev4
1274 lev('h4','toc')
1275 end
1276 def lev5
1277 lev('h5','toc')
1278 end
1279 def lev6
1280 lev('h6','toc')
1281 end
1282 def lev7
1283 lev('h7','toc')
1284 end
1285 def strip_endnotes(txt)
1286 txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
1287 txt
1288 end
1289 def mini_lev0
1290 @txt=strip_endnotes(@txt)
1291 lev('h1','minitoc')
1292 end
1293 def mini_lev1
1294 @txt=strip_endnotes(@txt)
1295 lev('h1','minitoc')
1296 end
1297 def mini_lev2
1298 @txt=strip_endnotes(@txt)
1299 lev('h2','minitoc')
1300 end
1301 def mini_lev3
1302 @txt=strip_endnotes(@txt)
1303 lev('h3','minitoc')
1304 end
1305 def mini_lev4
1306 @txt=strip_endnotes(@txt)
1307 lev('h4','minitoc')
1308 end
1309 def mini_lev5
1310 @txt=strip_endnotes(@txt)
1311 lev('h5','minitoc')
1312 end
1313 def mini_lev6
1314 @txt=strip_endnotes(@txt)
1315 lev('h6','minitoc')
1316 end
1317 def mini_lev7
1318 @txt=strip_endnotes(@txt)
1319 lev('h7','minitoc')
1320 end
1321 def mini_lev0 #docinfo
1322 lev('h1','minitoc')
1323 end
1324 def mini_tail
1325 %{
1326 <h4 class="minitoc">
1327 <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
1328 </h4>
1329 }
1330 end
1331 def mini_concord_tail
1332 %{
1333 <h4 class="minitoc">
1334 <a href="concordance.html">Concordance (wordlist)</a>
1335 </h4>
1336 <h4 class="minitoc">
1337 <a href="sisu_manifest.html">Manifest (alternative outputs)</a>
1338 </h4>
1339 }
1340 end
1341 end
1342 class FormatStr
1343 def initialize(md,str)
1344 @str=str
1345 end
1346 def center
1347 %{<p class="center">#{@str}</p>\n}
1348 end
1349 def bold
1350 %{<p class="bold">#{@str}</p>\n}
1351 end
1352 def center_bold
1353 %{<p class="centerbold">#{@str}</p>\n}
1354 end
1355 def endnote_body
1356 %{
1357 <p class="endnote">
1358 #{@str}
1359 </p>
1360 }
1361 end
1362 end
1363 end
1364 __END__