json, an output representation, first pass
[software/sisu] / lib / sisu / urls.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** urls for output files
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/urls.rb;hb=HEAD]
53
54 =end
55 module SiSU_Urls
56 require_relative 'se_hub_particulars' # se_hub_particulars.rb
57 include SiSU_Particulars
58 require_relative 'se' # se.rb
59 include SiSU_Env; include SiSU_Screen
60 class Source
61 attr_reader :opt
62 def initialize(opt)
63 @opt=opt
64 end
65 def read
66 begin
67 SiSU_Urls::OutputUrls.new(@opt).songsheet if @opt.fnb
68 rescue
69 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str).location do
70 __LINE__.to_s + ':' + __FILE__
71 end
72 ensure
73 end
74 end
75 end
76 class OutputUrls
77 attr_reader :fns,:fnb,:act,:dir,:m_regular,:u
78 def initialize(opt)
79 @opt=opt
80 @particulars=SiSU_Particulars::CombinedSingleton.instance.get_env_md(opt)
81 if @particulars.is_a?(NilClass)
82 if @opt.act[:verbose_plus][:set]==:on \
83 or @opt.act[:maintenance][:set]==:on
84 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
85 mark("@particulars is NilClass, acceptable e.g. for --harvest")
86 end
87 exit
88 end
89 @selections=@opt.selections.str
90 @act=@opt.act
91 @md=@particulars.md
92 @env=@particulars.env
93 @fnb=@env.fnb
94 fn_set_lang=SiSU_Env::StandardiseLanguage.new(@opt.lng).language
95 @fnl=@env.i18n.lang_filename(fn_set_lang[:c])
96 @fn=SiSU_Env::EnvCall.new(@opt.fns).lang(fn_set_lang[:c])
97 @m_regular=/(.+?)\.(?:(?:-|ssm\.)?sst|ssm)$/
98 @prog=@env.program
99 end
100 def songsheet
101 begin
102 (@opt.act[:urls_all][:set]==:on) \
103 ? urls_all \
104 : (urls_select unless @opt.act[:quiet][:set]==:on)
105 rescue
106 SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
107 __LINE__.to_s + ':' + __FILE__
108 end
109 ensure
110 end
111 end
112 def show
113 def report(x)
114 SiSU_Screen::Ansi.new(
115 @opt.act[:color_state][:set],
116 "[#{@opt.f_pth[:lng_is]}]",
117 x[:cmd],
118 x[:viewer] + ' ' \
119 + x[:f_pth]
120 ).result
121 end
122 def maintenance(x)
123 if @opt.act[:maintenance][:set]==:on
124 SiSU_Screen::Ansi.new(
125 @opt.act[:color_state][:set],
126 "[#{@opt.f_pth[:lng_is]}]",
127 x[:cmd],
128 x[:p_pth]
129 ).maintenance
130 end
131 end
132 self
133 end
134 def report_info
135 def dal
136 {
137 cmd: '--ao',
138 p_pth: @env.processing_path.ao + '/' \
139 + @opt.fns + '.meta',
140 fn: 'ao',
141 }
142 end
143 def hash_digests
144 {
145 cmd: '--hash-digests (sha512/sha256/md5)',
146 viewer: @prog.web_browser,
147 f_pth: @md.file.output_path.hash_digest.dir + '/' \
148 + @md.file.base_filename.hash_digest,
149 fn: @fn[:digest],
150 }
151 end
152 def text
153 def txt
154 {
155 cmd: '--txt',
156 viewer: @prog.web_browser,
157 f_pth: @md.file.output_path.txt.dir + '/' \
158 + @md.file.base_filename.txt,
159 fn: @fn[:plain],
160 }
161 end
162 def asciidoc
163 {
164 cmd: '--asciidoc',
165 viewer: @prog.web_browser,
166 f_pth: @md.file.output_path.asciidoc.dir + '/' \
167 + @md.file.base_filename.asciidoc,
168 fn: @fn[:txt_asciidoc],
169 }
170 end
171 def markdown
172 {
173 cmd: '--markdown',
174 viewer: @prog.web_browser,
175 f_pth: @md.file.output_path.markdown.dir + '/' \
176 + @md.file.base_filename.markdown,
177 fn: @fn[:txt_markdown],
178 }
179 end
180 def rst
181 {
182 cmd: '--rst',
183 viewer: @prog.web_browser,
184 f_pth: @md.file.output_path.rst.dir + '/' \
185 + @md.file.base_filename.rst,
186 fn: @fn[:txt_rst],
187 }
188 end
189 def textile
190 {
191 cmd: '--textile',
192 viewer: @prog.web_browser,
193 f_pth: @md.file.output_path.textile.dir + '/' \
194 + @md.file.base_filename.textile,
195 fn: @fn[:txt_textile],
196 }
197 end
198 def orgmode
199 {
200 cmd: '--orgmode',
201 viewer: @prog.web_browser,
202 f_pth: @md.file.output_path.orgmode.dir + '/' \
203 + @md.file.base_filename.orgmode,
204 fn: @fn[:txt_orgmode],
205 }
206 end
207 self
208 end
209 def html
210 def seg
211 {
212 cmd: '--html-seg',
213 viewer: @prog.web_browser,
214 f_pth: @md.file.output_path.html_seg.dir + '/' \
215 + @md.file.base_filename.html_segtoc,
216 p_pth: @env.processing_path.tune + '/' \
217 + @md.fns + '.tune',
218 fn: @fn[:toc],
219 }
220 end
221 def scroll
222 {
223 cmd: '--html-scroll',
224 viewer: @prog.web_browser,
225 f_pth: @md.file.output_path.html_scroll.dir + '/' \
226 + @md.file.base_filename.html_scroll,
227 p_pth: @env.processing_path.tune + '/' \
228 + @md.fns + '.tune',
229 fn: @fn[:doc],
230 }
231 end
232 def concordance
233 {
234 cmd: '--concordance',
235 viewer: @prog.web_browser,
236 f_pth: @md.file.output_path.html_concordance.dir + '/' \
237 + @md.file.base_filename.html_concordance,
238 fn: @fn[:concordance],
239 }
240 end
241 self
242 end
243 def xhtml
244 def xhtml
245 {
246 cmd: '--xhtml',
247 viewer: @prog.web_browser,
248 f_pth: @md.file.output_path.xhtml.dir + '/' \
249 + @md.file.base_filename.xhtml,
250 p_pth: @env.processing_path.tune + '/' \
251 + @md.fns + '.tune',
252 fn: @fn[:xhtml],
253 }
254 end
255 def epub
256 {
257 cmd: '--epub',
258 viewer: @prog.epub_viewer,
259 f_pth: @md.file.output_path.epub.dir + '/' \
260 + @md.file.base_filename.epub,
261 p_pth: @env.processing_path.epub + '/' \
262 + Ep[:d_oebps] + '/' \
263 + 'index.xhtml',
264 fn: @fn[:epub],
265 }
266 end
267 self
268 end
269 def xml
270 def odt
271 {
272 cmd: '--odt (ODF:ODT)',
273 viewer: @prog.odf_viewer,
274 f_pth: @md.file.output_path.odt.dir + '/' \
275 + @md.file.base_filename.odt,
276 p_pth: @env.processing_path.odf + '/' \
277 + @opt.fns + '/' \
278 + 'odt/content.xml',
279 fn: @fn[:odf],
280 }
281 end
282 def docbook
283 {
284 cmd: '--docbook',
285 viewer: @prog.web_browser,
286 f_pth: @md.file.output_path.xml_docbook_book.dir + '/' \
287 + @md.file.base_filename.xml_docbook_book,
288 fn: @fn[:xml_docbook_book],
289 }
290 end
291 def fictionbook
292 {
293 cmd: '--fictionbook',
294 viewer: @prog.web_browser,
295 f_pth: @md.file.output_path.xml_fictionbook.dir + '/' \
296 + @md.file.base_filename.xml_fictionbook,
297 fn: @fn[:xml_fictionbook],
298 }
299 end
300 def sax
301 {
302 cmd: '--xml-sax',
303 viewer: @prog.web_browser,
304 f_pth: @md.file.output_path.xml_sax.dir + '/' \
305 + @md.file.base_filename.xml_sax,
306 fn: @fn[:sax],
307 }
308 end
309 def dom
310 {
311 cmd: '--xml-dom',
312 viewer: @prog.web_browser,
313 f_pth: @md.file.output_path.xml_dom.dir + '/' \
314 + @md.file.base_filename.xml_dom,
315 fn: @fn[:dom],
316 }
317 end
318 def scaffold_sisu
319 {
320 cmd: '--xml-scaffold-sisu',
321 viewer: @prog.web_browser,
322 f_pth: @md.file.output_path.xml_scaffold_structure_sisu.dir + '/' \
323 + @md.file.base_filename.xml_scaffold_structure_sisu,
324 fn: @fn[:xml_scaffold_structure_sisu],
325 }
326 end
327 def scaffold_collapse
328 {
329 cmd: '--xml-scaffold-collapse',
330 viewer: @prog.web_browser,
331 f_pth: @md.file.output_path.xml_scaffold_structure_collapse.dir + '/' \
332 + @md.file.base_filename.xml_scaffold_structure_collapse,
333 fn: @fn[:xml_scaffold_structure_collapse],
334 }
335 end
336 self
337 end
338 def json
339 {
340 cmd: '--js (json)',
341 viewer: @prog.web_browser,
342 f_pth: @md.file.output_path.json.dir + '/' \
343 + @md.file.base_filename.json,
344 fn: @fn[:json],
345 }
346 end
347 def pdf
348 def landscape
349 {
350 cmd: '--pdf (landscape)',
351 viewer: @prog.pdf_viewer,
352 f_pth: @md.file.output_path.pdf.dir + '/' \
353 + @md.file.base_filename.pdf_l \
354 + @md.papersize_array[0] + '.pdf',
355 p_pth: @env.processing_path.tex + '/' \
356 + @opt.fns.gsub(/~/,'-') + '.' \
357 + @md.papersize_array[0] \
358 + '.landscape.tex',
359 fn: @fn[:pdf_l],
360 }
361 end
362 def portrait
363 {
364 cmd: '--pdf (portrait)',
365 viewer: @prog.pdf_viewer,
366 f_pth: @md.file.output_path.pdf.dir + '/' \
367 + @md.file.base_filename.pdf_p \
368 + @md.papersize_array[0] + '.pdf',
369 p_pth: @env.processing_path.tex + '/' \
370 + @opt.fns.gsub(/~/,'-') + '.' \
371 + @md.papersize_array[0] \
372 + '.tex',
373 fn: @fn[:pdf_p],
374 }
375 end
376 self
377 end
378 def manpage
379 {
380 cmd: '--manpage',
381 viewer: @prog.manpage_viewer,
382 f_pth: @md.file.output_path.manpage.dir + '/' \
383 + @md.file.base_filename.manpage,
384 fn: 'manpage',
385 }
386 end
387 def texinfo
388 {
389 cmd: '--texinfo',
390 viewer: '',
391 f_pth: 'cd ' \
392 + @md.file.output_path.texinfo.dir + ' && ' \
393 + @env.program.texinfo + ' ' \
394 + @md.file.base_filename.info \
395 + '; cd -',
396 fn: 'info',
397 }
398 end
399 def db
400 def psql
401 {
402 cmd: '--psql --update/--import',
403 viewer: '',
404 f_pth: @pwd_stub + '::' \
405 + @opt.fns \
406 + 'dbi psql',
407 p_pth: @env.processing_path.postgresql + '/' \
408 + @md.fns \
409 + '.sql',
410 fn: 'dbi psql',
411 }
412 end
413 def sqlite
414 {
415 cmd: '--sqlite --update/--import',
416 viewer: 'sqlite3 ',
417 f_pth: @env.path.webserv + '/' \
418 + @md.opt.f_pth[:pth_stub] + '/' \
419 + 'sisu_sqlite.db',
420 p_pth: @env.processing_path.sqlite + '/' \
421 + @md.fns \
422 + '.sql',
423 fn: 'dbi sqlite3',
424 }
425 end
426 def sqlite_discrete
427 {
428 cmd: '--sqlite',
429 viewer: 'sqlite3 ',
430 f_pth: @md.file.output_path.sqlite_discrete.dir + '/' \
431 + @md.file.base_filename.sqlite_discrete,
432 p_pth: @env.processing_path.sqlite + '/' \
433 + @md.fns \
434 + '.sql',
435 fn: 'dbi sqlite3',
436 }
437 end
438 self
439 end
440 def po4a
441 def po
442 {
443 cmd: '--po4a/--pot',
444 viewer: @prog.web_browser,
445 f_pth: @prog.text_editor + ' ' \
446 + @md.file.output_path.po.dir \
447 + '/' + y,
448 fn: @fn[:pot],
449 }
450 end
451 def pot
452 {
453 cmd: '--po4a/--pot',
454 viewer: @prog.web_browser,
455 f_pth: @prog.text_editor + ' ' \
456 + @md.file.output_path.pot.dir \
457 + '/' + y,
458 fn: @fn[:pot],
459 }
460 end
461 self
462 end
463 def source
464 {
465 cmd: '--source (sisu markup)',
466 viewer: @prog.text_editor,
467 f_pth: @md.file.output_path.src.dir + '/' \
468 + @opt.fno,
469 p_pth: @md.file.output_path.src.dir + '/' \
470 + @opt.fno,
471 fn: @opt.fno,
472 }
473 end
474 def sisupod
475 {
476 cmd: '--sisupod',
477 viewer: '',
478 f_pth: @md.file.output_path.sisupod.dir + '/' \
479 + @opt.fno \
480 + '.txz',
481 p_pth: @md.file.output_path.sisupod.dir + '/' \
482 + @opt.fno + '/' \
483 + 'sisupod/',
484 fn: @fn[:sisupod],
485 }
486 end
487 def ruby_profile
488 {
489 cmd: '--profile (ruby profiler)',
490 fn: 'profile',
491 }
492 end
493 def qrcode
494 {
495 cmd: '--qrcode',
496 viewer: @prog.web_browser,
497 f_pth: @md.file.output_path.manifest.dir + '/' \
498 + @md.file.base_filename.manifest,
499 fn: @fn[:qrcode],
500 }
501 end
502 def manifest
503 {
504 cmd: '--manifest',
505 viewer: @prog.web_browser,
506 f_pth: @md.file.output_path.manifest.dir + '/' \
507 + @md.file.base_filename.manifest,
508 fn: @fn[:manifest],
509 }
510 end
511 def sitemap
512 {
513 cmd: '--sitemap',
514 viewer: @prog.web_browser,
515 f_pth: @md.file.output_path.sitemaps.dir + '/' \
516 + @md.file.base_filename.sitemap,
517 fn: @fn[:sitemap],
518 }
519 end
520 self
521 end
522 def urls_select
523 unless @opt.act[:quiet][:set]==:on
524 i1='[' + @opt.f_pth[:lng_is] + ']'
525 i2='file://' \
526 + @md.file.output_path.manifest.dir + '/' \
527 + @md.file.base_filename.manifest
528 (@opt.act[:verbose][:set]==:on \
529 || @opt.act[:verbose_plus][:set]==:on \
530 || @opt.act[:maintenance][:set]==:on) \
531 ? SiSU_Screen::Ansi.new(
532 @opt.act[:color_state][:set],
533 'URLs'
534 ).green_title_hi
535 : SiSU_Screen::Ansi.new(
536 @opt.act[:color_state][:set],
537 'URL (output manifest)',
538 i1, i2
539 ).grey_title_grey_blue
540 if (@opt.act[:verbose][:set]==:on \
541 || @opt.act[:verbose_plus][:set]==:on \
542 || @opt.act[:maintenance][:set]==:on)
543 SiSU_Screen::Ansi.new(
544 @opt.act[:color_state][:set],
545 i1, i2,
546 ).flow
547 end
548 end
549 m=/.+\/(?:src\/)?(\S+)/im
550 @pwd_stub="#{@env.url.output_tell}"[m,1]
551 unless @opt.act[:quiet][:set]==:on
552 if @opt.fns =~ @m_regular
553 if (@opt.act[:verbose][:set]==:on \
554 || @opt.act[:verbose_plus][:set]==:on \
555 || @opt.act[:maintenance][:set]==:on)
556 if @opt.act[:txt][:set]==:on
557 show.report(report_info.text.txt)
558 #show.maintenance(report_info.text.txt)
559 end
560 if @opt.act[:txt_textile][:set]==:on
561 show.report(report_info.text.textile)
562 #show.maintenance(report_info.text.textile)
563 end
564 if @opt.act[:txt_asciidoc][:set]==:on
565 show.report(report_info.text.asciidoc)
566 #show.maintenance(report_info.text.asciidoc)
567 end
568 if @opt.act[:txt_markdown][:set]==:on
569 show.report(report_info.text.markdown)
570 #show.maintenance(report_info.text.markdown)
571 end
572 if @opt.act[:txt_rst][:set]==:on
573 show.report(report_info.text.rst)
574 #show.maintenance(report_info.text.rst)
575 end
576 if @opt.act[:txt_orgmode][:set]==:on
577 show.report(report_info.text.orgmode)
578 #show.maintenance(report_info.text.orgmode)
579 end
580 if (@opt.act[:html][:set]==:on \
581 or @opt.act[:html_scroll][:set]==:on \
582 or @opt.act[:html_seg][:set]==:on)
583 if @opt.act[:html_scroll][:set]==:on
584 show.report(report_info.html.scroll)
585 show.maintenance(report_info.html.scroll)
586 end
587 if @opt.act[:html_seg][:set]==:on
588 show.report(report_info.html.seg)
589 show.maintenance(report_info.html.seg)
590 end
591 end
592 if @opt.act[:concordance][:set]==:on
593 show.report(report_info.html.concordance)
594 #show.maintenance(report_info.html.concordance)
595 end
596 if @opt.act[:xhtml][:set]==:on
597 show.report(report_info.xhtml.xhtml)
598 show.maintenance(report_info.xhtml.xhtml)
599 end
600 if @opt.act[:epub][:set]==:on
601 show.report(report_info.xhtml.epub)
602 show.maintenance(report_info.xhtml.epub)
603 end
604 if @opt.act[:odt][:set]==:on
605 show.report(report_info.xml.odt)
606 show.maintenance(report_info.xml.odt)
607 end
608 if @opt.act[:xml_dom][:set]==:on
609 show.report(report_info.xml.dom)
610 #show.maintenance(report_info.xml.dom)
611 end
612 if @opt.act[:xml_sax][:set]==:on
613 show.report(report_info.xml.sax)
614 #show.maintenance(report_info.xml.sax)
615 end
616 if @opt.act[:xml_docbook_book][:set]==:on
617 show.report(report_info.xml.docbook)
618 #show.maintenance(report_info.xml.docbook)
619 end
620 if @opt.act[:xml_fictionbook][:set]==:on
621 show.report(report_info.xml.fictionbook)
622 #show.maintenance(report_info.xml.fictionbook)
623 end
624 if @opt.act[:xml_scaffold_structure_sisu][:set]==:on
625 show.report(report_info.xml.scaffold_structure_sisu)
626 #show.maintenance(report_info.xml.scaffold_structure_sisu)
627 end
628 if @opt.act[:xml_scaffold_structure_collapse][:set]==:on
629 show.report(report_info.xml.scaffold_collapse)
630 #show.maintenance(report_info.xml.scaffold_collapse)
631 end
632 if @opt.act[:json][:set]==:on
633 show.report(report_info.json)
634 #show.maintenance(report_info.json)
635 end
636 if (@opt.act[:pdf][:set]==:on \
637 or @opt.act[:pdf_p][:set]==:on \
638 or @opt.act[:pdf_l][:set]==:on)
639 if @opt.act[:pdf_p][:set]==:on
640 show.report(report_info.pdf.portrait)
641 show.maintenance(report_info.pdf.portrait)
642 end
643 if @opt.act[:pdf_l][:set]==:on
644 show.report(report_info.pdf.landscape)
645 show.maintenance(report_info.pdf.landscape)
646 end
647 end
648 if @opt.act[:psql][:set]==:on
649 show.report(report_info.db.psql)
650 show.maintenance(report_info.db.psql)
651 end
652 if @opt.act[:sqlite_discrete][:set]==:on
653 show.report(report_info.db.sqlite_discrete)
654 show.maintenance(report_info.db.sqlite_discrete)
655 end
656 if @opt.act[:sqlite][:set]==:on
657 show.report(report_info.db.sqlite)
658 show.maintenance(report_info.db.sqlite)
659 end
660 if @opt.act[:texinfo][:set]==:on
661 show.report(report_info.texinfo)
662 #show.maintenance(report_info.texinfo)
663 end
664 if @opt.act[:manpage][:set]==:on
665 show.report(report_info.manpage)
666 #show.maintenance(report_info.manpage)
667 end
668 if @opt.act[:hash_digests][:set]==:on
669 show.report(report_info.hash_digests)
670 #show.maintenance(report_info.hash_digests)
671 end
672 if @opt.act[:po4a_shelf][:set]==:on
673 #if @opt.fns =~/\S+?~\S{2}(?:_\S{2})?\.ss[mt]/
674 #else
675 #end
676 end
677 if @opt.act[:share_source][:set]==:on
678 show.report(report_info.source)
679 show.maintenance(report_info.source)
680 end
681 if @opt.act[:sisupod][:set]==:on
682 show.report(report_info.sisupod)
683 show.maintenance(report_info.sisupod)
684 end
685 if @opt.act[:qrcode][:set]==:on
686 show.report(report_info.qrcode)
687 #show.maintenance(report_info.qrcode)
688 end
689 if @opt.act[:manifest][:set]==:on
690 show.report(report_info.manifest)
691 show.maintenance(report_info.manifest)
692 end
693 end
694 end
695 end
696 end
697 def urls_all
698 i="(output manifest) [#{@opt.f_pth[:lng_is]}] #{@env.url.output_tell}/#{@fnb}/sisu_manifest.html"
699 SiSU_Screen::Ansi.new(
700 @opt.act[:color_state][:set],
701 'URLs',
702 i
703 ).grey_title_hi
704 end
705 end
706 end
707 __END__