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