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