aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/se_processing.rb
blob: 9b96a9da1808089d41122887e0a808a8697b9708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#encoding: utf-8
#- Name: SiSU
#
#  - Description: documents, structuring, processing, publishing, search
#    se
#
#  - Author: Ralph Amissah
#    <ralph.amissah@gmail.com>
#
#  - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
#    2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019,
#    2020, 2021, Ralph Amissah,
#    All Rights Reserved.
#
#  - License: GPL 3 or later:
#
#    SiSU, a framework for document structuring, publishing and search
#
#    Copyright (C) Ralph Amissah
#
#    This program is free software: you can redistribute it and/or modify it
#    under the terms of the GNU General Public License as published by the Free
#    Software Foundation, either version 3 of the License, or (at your option)
#    any later version.
#
#    This program is distributed in the hope that it will be useful, but WITHOUT
#    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
#    more details.
#
#    You should have received a copy of the GNU General Public License along with
#    this program. If not, see <http://www.gnu.org/licenses/>.
#
#    If you have Internet connection, the latest version of the GPL should be
#    available at these locations:
#    <http://www.fsf.org/licensing/licenses/gpl.html>
#    <http://www.gnu.org/licenses/gpl.html>
#
#    <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
#
#  - SiSU uses:
#    - Standard SiSU markup syntax,
#    - Standard SiSU meta-markup syntax, and the
#    - Standard SiSU object citation numbering and system
#
#  - Homepages:
#    <http://www.sisudoc.org>
#
#  - Git
#    <https://git.sisudoc.org/projects/>
#    <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary>
#    <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary>
module SiSU_Processing_Settings
  require_relative 'constants'                             # constants.rb
  require_relative 'utils'                                 # utils.rb
  class ProcessingSettings
    def initialize(md)
      @md=md
    end
    def cnf_rc #sisurc.yml
      @rc=SiSU_Env::GetInit.new.sisu_yaml.rc
    end
    def env_rc #env rc (including sisurc.yml)
      @env_rc ||=SiSU_Env::InfoEnv.new(@md.fns)
    end
    def doc_rc #document rc, make instructions
      (defined? @md.make) \
      ? @md.make
      : nil
    end
    def cmd_rc_act #command-line rc
      @cmd_rc_act=@md.opt.opt_act
    end
    def build
      def ocn?
        if cmd_rc_act[:ocn][:set]==:on
          true
        elsif cmd_rc_act[:ocn][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.ocn? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.ocn? ==:off
          false
        else
          true
        end
      end
      def plaintext_ocn?
        if cmd_rc_act[:txt_ocn][:set]==:on \
        or cmd_rc_act[:ocn][:set]==:on
          true
        elsif cmd_rc_act[:txt_ocn][:set]==:off \
        or cmd_rc_act[:ocn][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.ocn? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.ocn? ==:off
          false
        else
          true
        end
      end
      def odt_ocn?
        if cmd_rc_act[:odt_ocn][:set]==:on \
        or cmd_rc_act[:ocn][:set]==:on
          true
        elsif cmd_rc_act[:odt_ocn][:set]==:off \
        or cmd_rc_act[:ocn][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.ocn? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.ocn? ==:off
          false
        else
          true
        end
      end
      def html_strict?
        if cmd_rc_act[:html_strict][:set]==:on
          true
        elsif cmd_rc_act[:html_strict][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_strict? \
        and doc_rc.html_strict? ==:on
          true
        else
          false
        end
      end
      def toc?
        if cmd_rc_act[:toc][:set]==:on
          true
        elsif cmd_rc_act[:toc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.toc? \
        and doc_rc.toc? ==:off
          false
        elsif env_rc.build.toc? ==:off
          false
        else
          true
        end
      end
      def manifest?
        if cmd_rc_act[:manifest][:set]==:on
          true
        elsif cmd_rc_act[:manifest][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.manifest? \
        and doc_rc.manifest? ==:off
          false
        elsif env_rc.build.manifest? ==:off
          false
        else
          true
        end
      end
      def links_to_manifest?
        if cmd_rc_act[:links_to_manifest][:set]==:on
          true
        elsif cmd_rc_act[:links_to_manifest][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.links_to_manifest? \
        and doc_rc.links_to_manifest? ==:off
          false
        elsif env_rc.build.links_to_manifest? ==:off
          false
        else
          true
        end
      end
      def metadata?
        if cmd_rc_act[:metadata][:set]==:on
          true
        elsif cmd_rc_act[:metadata][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.metadata? \
        and doc_rc.metadata? ==:off
          false
        elsif env_rc.build.metadata? ==:off
          false
        else
          true
        end
      end
      def minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.minitoc? \
        and doc_rc.minitoc? ==:off
          false
        elsif env_rc.build.minitoc? ==:off
          false
        else
          false
        end
      end
      def manifest_minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:manifest_minitoc][:set]==:on \
        || cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:manifest_minitoc][:set]==:off \
        || cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.manifest_minitoc? \
        and (doc_rc.manifest_minitoc? ==:off \
        || doc_rc.minitoc? ==:off)
          false
        elsif env_rc.build.manifest_minitoc? ==:off \
        || env_rc.build.minitoc? ==:off
          false
        elsif minitoc? == false
          false
        else
          false
        end
      end
      def html_minitoc?
        if html_top_band? == false #one form of navigation necessary
          true
        elsif cmd_rc_act[:html_minitoc][:set]==:on \
        || cmd_rc_act[:minitoc][:set]==:on
          true
        elsif cmd_rc_act[:html_minitoc][:set]==:off \
        || cmd_rc_act[:minitoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_minitoc? \
        and (doc_rc.html_minitoc? ==:off \
        || doc_rc.minitoc? ==:off)
          false
        elsif env_rc.build.html_minitoc? ==:off \
        || env_rc.build.minitoc? ==:off
          false
        elsif minitoc? == false
          false
        else
          false
        end
      end
      def html_top_band?
        if cmd_rc_act[:html_top_band][:set]==:on
          true
        elsif cmd_rc_act[:html_top_band][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_top_band? \
        and doc_rc.html_top_band? ==:off
          false
        elsif env_rc.build.html_top_band? ==:off
          false
        else
          true
        end
      end
      def html_navigation?
        if cmd_rc_act[:html_navigation][:set]==:on
          true
        elsif cmd_rc_act[:html_navigation][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_navigation? \
        and doc_rc.html_navigation? ==:off
          false
        elsif env_rc.build.html_navigation? ==:off
          false
        else
          true
        end
      end
      def html_navigation_bar?
        if cmd_rc_act[:html_navigation_bar][:set]==:on
          true
        elsif cmd_rc_act[:html_navigation_bar][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_navigation_bar? \
        and doc_rc.html_navigation_bar? ==:off
          false
        elsif env_rc.build.html_navigation_bar? ==:off
          false
        else
          false
        end
      end
      def search_form?
        if cmd_rc_act[:search_form][:set]==:on
          true
        elsif cmd_rc_act[:search_form][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_search_form? \
        and doc_rc.search_form? ==:off
          false
        elsif env_rc.build.search_form? ==:off
          false
        else
          true
        end
      end
      def html_search_form?
        if cmd_rc_act[:html_search_form][:set]==:on \
        || cmd_rc_act[:search_form][:set]==:on
          true
        elsif cmd_rc_act[:html_search_form][:set]==:off \
        || cmd_rc_act[:search_form][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_search_form? \
        and (doc_rc.html_search_form? ==:off \
        || doc_rc.search_form? ==:off)
          false
        elsif env_rc.build.html_search_form? ==:off \
        || env_rc.build.search_form? ==:off
          false
        elsif search_form? == false
          false
        else
          true
        end
      end
      def html_right_pane?
        if cmd_rc_act[:html_right_pane][:set]==:on
          true
        elsif cmd_rc_act[:html_right_pane][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.html_right_pane? \
        and doc_rc.html_right_pane? ==:off
          false
        elsif env_rc.build.html_right_pane? ==:off
          false
        else
          true
        end
      end
      def segsubtoc?
        if cmd_rc_act[:segsubtoc][:set]==:on
          true
        elsif cmd_rc_act[:segsubtoc][:set]==:off
          false
        elsif doc_rc.is_a?(Method) \
        and defined? doc_rc.segsubtoc? \
        and doc_rc.segsubtoc? ==:off
          false
        elsif env_rc.build.segsubtoc? ==:off
          false
        else
          true
        end
      end
      self
    end
    def ocn_html_identifier
      (build.html_strict?) \
      ? Mx[:ocn_id_char]
      : ''
    end
    def output_dir_structure
      def by_language_code?
        if cmd_rc_act[:output_by][:set] == :language
          true
        elsif cmd_rc_act[:output_by][:set] == :filetype \
        or cmd_rc_act[:output_by][:set] == :filename
          false
        elsif cmd_rc_act[:output_by][:set] == :language
          true
        else
          env_rc.output_dir_structure.by_language_code?
        end
      end
      def by_filetype?
        if cmd_rc_act[:output_by][:set] == :filetype
          true
        elsif cmd_rc_act[:output_by][:set] == :language \
        or cmd_rc_act[:output_by][:set] == :filename
          false
        elsif cmd_rc_act[:output_by][:set] == :filetype
          true
        else
          env_rc.output_dir_structure.by_filetype?
        end
      end
      def by_filename?
        if cmd_rc_act[:output_by][:set] == :filename
          true
        elsif cmd_rc_act[:output_by][:set] == :language \
        or cmd_rc_act[:output_by][:set] == :filetype
          false
        elsif cmd_rc_act[:output_by][:set] == :filename
          true
        else
          env_rc.output_dir_structure.by_filename?
        end
      end
      def multilingual?
        by_language_code?
      end
      def dump?
        ((cmd_rc_act[:dump][:bool] \
        &&  cmd_rc_act[:dump][:inst]) \
        || (env_rc.output_dir_structure.dump?)) \
        ? true
        : false
      end
      def redirect?
        ((cmd_rc_act[:redirect][:bool] \
        &&  cmd_rc_act[:redirect][:inst]) \
        || (env_rc.output_dir_structure.redirect?)) \
        ? true
        : false
      end
      def dump_or_redirect?
        ((dump?) || (redirect?)) \
        ? true
        : false
      end
      def by?
        if dump?
          :dump
        elsif redirect?
          :redirect
        elsif by_language_code?
          :language
        elsif by_filetype?
          :filetype
        elsif by_filename?
          :filename
        else #recheck current default
          :language
        end
      end
      self
    end
  end
end
module SiSU_Info_Processing_Flag
  class InfoProcessingFlag
    attr_accessor :color,:act_0,:act_1,:act_2,:act_3,:act_4,:act_5,:act_6,:act_7,:act_8,:act_9
    def initialize
      @rc=SiSU_Get_Init::GetInit.new.sisu_yaml.rc
    end
    def color                          #configurable processing flag shortcuts
      (defined? @rc['flag']['color']) \
      ? @rc['flag']['color']
      : false
    end
    def act_0                           #configurable processing flag shortcuts
      def default
        '--manifest --digest --qrcode --text --html --epub --concordance --pdf --odf --docbook --xhtml --xml-sax --xml-dom --sqlite --verbose'
      end
      def str
        if defined? @rc['flag']['act0'] \
        and @rc['flag']['act0'].is_a?(String)
          @rc['flag']['act0']
        elsif defined? @rc['flag']['default'] \
        and @rc['flag']['default'].is_a?(String)
          @rc['flag']['default']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_1                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html'
      end
      def str
        if defined? @rc['flag']['act1'] \
        and @rc['flag']['act1'].is_a?(String)
          @rc['flag']['act1']
        elsif defined? @rc['flag']['i'] \
        and @rc['flag']['i'].is_a?(String)
          @rc['flag']['i']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_2                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf'
      end
      def str
        if defined? @rc['flag']['act2'] \
        and @rc['flag']['act2'].is_a?(String)
          @rc['flag']['act2']
        elsif defined? @rc['flag']['ii'] \
        and @rc['flag']['ii'].is_a?(String)
          @rc['flag']['ii']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_3                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode'
      end
      def str
        if defined? @rc['flag']['act3'] \
        and @rc['flag']['act3'].is_a?(String)
          @rc['flag']['act3']
        elsif defined? @rc['flag']['iii'] \
        and @rc['flag']['iii'].is_a?(String)
          @rc['flag']['iii']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_4                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook'
      end
      def str
        if defined? @rc['flag']['act4'] \
        and @rc['flag']['act4'].is_a?(String)
          @rc['flag']['act4']
        elsif defined? @rc['flag']['iv'] \
        and @rc['flag']['iv'].is_a?(String)
          @rc['flag']['iv']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_5                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook --sqlite'
      end
      def str
        if defined? @rc['flag']['act5'] \
        and @rc['flag']['act5'].is_a?(String)
          @rc['flag']['act5']
        elsif defined? @rc['flag']['v'] \
        and @rc['flag']['v'].is_a?(String)
          @rc['flag']['v']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_6                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook --sqlite --xhtml --xml-sax --xml-dom'
      end
      def str
        if defined? @rc['flag']['act6'] \
        and @rc['flag']['act6'].is_a?(String)
          @rc['flag']['act6']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_7                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook --sqlite --xhtml --xml-sax --xml-dom --source --sisupod'
      end
      def str
        if defined? @rc['flag']['act7'] \
        and @rc['flag']['act7'].is_a?(String)
          @rc['flag']['act7']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_8                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook --xhtml --xml-sax --xml-dom --pg --update'
      end
      def str
        if defined? @rc['flag']['act8'] \
        and @rc['flag']['act8'].is_a?(String)
          @rc['flag']['act8']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_9                           #configurable processing flag shortcuts
      def default
        '--manifest --text --html --epub --pdf --concordance --qrcode --digest --odf --docbook --xhtml --xml-sax --xml-dom --pg --update --source --sisupod'
      end
      def str
        if defined? @rc['flag']['act9'] \
        and @rc['flag']['act9'].is_a?(String)
          @rc['flag']['act9']
        else default
        end
      end
      def arr
        str.scan(/\S+/)
      end
      self
    end
    def act_info
      puts 'current "act" settings:'
      acts=%w[ act_0 act_1 act_2 act_3 act_4 act_5 act_6 act_7 act_8 act_9 ]
      acts.each_with_index do |m,i|
        puts '--act-' + i.to_s + ' == ' \
        + send(m).str
      end
    end
  end
end
__END__