c&d: small fixes
[software/sisu] / lib / sisu / develop / shared_metadata.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** system environment, resource control and configuration details
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/shared_metadata.rb;hb=HEAD>
55
56 =end
57 module SiSU_Metadata
58 require_relative 'xml_parts' # xml_parts.rb
59 require_relative 'xml_shared' # xml_shared.rb
60 class Summary
61 include SiSU_Parts_XML
62 attr_accessor :tag,:inf,:class,:attrib
63 def initialize(md,display_heading=false)
64 @md,@display_heading=md,display_heading
65 @tag,@inf,@class,@attrib=nil
66 end
67 def metadata_base
68 meta=[]
69 l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
70 language=l[:n]
71 tr=SiSU_Translate::Source.new(@md,language)
72 @attrib='md'
73 def meta_content_clean(content='')
74 content=if not content.nil?
75 content=content.tr('"',"'").
76 gsub(/&/,'&amp;')
77 content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content)
78 else content
79 end
80 end
81 if @display_heading
82 @tag,@inf=%{<b><u>Document Metadata</u></b>},''
83 meta << self.meta_para
84 end
85 if defined? @md.title.full \
86 and @md.title.full=~/\S+/
87 @tag,@inf,@class=tr.full_title,@md.title.full,'dc' #1
88 meta << self.meta_para
89 end
90 if defined? @md.creator.author \
91 and @md.creator.author=~/\S+/
92 @tag,@inf,@class=tr.author,@md.creator.author,'dc' #2
93 meta << self.meta_para
94 end
95 if defined? @md.creator.translator \
96 and @md.creator.translator=~/\S+/
97 @tag,@inf,@class=tr.translator,@md.creator.translator,'ext'
98 meta << self.meta_para
99 end
100 if defined? @md.creator.illustrator \
101 and @md.creator.illustrator=~/\S+/
102 @tag,@inf,@class=tr.illustrator,@md.creator.illustrator,'ext'
103 meta << self.meta_para
104 end
105 if defined? @md.creator.prepared_by \
106 and @md.creator.prepared_by=~/\S+/
107 @tag,@inf,@class=tr.prepared_by,@md.creator.prepared_by,'ext'
108 meta << self.meta_para
109 end
110 if defined? @md.creator.digitized_by \
111 and @md.creator.digitized_by=~/\S+/
112 @tag,@inf,@class=tr.digitized_by,@md.creator.digitized_by,'ext'
113 meta << self.meta_para
114 end
115 if defined? @md.creator.contributor \
116 and @md.creator.contributor=~/\S+/
117 @tag,@inf,@class=tr.contributor,@md.creator.contributor,'dc' #6
118 meta << self.meta_para
119 end
120 if defined? @md.rights.all \
121 and @md.rights.all=~/\S+/
122 @tag,@inf,@class=tr.rights,meta_content_clean(@md.rights.all),'dc' #15
123 meta << self.meta_para
124 end
125 if defined? @md.classify.subject \
126 and @md.classify.subject=~/\S+/
127 @tag,@inf,@class=tr.subject,@md.classify.subject,'dc' #3
128 meta << self.meta_para
129 end
130 if defined? @md.classify.keywords \
131 and @md.classify.keywords=~/\S+/
132 @tag,@inf,@class=tr.keywords,@md.classify.keywords,'ext'
133 meta << self.meta_para
134 end
135 if defined? @md.classify.loc \
136 and @md.classify.loc=~/\S+/
137 @tag,@inf,@class=tr.cls_loc,@md.classify.loc,'id'
138 meta << self.meta_para
139 end
140 if defined? @md.classify.dewey \
141 and @md.classify.dewey=~/\S+/
142 @tag,@inf,@class=tr.cls_dewey,@md.classify.dewey,'id'
143 meta << self.meta_para
144 end
145 if defined? @md.publisher \
146 and @md.publisher=~/\S+/
147 @tag,@inf,@class=tr.publisher,@md.publisher,'dc' #5
148 meta << self.meta_para
149 end
150 if defined? @md.date.created \
151 and @md.date.created=~/\S+/
152 @tag,@inf,@class=tr.date_created,@md.date.created,'dc' #7
153 meta << self.meta_para
154 end
155 if defined? @md.date.issued \
156 and @md.date.issued=~/\S+/
157 @tag,@inf,@class=tr.date_issued,@md.date.issued,'dc' #7
158 meta << self.meta_para
159 end
160 if defined? @md.date.available \
161 and @md.date.available=~/\S+/
162 @tag,@inf,@class=tr.date_available,@md.date.available,'dc' #7
163 meta << self.meta_para
164 end
165 if defined? @md.date.modified \
166 and @md.date.modified=~/\S+/
167 @tag,@inf,@class=tr.date_modified,@md.date.modified,'dc' #7
168 meta << self.meta_para
169 end
170 if defined? @md.date.valid \
171 and @md.date.valid=~/\S+/
172 @tag,@inf,@class=tr.date_valid,@md.date.valid,'dc' #7
173 meta << self.meta_para
174 end
175 if defined? @md.date.published \
176 and @md.date.published=~/\S+/
177 @tag,@inf,@class=tr.date,@md.date.published,'dc' #7
178 meta << self.meta_para
179 end
180 if defined? @md.identifier.isbn \
181 and @md.identifier.isbn=~/\S+/
182 @tag,@inf,@class=tr.cls_isbn,@md.identifier.isbn,'id'
183 meta << self.meta_para
184 end
185 if defined? @md.identifier.oclc \
186 and @md.identifier.oclc=~/\S+/
187 @tag,@inf,@class=tr.cls_oclc,@md.identifier.oclc,'id'
188 meta << self.meta_para
189 end
190 if defined? @md.notes.description \
191 and @md.notes.description=~/\S+/
192 @tag,@inf,@class=tr.description,@md.notes.description,'dc' #4
193 meta << self.meta_para
194 end
195 if defined? @md.notes.abstract \
196 and @md.notes.abstract=~/\S+/
197 @tag,@inf,@class=tr.abstract,@md.notes.abstract,'ext'
198 meta << self.meta_para
199 end
200 if defined? @md.notes.comment \
201 and @md.notes.comment=~/\S+/
202 @tag,@inf,@class=tr.comments,@md.notes.comment,'ext'
203 meta << self.meta_para
204 end
205 if defined? @md.notes.coverage \
206 and @md.notes.coverage=~/\S+/
207 @tag,@inf,@class=tr.coverage,@md.notes.coverage,'dc' #14
208 meta << self.meta_para
209 end
210 if defined? @md.notes.relation \
211 and @md.notes.relation=~/\S+/
212 @tag,@inf,@class=tr.relation,@md.notes.relation,'dc' #13
213 meta << self.meta_para
214 end
215 #if defined? @md.notes.source \
216 #and @md.notes.source=~/\S+/
217 # @tag,@inf,@class=tr.source,@md.notes.source,'dc' #11
218 # meta << self.meta_para
219 #end
220 if defined? @md.notes.history \
221 and @md.notes.history=~/\S+/
222 @tag,@inf,@class=tr.type,@md.notes.history,'dc' #8
223 meta << self.meta_para
224 end
225 if defined? @md.notes.type \
226 and @md.notes.type=~/\S+/
227 @tag,@inf,@class=tr.type,@md.notes.type,'dc' #8
228 meta << self.meta_para
229 end
230 if defined? @md.notes.format \
231 and @md.notes.format=~/\S+/
232 @tag,@inf,@class=tr.format,@md.notes.format,'dc' #9
233 meta << self.meta_para
234 end
235 if defined? @md.notes.prefix_a \
236 and @md.notes.prefix_a=~/\S+/
237 @tag,@inf,@class=tr.prefix_a,@md.notes.prefix_a,'inf'
238 meta << self.meta_para
239 end
240 if defined? @md.notes.prefix_b \
241 and @md.notes.prefix_b=~/\S+/
242 @tag,@inf,@class=tr.prefix_b,@md.notes.prefix_b,'inf'
243 meta << self.meta_para
244 end
245 if defined? @md.original.source \
246 and @md.original.source=~/\S+/
247 @tag,@inf,@class=tr.source,@md.original.source,'dc' #11
248 meta << self.meta_para
249 end
250 if defined? @md.title.language \
251 and @md.title.language=~/\S+/
252 @tag,@inf,@class=tr.language,@md.title.language,'dc' #12
253 meta << self.meta_para
254 end
255 if defined? @md.original.language \
256 and @md.original.language=~/\S+/
257 @tag,@inf,@class=tr.language_original,@md.original.language,'ext'
258 meta << self.meta_para
259 end
260 if @display_heading
261 @tag,@inf=%{<b><u>Version Information</u></b>},''
262 meta << self.meta_para
263 end
264 if defined? @md.fns \
265 and @md.fns=~/\S+/
266 @tag,@inf,@class=tr.sourcefile,@md.fns,'src'
267 meta << self.meta_para
268 end
269 if defined? @md.file_encoding \
270 and @md.file_encoding=~/\S+/
271 @tag,@inf,@class='Filetype',@md.file_encoding,'src'
272 meta << self.meta_para
273 end
274 if defined? @md.dgst \
275 and @md.dgst.is_a?(Array)
276 @tag,@inf,@class='Source Digest',"#{@md.dgst[0]} #{@md.dgst[1]}",'src'
277 meta << self.meta_para
278 end
279 if @display_heading
280 @tag,@inf=%{<b><u>Generated</u></b>},''
281 meta << self.meta_para
282 end
283 if defined? @md.project_details \
284 and @md.project_details.version=~/\S+/
285 v="#{tr.sisu_version}: " +
286 "#{@md.project_details.project} " +
287 "#{@md.project_details.version} " +
288 "of #{@md.project_details.date_stamp} " +
289 "(#{@md.project_details.date})"
290 @tag,@inf,@class='Generated by',v,'ver'
291 meta << self.meta_para
292 end
293 if defined? @md.ruby_version \
294 and @md.ruby_version=~/\S+/
295 @tag,@inf,@class=tr.ruby_version,@md.ruby_version,'ver'
296 meta << self.meta_para
297 end
298 if defined? @md.generated \
299 and @md.generated.is_a?(Time)
300 @tag,@inf,@class=tr.last_generated,@md.generated,'date'
301 meta << self.meta_para
302 end
303 meta
304 end
305 def metadata_alt
306 meta=[]
307 if @display_heading
308 @tag,@inf=%{<b><u>Document Metadata</u></b>},''
309 meta << self.meta_para
310 end
311 if defined? @md.title.main \
312 and @md.title.main=~/\S+/
313 @tag='title'
314 @inf=@md.title.main
315 meta << self.meta_para
316 end
317 if defined? @md.title.sub \
318 and @md.title.sub=~/\S+/
319 @tag='subtitle'
320 @inf=@md.title.sub
321 meta << self.meta_para
322 end
323 if defined? @md.creator.author \
324 and @md.creator.author=~/\S+/
325 @tag='author'
326 @inf=@md.creator.author
327 meta << self.meta_para
328 end
329 if defined? @md.creator.translator \
330 and @md.creator.translator=~/\S+/
331 @tag='translator'
332 @inf=@md.creator.translator
333 meta << self.meta_para
334 end
335 if defined? @md.creator.illustrator \
336 and @md.creator.illustrator=~/\S+/
337 @tag='illustrator'
338 @inf=@md.creator.illustrator
339 meta << self.meta_para
340 end
341 if defined? @md.rights.copyright.text \
342 and @md.rights.copyright.text=~/\S+/
343 @tag='copyright'
344 @inf=@md.rights.copyright.text # year & holder
345 @inf=@inf.gsub(/(?:Copyright|\(C\))+\s*/,'')
346 meta << self.meta_para
347 end
348 if defined? @md.rights.license \
349 and @md.rights.license=~/\S+/
350 @tag='license'
351 @inf=@md.rights.license
352 meta << self.meta_para
353 end
354 meta
355 end
356 def processing_tags
357 def make
358 def language
359 if defined? @md.make.language \
360 and @md.make.language
361 ' :language: ' + @md.make.language.join(', ')
362 else nil
363 end
364 end
365 def headings
366 if defined? @md.make.headings \
367 and @md.make.headings
368 ' :headings: ' + @md.make.headings[0].join('; ')
369 else nil
370 end
371 end
372 def num_top
373 if defined? @md.make.num_top \
374 and @md.make.num_top
375 ' :num_top: ' + @md.make.num_top
376 else nil
377 end
378 end
379 def breaks
380 x=if defined? @md.make.breaks \
381 and @md.make.breaks
382 x=' :breaks:'
383 if @md.make.breaks[:page_break]
384 x +=' break=' + @md.make.breaks[:page_break] + ';'
385 end
386 if @md.make.breaks[:page_new]
387 x +=' new=' + @md.make.breaks[:page_new] + ';'
388 end
389 else nil
390 end
391 end
392 def emphasis
393 if defined? @md.make.emphasis \
394 and @md.make.emphasis
395 ' :emphasis: ' + @md.make.emphasis[:regx].inspect
396 else nil
397 end
398 end
399 def bold
400 if defined? @md.make.bold \
401 and @md.make.bold
402 ' :bold: ' + @md.make.bold[:regx].inspect
403 else nil
404 end
405 end
406 def italics
407 if defined? @md.make.italics \
408 and @md.make.italics
409 ' :italics: ' + @md.make.italics[:regx].inspect
410 else nil
411 end
412 end
413 def texpdf_font
414 if defined? @md.make.texpdf_font \
415 and @md.make.texpdf_font
416 ' :texpdf_font: ' + @md.make.texpdf_font.main
417 else nil
418 end
419 end
420 self
421 end
422 self
423 end
424 def metadata_tags
425 def title
426 def main
427 if defined? @md.title.main \
428 and @md.title.main
429 '@title: ' + @md.title.main
430 else '@title:'
431 end
432 end
433 def sub
434 if defined? @md.title.sub \
435 and @md.title.sub
436 ' :subtitle: ' + @md.title.sub
437 else nil
438 end
439 end
440 def edition
441 if defined? @md.title.edition \
442 and @md.title.edition
443 ' :edition: ' + @md.title.edition
444 else nil
445 end
446 end
447 def note
448 if defined? @md.title.note \
449 and @md.title.note
450 ' :note: ' + @md.title.note
451 else nil
452 end
453 end
454 def short
455 if defined? @md.title.short \
456 and @md.title.short
457 ' :short: ' + @md.title.short
458 else nil
459 end
460 end
461 def language
462 if defined? @md.title.language \
463 and @md.title.language
464 ' :language: ' + @md.title.language
465 else nil
466 end
467 end
468 def language_char
469 if defined? @md.title.language_char \
470 and @md.title.language_char
471 ' :language_char: ' + @md.title.language_char
472 else nil
473 end
474 end
475 self
476 end
477 def creator
478 def head
479 '@creator:'
480 end
481 def author
482 x=if defined? @md.creator.author_detail \
483 and @md.creator.author_detail
484 x=''
485 @md.creator.author_detail.each do |n|
486 x += "#{n[:the]}, #{n[:others]}; "
487 end
488 x=x.gsub(/;\s*$/,'')
489 ' :author: ' + x
490 else nil
491 end
492 end
493 def contributor
494 x=if defined? @md.creator.contributor_detail \
495 and @md.creator.contributor_detail
496 x=''
497 @md.creator.contributor_detail.each do |n|
498 x += "#{n[:the]}, #{n[:others]}; "
499 end
500 x=x.gsub(/;\s*$/,'')
501 ' :contributor: ' + x
502 else nil
503 end
504 end
505 def illustrator
506 x=if defined? @md.creator.illustrator_detail \
507 and @md.creator.illustrator_detail
508 x=''
509 @md.creator.illustrator_detail.each do |n|
510 x += "#{n[:the]}, #{n[:others]}; "
511 end
512 x=x.gsub(/;\s*$/,'')
513 ' :illustrator: ' + x
514 else nil
515 end
516 end
517 def photographer
518 x=if defined? @md.creator.photographer_detail \
519 and @md.creator.photographer_detail
520 x=''
521 @md.creator.photographer_detail.each do |n|
522 x += "#{n[:the]}, #{n[:others]}; "
523 end
524 x=x.gsub(/;\s*$/,'')
525 ' :photographer: ' + x
526 else nil
527 end
528 end
529 def translator
530 x=if defined? @md.creator.translator_detail \
531 and @md.creator.translator_detail
532 x=''
533 @md.creator.translator_detail.each do |n|
534 x += "#{n[:the]}, #{n[:others]}; "
535 end
536 x=x.gsub(/;\s*$/,'')
537 ' :translator: ' + x
538 else nil
539 end
540 end
541 def audio
542 x=if defined? @md.creator.audio_detail \
543 and @md.creator.audio_detail
544 x=''
545 @md.creator.audio_detail.each do |n|
546 x += "#{n[:the]}, #{n[:others]}; "
547 end
548 x=x.gsub(/;\s*$/,'')
549 ' :audio: ' + x
550 else nil
551 end
552 end
553 def digitized_by
554 x=if defined? @md.creator.digitized_by_detail \
555 and @md.creator.digitized_by_detail
556 x=''
557 @md.creator.digitized_by_detail.each do |n|
558 x += "#{n[:the]}, #{n[:others]}; "
559 end
560 x=x.gsub(/;\s*$/,'')
561 ' :digitized_by: ' + x
562 else nil
563 end
564 end
565 def prepared_by
566 x=if defined? @md.creator.prepared_by_detail \
567 and @md.creator.prepared_by_detail
568 x=''
569 @md.creator.prepared_by_detail.each do |n|
570 x += "#{n[:the]}, #{n[:others]}; "
571 end
572 x=x.gsub(/;\s*$/,'')
573 ' :prepared_by: ' + x
574 else nil
575 end
576 end
577 self
578 end
579 def rights
580 def head
581 '@rights:'
582 end
583 def copyright
584 def text
585 if defined? @md.rights.copyright.text \
586 and @md.rights.copyright.text
587 ' :copyright: ' + @md.rights.copyright.text
588 else nil
589 end
590 end
591 def translation
592 if defined? @md.rights.copyright.translation \
593 and @md.rights.copyright.translation
594 ' :translation: ' + @md.rights.copyright.translation
595 else nil
596 end
597 end
598 def illustrations
599 if defined? @md.rights.copyright.illustrations \
600 and @md.rights.copyright.illustrations
601 ' :illustrations: ' + @md.rights.copyright.illustrations
602 else nil
603 end
604 end
605 def photographs
606 if defined? @md.rights.copyright.photographs \
607 and @md.rights.copyright.photographs
608 ' :photographs: ' + @md.rights.copyright.photographs
609 else nil
610 end
611 end
612 def digitization
613 if defined? @md.rights.copyright.digitization \
614 and @md.rights.copyright.digitization
615 ' :digitization: ' + @md.rights.copyright.digitization
616 else nil
617 end
618 end
619 def audio
620 if defined? @md.rights.copyright.audio \
621 and @md.rights.copyright.audio
622 ' :audio: ' + @md.rights.copyright.audio
623 else nil
624 end
625 end
626 self
627 end
628 def license
629 if defined? @md.rights.license \
630 and @md.rights.license
631 ' :license: ' + @md.rights.license
632 else nil
633 end
634 end
635 self
636 end
637 def classify
638 def head
639 '@classify:'
640 end
641 def coverage
642 if defined? @md.classify.coverage \
643 and @md.classify.coverage
644 ' :coverage: ' + @md.classify.coverage
645 else nil
646 end
647 end
648 def relation
649 if defined? @md.classify.relation \
650 and @md.classify.relation
651 ' :relation: ' + @md.classify.relation
652 else nil
653 end
654 end
655 def subject
656 if defined? @md.classify.subject \
657 and @md.classify.subject
658 ' :subject: ' + @md.classify.subject
659 else nil
660 end
661 end
662 def topic_register
663 if defined? @md.classify.topic_register \
664 and @md.classify.topic_register
665 ' :topic_register: ' + @md.classify.topic_register
666 else nil
667 end
668 end
669 def type
670 # if defined? @md.classify.type \
671 # and @md.classify.type
672 # ' :type: ' + @md.classify.type
673 # else nil
674 # end
675 nil
676 end
677 def identifier
678 if defined? @md.classify.identifier \
679 and @md.classify.identifier
680 ' :identifier: ' + @md.classify.identifier
681 else nil
682 end
683 end
684 def loc
685 if defined? @md.classify.loc \
686 and @md.classify.loc
687 ' :loc: ' + @md.classify.loc
688 else nil
689 end
690 end
691 def dewey
692 if defined? @md.classify.dewey \
693 and @md.classify.dewey
694 ' :dewey: ' + @md.classify.dewey
695 else nil
696 end
697 end
698 def oclc
699 if defined? @md.classify.oclc \
700 and @md.classify.oclc
701 ' :oclc: ' + @md.classify.oclc
702 else nil
703 end
704 end
705 def pg
706 if defined? @md.classify.pg \
707 and @md.classify.pg
708 ' :pg: ' + @md.classify.pg
709 else nil
710 end
711 end
712 def isbn
713 if defined? @md.classify.isbn \
714 and @md.classify.isbn
715 ' :isbn: ' + @md.classify.isbn
716 else nil
717 end
718 end
719 self
720 end
721 def date
722 def head
723 '@date:'
724 end
725 def added_to_site
726 if defined? @md.date.added_to_site \
727 and @md.date.added_to_site
728 ' :added_to_site: ' + @md.date.added_to_site
729 else nil
730 end
731 end
732 def available
733 if defined? @md.date.available \
734 and @md.date.available
735 ' :available: ' + @md.date.available
736 else nil
737 end
738 end
739 def created
740 if defined? @md.date.created \
741 and @md.date.created
742 ' :created: ' + @md.date.created
743 else nil
744 end
745 end
746 def issued
747 if defined? @md.date.issued \
748 and @md.date.issued
749 ' :issued: ' + @md.date.issued
750 else nil
751 end
752 end
753 def modified
754 if defined? @md.date.modified \
755 and @md.date.modified
756 ' :modified: ' + @md.date.modified
757 else nil
758 end
759 end
760 def published
761 if defined? @md.date.published \
762 and @md.date.published
763 ' :published: ' + @md.date.published
764 else nil
765 end
766 end
767 def valid
768 if defined? @md.date.valid \
769 and @md.date.valid
770 ' :valid: ' + @md.date.valid
771 else nil
772 end
773 end
774 self
775 end
776 #def make
777 # def headings
778 # @md.make.headings \
779 # ? (' :headings: ' + @md.make.headings) \
780 # : nil
781 # end
782 #end
783 self
784 end
785 def char_enc(str)
786 @s=str
787 def amp
788 if @s \
789 and @s.is_a?(String)
790 @s=@s.gsub(/&/u,'&amp;')
791 end
792 @s
793 end
794 def br
795 if @s \
796 and @s.is_a?(String)
797 @s=@s.gsub(/(?:#{Mx[:br_line]}|\\\\)+/,'<br />')
798 end
799 @s
800 end
801 def utf8
802 if @s \
803 and @s.is_a?(String)
804 @s=@s.gsub(/<br(?: \/)?>/u,Mx[:br_paragraph]).
805 gsub(/</um,'&lt;').gsub(/>/um,'&gt;').
806 #gsub(/</um,'&#60;').gsub(/>/um,'&#62;').
807 gsub(/ /um,' '). # space identify
808 gsub(/ /um,' '). # space identify
809 gsub(/#{Mx[:br_paragraph]}/u,'<br />')
810 end
811 @s
812 end
813 self
814 end
815 def xml_docbook
816 def meta_para
817 inf_xml=char_enc(@inf).amp
818 inf_xml=char_enc(inf_xml).utf8
819 inf_xml=char_enc(inf_xml).br
820 <<WOK
821 #{Ax[:tab]}<#{@tag}>
822 #{Ax[:tab]*2}#{inf_xml}
823 #{Ax[:tab]}</#{@tag}>
824 WOK
825 end
826 def metadata
827 SiSU_Metadata::Summary.new(@md).metadata_alt
828 end
829 self
830 end
831 def html_display
832 def meta_para
833 inf_xml=char_enc(@inf).amp
834 inf_xml=char_enc(inf_xml).utf8
835 inf_xml=char_enc(inf_xml).br
836 %{<p class="norm">
837 <b>#{@tag}</b>: #{inf_xml}
838 </p>}
839 end
840 def metadata
841 SiSU_Metadata::Summary.new(@md,true).metadata_base
842 end
843 self
844 end
845 def xml_sax
846 def meta_para
847 inf_xml=char_enc(@inf).utf8
848 inf_xml=char_enc(inf_xml).br
849 <<WOK
850 <metadata>
851 #{Ax[:tab]}<meta>#{@tag.capitalize}:</meta>
852 #{Ax[:tab]}<data class="#{@attrib}">
853 #{Ax[:tab]*2}#{inf_xml}
854 #{Ax[:tab]}</data>
855 </metadata>
856 WOK
857 end
858 def metadata
859 SiSU_Metadata::Summary.new(@md).metadata_base
860 end
861 self
862 end
863 def xml_dom
864 def meta_para
865 inf_xml=char_enc(inf_xml).amp
866 inf_xml=char_enc(@inf).utf8
867 inf_xml=char_enc(inf_xml).br
868 <<WOK
869 #{Ax[:tab]}<header>
870 #{Ax[:tab]*2}<meta>#{@tag.capitalize}:</meta>
871 #{Ax[:tab]*2}<#{@attrib}>
872 #{Ax[:tab]*3}#{inf_xml}
873 #{Ax[:tab]*2}</#{@attrib}>
874 #{Ax[:tab]}</header>
875 WOK
876 end
877 def metadata
878 SiSU_Metadata::Summary.new(@md).metadata_base
879 end
880 self
881 end
882 def xhtml_scroll
883 def meta_para
884 inf_xml=char_enc(inf_xml).amp
885 inf_xml=char_enc(@inf).utf8
886 inf_xml=char_enc(inf_xml).br
887 <<WOK
888 #{Ax[:tab]}<metadata>
889 #{Ax[:tab]}<meta>#{@tag.capitalize}:</meta>
890 #{Ax[:tab]}<#{@attrib} class="#{@class}">
891 #{Ax[:tab]*2}#{inf_xml}
892 #{Ax[:tab]}</#{@attrib}>
893 #{Ax[:tab]}</metadata>
894 <br />
895 WOK
896 end
897 def metadata
898 SiSU_Metadata::Summary.new(@md).metadata_base
899 end
900 self
901 end
902 def xhtml_display
903 def meta_para
904 inf_xml=char_enc(@inf).amp
905 inf_xml=char_enc(inf_xml).utf8
906 inf_xml=char_enc(inf_xml).br
907 %{<p class="norm">
908 <b>#{@tag}</b>: #{inf_xml}
909 </p>}
910 end
911 def metadata
912 SiSU_Metadata::Summary.new(@md,true).metadata_base
913 end
914 self
915 end
916 def odf
917 def meta_para
918 if @inf.is_a?(String)
919 @inf=@inf.gsub(/</,'&lt;').gsub(/>/,'&gt;').
920 gsub(/&lt;br(?: \/)?&gt;/,'<br />')
921 if @inf =~/&/
922 inf_array=[]
923 word=@inf.scan(/\S+|\n/)
924 word.each do |w| # _ - / # | : ! ^ ~
925 w=w.gsub(/&nbsp;/,'&#160;')
926 if w !~/&\S{2,7}?;/
927 w=w.gsub(/&/,'&amp;')
928 end
929 inf_array << w
930 end
931 @inf=inf_array.join(' ')
932 end
933 @inf=@inf.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
934 '<text:a xl:type="simple" xl:href="\1">\1</text:a>'). #http ftp matches escaped, no decoration
935 gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
936 '\1<text:a xl:type="simple" xl:href="\2">\2</text:a>') #special case \{ e.g. \}http://url
937 @inf=if @inf =~/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/
938 @inf.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
939 %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{the_url_decoration.xml_close}}) #http ftp matches with decoration
940 else
941 @inf.gsub(/(https?:\/\/[^<>()'"\s]+)/,
942 %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{the_url_decoration.xml_close}}) #http ftp matches with decoration
943 end
944 @inf=@inf.gsub(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)/,
945 %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="mailto:\\1">\\1</text:a>#{the_url_decoration.xml_close}}) if @inf !~/http:\/\// # improve upon, document crash where url contains '@' symbol
946 end
947 <<WOK
948 <text:p text:style-name="P1">#{@tag.capitalize}: #{@inf}</text:p>
949 WOK
950 end
951 def metadata
952 SiSU_Metadata::Summary.new(@md).metadata_base
953 end
954 self
955 end
956 def plaintext
957 def meta_para
958 <<WOK
959
960 #{@tag.capitalize}: #{@inf}
961 WOK
962 end
963 def metadata
964 SiSU_Metadata::Summary.new(@md).metadata_base
965 end
966 self
967 end
968 def manpage
969 def meta_para
970 <<WOK
971
972 .TP
973 #{@tag.capitalize}:
974 .I #{@inf}
975 WOK
976 end
977 def metadata
978 SiSU_Metadata::Summary.new(@md).metadata_base
979 end
980 self
981 end
982 end
983 class TeX_Metadata
984 def initialize(md)
985 @md=md
986 @br="\\\\\n"
987 @make=SiSU_Env::ProcessingSettings.new(md)
988 @o_str ||=SiSU_Env::ProcessingSettings.new(md).output_dir_structure
989 end
990 def meta_para(tag,inf,sc=true)
991 inf=((inf.is_a?(String) && sc) ? spec_char(inf) : inf)
992 %{\\begin\{bfseries\}#{tag}:\\end\{bfseries\} #{inf}
993 }
994 end
995 def spec_char(inf)
996 SiSU_TeX_Pdf::SpecialCharacters.new(@md,inf).special_characters
997 end
998 def word_break_points(inf)
999 SiSU_TeX_Pdf::SpecialCharacters.new(@md,inf).special_word_break_points
1000 end
1001 def number_break_points(inf)
1002 SiSU_TeX_Pdf::SpecialCharacters.new(@md,inf).special_number_break_points
1003 end
1004 def metadata_tex
1005 meta=[]
1006 l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
1007 language=l[:n]
1008 tr=SiSU_Translate::Source.new(@md,language)
1009 if @make.build.links_to_manifest? \
1010 and not @o_str.dump_or_redirect?
1011 tag="Document Manifest @"
1012 inf="#{@br}#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}"
1013 meta << meta_para(tag,inf)
1014 end
1015 if defined? @md.title.full \
1016 and @md.title.full=~/\S+/
1017 tag,inf=tr.full_title,@md.title.full
1018 meta << meta_para(tag,inf)
1019 end
1020 if defined? @md.creator.author \
1021 and @md.creator.author=~/\S+/
1022 tag,inf=tr.author,@md.creator.author
1023 meta << meta_para(tag,inf)
1024 end
1025 if defined? @md.creator.translator \
1026 and @md.creator.translator=~/\S+/
1027 tag,inf=tr.translator,@md.creator.translator
1028 meta << meta_para(tag,inf)
1029 end
1030 if defined? @md.creator.illustrator \
1031 and @md.creator.illustrator=~/\S+/
1032 tag,inf=tr.illustrator,@md.creator.illustrator
1033 meta << meta_para(tag,inf)
1034 end
1035 if defined? @md.creator.prepared_by \
1036 and @md.creator.prepared_by=~/\S+/
1037 tag,inf=tr.prepared_by,@md.creator.prepared_by
1038 meta << meta_para(tag,inf)
1039 end
1040 if defined? @md.creator.digitized_by \
1041 and @md.creator.digitized_by=~/\S+/
1042 tag,inf=tr.digitized_by,@md.creator.digitized_by
1043 meta << meta_para(tag,inf)
1044 end
1045 if defined? @md.rights.all \
1046 and @md.rights.all=~/\S+/
1047 tag,inf=tr.rights,@md.rights.all
1048 meta << meta_para(tag,inf)
1049 end
1050 if defined? @md.notes.description \
1051 and @md.notes.description=~/\S+/
1052 tag,inf=tr.description,@md.notes.description
1053 meta << meta_para(tag,inf)
1054 end
1055 if defined? @md.classify.subject \
1056 and @md.classify.subject=~/\S+/
1057 tag,inf=tr.subject,@md.classify.subject
1058 meta << meta_para(tag,inf)
1059 end
1060 if defined? @md.publisher \
1061 and @md.publisher=~/\S+/
1062 tag,inf=tr.publisher,@md.publisher
1063 meta << meta_para(tag,inf)
1064 end
1065 if defined? @md.creator.contributor \
1066 and @md.creator.contributor=~/\S+/
1067 tag,inf=tr.contributor,@md.creator.contributor
1068 meta << meta_para(tag,inf)
1069 end
1070 if defined? @md.notes.abstract \
1071 and @md.notes.abstract=~/\S+/
1072 tag,inf=tr.abstract,@md.notes.abstract
1073 meta << meta_para(tag,inf)
1074 end
1075 if defined? @md.date.created \
1076 and @md.date.created=~/\S+/
1077 tag,inf=tr.date_created,@md.date.created
1078 meta << meta_para(tag,inf)
1079 end
1080 if defined? @md.date.issued \
1081 and @md.date.issued=~/\S+/
1082 tag,inf=tr.date_issued,@md.date.issued
1083 meta << meta_para(tag,inf)
1084 end
1085 if defined? @md.date.available \
1086 and @md.date.available=~/\S+/
1087 tag,inf=tr.date_available,@md.date.available
1088 meta << meta_para(tag,inf)
1089 end
1090 if defined? @md.date.modified \
1091 and @md.date.modified=~/\S+/
1092 tag,inf=tr.date_modified,@md.date.modified
1093 meta << meta_para(tag,inf)
1094 end
1095 if defined? @md.date.valid \
1096 and @md.date.valid=~/\S+/
1097 tag,inf=tr.date_valid,@md.date.valid
1098 meta << meta_para(tag,inf)
1099 end
1100 if defined? @md.date.published \
1101 and @md.date.published=~/\S+/
1102 tag,inf=tr.date,@md.date.published
1103 meta << meta_para(tag,inf)
1104 end
1105 if defined? @md.classify.topic_register \
1106 and @md.classify.topic_register=~/\S+/
1107 tag,inf=tr.topic_register,@md.classify.topic_register
1108 inf=word_break_points(inf)
1109 meta << meta_para(tag,inf)
1110 end
1111 if defined? @md.classify.loc \
1112 and @md.classify.loc=~/\S+/
1113 tag,inf=tr.cls_loc,@md.classify.loc
1114 meta << meta_para(tag,inf)
1115 end
1116 if defined? @md.classify.dewey \
1117 and @md.classify.dewey=~/\S+/
1118 tag,inf=tr.cls_dewey,@md.classify.dewey
1119 meta << meta_para(tag,inf)
1120 end
1121 if defined? @md.classify.oclc \
1122 and @md.classify.oclc=~/\S+/
1123 tag,inf=tr.cls_oclc,@md.classify.oclc
1124 meta << meta_para(tag,inf)
1125 end
1126 if defined? @md.classify.pg \
1127 and @md.classify.pg=~/\S+/
1128 tag,inf=tr.cls_gutenberg,@md.classify.pg
1129 meta << meta_para(tag,inf)
1130 end
1131 if defined? @md.classify.isbn \
1132 and @md.classify.isbn=~/\S+/
1133 tag,inf=tr.cls_isbn,@md.classify.isbn
1134 meta << meta_para(tag,inf)
1135 end
1136 if defined? @md.notes.comment \
1137 and @md.notes.comment=~/\S+/
1138 tag,inf=tr.comments,@md.notes.comment
1139 meta << meta_para(tag,inf)
1140 end
1141 if defined? @md.notes.prefix_a \
1142 and @md.notes.prefix_a=~/\S+/
1143 tag,inf=tr.prefix_a,@md.notes.prefix_a
1144 meta << meta_para(tag,inf)
1145 end
1146 if defined? @md.notes.prefix_b \
1147 and @md.notes.prefix_b=~/\S+/
1148 tag,inf=tr.prefix_b,@md.notes.prefix_b
1149 meta << meta_para(tag,inf)
1150 end
1151 if defined? @md.classify.identifier \
1152 and @md.classify.identifier=~/\S+/
1153 tag,inf=tr.identifier,@md.classify.identifier
1154 meta << meta_para(tag,inf)
1155 end
1156 if defined? @md.original.source \
1157 and @md.original.source=~/\S+/
1158 tag,inf=tr.source,@md.original.source
1159 meta << meta_para(tag,inf)
1160 end
1161 if defined? @md.title.language \
1162 and @md.title.language=~/\S+/
1163 tag,inf=tr.language,@md.title.language
1164 meta << meta_para(tag,inf)
1165 end
1166 if defined? @md.original.language \
1167 and @md.original.language=~/\S+/
1168 tag,inf=tr.language_original,@md.original.language
1169 meta << meta_para(tag,inf)
1170 end
1171 if defined? @md.classify.format \
1172 and @md.classify.format=~/\S+/
1173 tag,inf=tr.format,@md.classify.format
1174 meta << meta_para(tag,inf)
1175 end
1176 if defined? @md.classify.relation \
1177 and @md.classify.relation=~/\S+/
1178 tag,inf=tr.relation,@md.classify.relation
1179 meta << meta_para(tag,inf)
1180 end
1181 if defined? @md.classify.coverage \
1182 and @md.classify.coverage=~/\S+/
1183 tag,inf=tr.coverage,@md.classify.coverage
1184 meta << meta_para(tag,inf)
1185 end
1186 if defined? @md.classify.keywords \
1187 and @md.classify.keywords=~/\S+/
1188 tag,inf=tr.keywords,@md.classify.keywords
1189 meta << meta_para(tag,inf)
1190 end
1191 meta << %{#{@br}\\begin\{bfseries\}Version Information \\end\{bfseries\}}
1192 if defined? @md.fns \
1193 and @md.fns=~/\S+/
1194 fn=spec_char(@md.fns)
1195 fn=word_break_points(fn)
1196 fn="\\begin\{footnotesize\}#{fn}\\end\{footnotesize\}"
1197 tag,inf=tr.sourcefile,fn
1198 meta << meta_para(tag,inf,false)
1199 end
1200 if defined? @md.file_encoding \
1201 and @md.file_encoding=~/\S+/
1202 tag,inf='Filetype',@md.file_encoding
1203 meta << meta_para(tag,inf)
1204 end
1205 if defined? @md.dgst \
1206 and @md.dgst.is_a?(Array)
1207 hash_of=spec_char(@md.dgst[0])
1208 hash_of=word_break_points(hash_of)
1209 dgst=number_break_points(@md.dgst[1])
1210 tag,inf='Source Digest',"\\begin\{footnotesize\}#{hash_of}\\end\{footnotesize\}\\-\\begin\{scriptsize\}#{dgst}\\end\{scriptsize\}"
1211 meta << meta_para(tag,inf,false)
1212 end
1213 meta << %{#{@br}\\begin\{bfseries\}Generated \\end\{bfseries\}}
1214 if defined? @md.generated \
1215 and @md.generated.is_a?(Time)
1216 tag,inf=tr.last_generated,@md.generated
1217 meta << meta_para(tag,inf)
1218 end
1219 if defined? @md.project_details \
1220 and @md.project_details.version=~/\S+/
1221 tag=tr.sisu_version
1222 inf="#{@md.project_details.project} " +
1223 "#{@md.project_details.version} " +
1224 "of #{@md.project_details.date_stamp} " +
1225 "(#{@md.project_details.date})"
1226 meta << meta_para(tag,inf)
1227 end
1228 if defined? @md.ruby_version \
1229 and @md.ruby_version=~/\S+/
1230 tag,inf=tr.ruby_version,@md.ruby_version
1231 meta << meta_para(tag,inf)
1232 end
1233 meta
1234 end
1235 end
1236 end
1237 __END__
1238 if @md.title
1239 x=[
1240 @md.title.main,
1241 @md.title.sub,
1242 @md.title.edition,
1243 @md.title.note,
1244 @md.title.short,
1245 @md.title.full,
1246 @md.title.language,
1247 @md.title.language_char
1248 ]
1249 x.each {|y| p y if y}
1250 end
1251 if @md.creator
1252 x=[
1253 @md.creator.author,
1254 @md.creator.author_detail,
1255 @md.creator.contributor,
1256 @md.creator.contributor_detail,
1257 @md.creator.illustrator,
1258 @md.creator.illustrator_detail,
1259 @md.creator.photographer,
1260 @md.creator.photographer_detail,
1261 @md.creator.translator,
1262 @md.creator.translator_detail,
1263 @md.creator.audio,
1264 @md.creator.audio_detail,
1265 @md.creator.digitized_by,
1266 @md.creator.digitized_by_detail,
1267 @md.creator.prepared_by,
1268 @md.creator.prepared_by_detail
1269 ]
1270 x.each {|y| p y if y}
1271 end
1272 if @md.rights
1273 x=[
1274 @md.rights.copyright.text,
1275 @md.rights.copyright.translation,
1276 @md.rights.copyright.illustrations,
1277 @md.rights.copyright.photographs,
1278 @md.rights.copyright.digitization,
1279 @md.rights.copyright.audio,
1280 @md.rights.license,
1281 @md.rights.all
1282 ]
1283 x.each {|y| p y if y}
1284 end
1285 if @md.classify
1286 x=[
1287 @md.classify.coverage,
1288 @md.classify.relation,
1289 @md.classify.subject,
1290 @md.classify.topic_register,
1291 @md.classify.type,
1292 @md.classify.identifier,
1293 @md.classify.loc,
1294 @md.classify.dewey,
1295 @md.classify.oclc,
1296 @md.classify.pg,
1297 @md.classify.isbn,
1298 ]
1299 x.each {|y| p y if y}
1300 end
1301 if @md.date
1302 x=[
1303 @md.date.added_to_site,
1304 @md.date.available,
1305 @md.date.created,
1306 @md.date.issued,
1307 @md.date.modified,
1308 @md.date.published,
1309 @md.date.valid
1310 ]
1311 x.each {|y| p y if y}
1312 end
1313 #if @md.language
1314 # p @md.language.document
1315 # p @md.language.document_char
1316 # p @md.language.original
1317 # p @md.language.original_char
1318 #end
1319 if @md.make
1320 x=[
1321 @md.make.headings,
1322 @md.make.num_top,
1323 @md.make.breaks,
1324 @md.make.bold,
1325 @md.make.italics,
1326 @md.make.emphasis,
1327 @md.make.plaintext_wrap,
1328 @md.make.texpdf_font,
1329 @md.make.promo,
1330 @md.make.ad,
1331 @md.make.manpage
1332 ]
1333 x.each {|y| p y if y}
1334 end
1335 if @md.current_publisher # @md.publisher
1336 x=[
1337 @md.current_publisher
1338 ]
1339 x.each {|y| p y if y}
1340 end
1341 if @md.original
1342 x=[
1343 @md.original.publisher,
1344 @md.original.language,
1345 @md.original.language_char,
1346 @md.original.source,
1347 @md.original.institution,
1348 @md.original.nationality
1349 ]
1350 x.each {|y| p y if y}
1351 end
1352 if @md.notes
1353 x=[
1354 @md.notes.abstract,
1355 @md.notes.comment,
1356 @md.notes.description,
1357 @md.notes.history,
1358 @md.notes.prefix
1359 ]
1360 x.each {|y| p y if y}
1361 end