Class: SiSU_Param_Make::MdMake

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/dp_make.rb

Direct Known Subclasses

SiSU_Param::Parameters::MdMake

Instance Method Summary collapse

Constructor Details

#initialize(str, opt, env) ⇒ MdMake

Returns a new instance of MdMake.



60
61
62
# File 'lib/sisu/dp_make.rb', line 60

def initialize(str,opt,env)
  @s,@opt,@env=str,opt,env
end

Instance Method Details

#adObject



392
393
394
# File 'lib/sisu/dp_make.rb', line 392

def ad
  @h['ad']
end

#append?Boolean

Returns:

  • (Boolean)


533
534
535
536
537
# File 'lib/sisu/dp_make.rb', line 533

def append?
  (@doc_links[0]=='+') \
    ? :yes
    : :no
end

#boldObject



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/sisu/dp_make.rb', line 186

def bold
  m=@h['bold']
  i=(m=~/\/i$/)? 'i' : ''
  if m
    x=m.gsub(/^\/(.+?)\/i?/,'\1').
      gsub(/\((?:\?:)?/,'(?:')                                         # avoid need to escape use of brackets within regex provided
    rgx='\b(' + x + ')\b'
    y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/))
    { str: '\b(?:' + x + ')\b', regx: y, i: i }
  else nil
  end
end

#breaksObject



166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/sisu/dp_make.rb', line 166

def breaks
  pagebreaks=((@h['breaks'] =~/;/) \
  ? (@h['breaks'].split(/;\s*/))
  : [ @h['breaks'] ])
  page_new,page_break,page_line=nil,nil,nil
  pagebreaks.each do |x|
    page_new=x[/(:?[\dA-C],?)+/] if x=~/new|clear/
    page_break=x[/(:?[\dA-C],?)+/] if x =~/break/
    page_line=x[/(:?[\dA-C],?)+/] if x =~/line/
  end
  { page_new: page_new, page_break: page_break, page_line: page_line }
end

#build_hash(arr) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/sisu/dp_make.rb', line 124

def build_hash(arr)
  @h={}
  arr.each_with_index do |x,i|
    a,b=nil,nil
    if x =~/^%[:\s]/ #ignore comment
    elsif x =~/:(\S+?):\s+(.+)/
      a,b=/:(\S+?):\s+(.+)\Z/m.match(x)[1,2]
    elsif i == 0
      a='main'
      b=x
    else
    end
    @h[a]=b
  end
  @h
end

#cjkObject



363
364
365
366
367
368
# File 'lib/sisu/dp_make.rb', line 363

def cjk
  @h['texpdf_font_cjk'] \
  && (@h['texpdf_font_cjk']=~/\S{3,}/) \
  ? @h['texpdf_font_cjk']
  : @env.font.texpdf.cjk
end

#cjk_jaObject



375
376
377
378
379
380
# File 'lib/sisu/dp_make.rb', line 375

def cjk_ja
  @h['texpdf_font_cjk_ja'] \
  && (@h['texpdf_font_cjk_ja']=~/\S{3,}/) \
  ? @h['texpdf_font_cjk_ja']
  : @env.font.texpdf.cjk_ja
end

#cjk_koObject



381
382
383
384
385
386
# File 'lib/sisu/dp_make.rb', line 381

def cjk_ko
  @h['texpdf_font_cjk_ko'] \
  && (@h['texpdf_font_cjk_ko']=~/\S{3,}/) \
  ? @h['texpdf_font_cjk_ko']
  : @env.font.texpdf.cjk_ko
end

#cjk_zhObject



369
370
371
372
373
374
# File 'lib/sisu/dp_make.rb', line 369

def cjk_zh
  @h['texpdf_font_cjk_zh'] \
  && (@h['texpdf_font_cjk_zh']=~/\S{3,}/) \
  ? @h['texpdf_font_cjk_zh']
  : @env.font.texpdf.cjk_zh
end

#cover_imageObject



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
# File 'lib/sisu/dp_make.rb', line 484

def cover_image
  s=nil
  if @h['cover_image']
    s=@h['cover_image'].split(/\s*;\s*/)
    s=s[0] #if
    image={}
    if s =~/{\s*(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?(?:\s+"(.+?)")?\s*}image/
      image[:cover]=$1
      if $2
        image[:dimensions]=$2
        image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2]
      else
        d=get_image_dimensions(image[:cover])
        image[:w],image[:h]=d[:w],d[:h]
        image[:dimensions]="#{d[:w]}x#{d[:h]}"
      end
      image[:note]=$3
    elsif s =~/(\S+\.(?:jpg|png|gif))/
      image[:cover]=$1
      d=get_image_dimensions(image[:cover])
      image[:w],image[:h]=d[:w],d[:h]
      image[:dimensions]="#{d[:w]}x#{d[:h]}"
      image[:note]=nil
    end
    image
  else nil
  end
end

#cover_image?Boolean

Returns:

  • (Boolean)


328
329
330
331
332
# File 'lib/sisu/dp_make.rb', line 328

def cover_image?
  (omit.list.inspect =~/"cover_image"/) \
  ? :off
  : :na
end

#emphasisObject



210
211
212
213
214
215
216
# File 'lib/sisu/dp_make.rb', line 210

def emphasis
  if @h['emphasis'] =~/bold/                   then 'bold'
  elsif @h['emphasis'] =~/italics?/            then 'italics'
  elsif @h['emphasis'] =~/under(?:line|score)/ then 'underscore'
  else nil
  end
end


512
513
514
515
516
517
# File 'lib/sisu/dp_make.rb', line 512

def footer
  if @h['footer']
    @h['footer'].split(/\s*;\s*/)
  else nil
  end
end

#get_image_dimensions(img) ⇒ Object



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
# File 'lib/sisu/dp_make.rb', line 427

def get_image_dimensions(img)
  imgk=SiSU_Env::SystemCall.new.imagemagick
  gmgk=SiSU_Env::SystemCall.new.graphicsmagick
  img_pth={
    sst: @env.path.image_source_include,
    pod: File.expand_path("../../../sisupod/image" )
  }
  path_img=if FileTest.file?("#{img_pth[:pod]}/#{img}")
    "#{img_pth[:pod]}/#{img}"
  elsif FileTest.file?("#{img_pth[:sst]}/#{img}")
    "#{img_pth[:sst]}/#{img}"
  else nil
  end
  if path_img
    if imgk or gmgk
      if imgk
        imgsys=`identify #{path_img}`.strip                           #system call
      elsif gmgk
        imgsys=`gm identify #{path_img}`.strip                        #system call
      end
      w,h=/(\d+)x(\d+)/m.match(imgsys)[1,2]
    else
      w,h='600','800'
    end
  else
    w,h=nil,nil
  end
  {w: w, h: h}
end

#headingsObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/sisu/dp_make.rb', line 143

def headings
  lv=[]
  x=@h['headings']
  x=((x =~/;/) ? (x.split(/;\s*/)) : [ x ])
  lv[0]=x
  lv0 ||='A~ '             #root level, single document apex, document title
  lv1=x[0] ||='B~ '
  lv[1]=/^#{lv1}/
  lv2=x[1] ||='C~ '
  lv[2]=/^#{lv2}/
  lv3=x[2] ||='D~ '
  lv[3]=/^#{lv3}/
  lv4=x[3] ||='1~ '
  lv[4]=/^#{lv4}/
  lv5=x[4] ||='2~ '
  lv[5]=/^#{lv5}/
  lv6=x[5] ||='3~ '
  lv[6]=/^#{lv6}/
  lv
end

#home_button_imageObject



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/sisu/dp_make.rb', line 462

def home_button_image
  s=nil
  s=if @h['home_button_image']
    s=@h['home_button_image'].split(/\s*;\s*/)
    s0=s[0] #if
    image={}
    s=if s0 =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s*}(?:(http:\/\/\S+)|image)/
      image[:home_button]=$1
      if $2
        image[:dimensions]=$2
        image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2]
      else
        d=get_image_dimensions(image[:home_button])
        image[:w],image[:h]=d[:w],d[:h]
        image[:dimensions]="#{d[:w]}x#{d[:h]}"
      end
      image[:link]=$3
      image
    end
  else nil
  end
end

#home_button_image?Boolean

Returns:

  • (Boolean)


333
334
335
336
337
# File 'lib/sisu/dp_make.rb', line 333

def home_button_image?
  (omit.list.inspect =~/"home_button_image"/) \
  ? :off
  : :na
end

#home_button_textObject



456
457
458
459
460
461
# File 'lib/sisu/dp_make.rb', line 456

def home_button_text
  if @h['home_button_text']
    @h['home_button_text'].split(/\s*;\s*/)
  else nil
  end
end

#html_minitoc?Boolean

Returns:

  • (Boolean)


283
284
285
286
287
# File 'lib/sisu/dp_make.rb', line 283

def html_minitoc?
  (omit.list.inspect =~/"html_minitoc"/) \
  ? :off
  : :na
end

#html_navigation?Boolean

Returns:

  • (Boolean)


293
294
295
296
297
# File 'lib/sisu/dp_make.rb', line 293

def html_navigation?
  (omit.list.inspect =~/"html_navigation"/) \
  ? :off
  : :na
end

#html_navigation_bar?Boolean

Returns:

  • (Boolean)


298
299
300
301
302
# File 'lib/sisu/dp_make.rb', line 298

def html_navigation_bar?
  (omit.list.inspect =~/"html_navigation_bar"/) \
  ? :off
  : :na
end

#html_right_pane?Boolean

Returns:

  • (Boolean)


318
319
320
321
322
# File 'lib/sisu/dp_make.rb', line 318

def html_right_pane?
  (omit.list.inspect =~/"html_right_column"|"html_right_pane"/) \
  ? :off
  : :na
end

#html_search_form?Boolean

Returns:

  • (Boolean)


313
314
315
316
317
# File 'lib/sisu/dp_make.rb', line 313

def html_search_form?
  (omit.list.inspect =~/"html_search_form"/) \
  ? :off
  : :na
end

#html_top_band?Boolean

Returns:

  • (Boolean)


288
289
290
291
292
# File 'lib/sisu/dp_make.rb', line 288

def html_top_band?
  (omit.list.inspect =~/"html_top_band"/) \
  ? :off
  : :na
end

#italicsObject



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/sisu/dp_make.rb', line 198

def italics
  m=@h['italics']
  i=((m=~/\/i$/) ? 'i' : '')
  if m
    x=m.gsub(/^\/(.+?)\/i?/,'\1').
      gsub(/\((?:\?:)?/,'(?:')                                         # avoid need to escape use of brackets within regex provided
    rgx='\b(' + x + ')\b'
    y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/))
    { str: '\b(?:' + x + ')\b', regx: y, i: i }
  else nil
  end
end

#languageObject



178
179
180
181
182
183
184
185
# File 'lib/sisu/dp_make.rb', line 178

def language
  if @h['language'] && (@h['language']=~/\S{2,}/)
    ((@h['language'] =~/,/) \
    ? (@h['language'].split(/,\s*/))
    : [ @h['language'] ])
  else [ 'en' ]
  end
end


522
523
524
525
526
527
528
529
530
531
532
# File 'lib/sisu/dp_make.rb', line 522

def links
  lnks,a_idx=[],0
  @doc_links.each do |doc_link|
    if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/
      say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2]
      lnks[a_idx]={ say: say, url: url  }
      a_idx +=1
    end
  end
  lnks
end

Returns:

  • (Boolean)


268
269
270
271
272
# File 'lib/sisu/dp_make.rb', line 268

def links_to_manifest?
  (omit.list.inspect =~/"manifest_links"|"links_to_manifest"/) \
  ? :off
  : :na
end

#listObject



248
249
250
# File 'lib/sisu/dp_make.rb', line 248

def list
  @m
end

#mainObject



339
340
341
342
343
344
# File 'lib/sisu/dp_make.rb', line 339

def main
  @h['texpdf_font'] \
  && (@h['texpdf_font']=~/\S{3,}/) \
  ? @h['texpdf_font']
  : @env.font.texpdf.main
end

#makeObject



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
# File 'lib/sisu/dp_make.rb', line 140

def make
  a=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
  @h=build_hash(a)
  def headings
    lv=[]
    x=@h['headings']
    x=((x =~/;/) ? (x.split(/;\s*/)) : [ x ])
    lv[0]=x
    lv0 ||='A~ '             #root level, single document apex, document title
    lv1=x[0] ||='B~ '
    lv[1]=/^#{lv1}/
    lv2=x[1] ||='C~ '
    lv[2]=/^#{lv2}/
    lv3=x[2] ||='D~ '
    lv[3]=/^#{lv3}/
    lv4=x[3] ||='1~ '
    lv[4]=/^#{lv4}/
    lv5=x[4] ||='2~ '
    lv[5]=/^#{lv5}/
    lv6=x[5] ||='3~ '
    lv[6]=/^#{lv6}/
    lv
  end
  def num_top
    @h['num_top']
  end
  def breaks
    pagebreaks=((@h['breaks'] =~/;/) \
    ? (@h['breaks'].split(/;\s*/))
    : [ @h['breaks'] ])
    page_new,page_break,page_line=nil,nil,nil
    pagebreaks.each do |x|
      page_new=x[/(:?[\dA-C],?)+/] if x=~/new|clear/
      page_break=x[/(:?[\dA-C],?)+/] if x =~/break/
      page_line=x[/(:?[\dA-C],?)+/] if x =~/line/
    end
    { page_new: page_new, page_break: page_break, page_line: page_line }
  end
  def language
    if @h['language'] && (@h['language']=~/\S{2,}/)
      ((@h['language'] =~/,/) \
      ? (@h['language'].split(/,\s*/))
      : [ @h['language'] ])
    else [ 'en' ]
    end
  end
  def bold
    m=@h['bold']
    i=(m=~/\/i$/)? 'i' : ''
    if m
      x=m.gsub(/^\/(.+?)\/i?/,'\1').
        gsub(/\((?:\?:)?/,'(?:')                                         # avoid need to escape use of brackets within regex provided
      rgx='\b(' + x + ')\b'
      y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/))
      { str: '\b(?:' + x + ')\b', regx: y, i: i }
    else nil
    end
  end
  def italics
    m=@h['italics']
    i=((m=~/\/i$/) ? 'i' : '')
    if m
      x=m.gsub(/^\/(.+?)\/i?/,'\1').
        gsub(/\((?:\?:)?/,'(?:')                                         # avoid need to escape use of brackets within regex provided
      rgx='\b(' + x + ')\b'
      y=((i =~/i/) ? (/#{rgx}/i) : (/#{rgx}/))
      { str: '\b(?:' + x + ')\b', regx: y, i: i }
    else nil
    end
  end
  def emphasis
    if @h['emphasis'] =~/bold/                   then 'bold'
    elsif @h['emphasis'] =~/italics?/            then 'italics'
    elsif @h['emphasis'] =~/under(?:line|score)/ then 'underscore'
    else nil
    end
  end
  def substitute
    m=@h['substitute']
    if m
      w=m.scan(/\/(.+?)\/(i?,)\s*'(.+?)'(?:\s+|\s*;\s*|$)/)
      arr_hash=[]
      matches=''
      w.each do |x|
        c=(x[1] =~/[i],/) ? :i : :s
        matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|'
        arr_hash << {
          match: x[0].gsub(/([${}])/,'\\\\\1'),
          replace: x[2],
          case_s: c
        }
      end
      matches.chop!
      { match_and_replace: arr_hash, matches: matches }
    else nil
    end
  end
  def plaintext_wrap
    if @h['plaintext_wrap'].to_s =~/\d\d+/ \
    and @h['plaintext_wrap'].to_i > 19 \
    and @h['plaintext_wrap'].to_i < 201
      @h['plaintext_wrap'].to_i
    else nil
    end
  end
  def omit
    m=@h['omit']
    @m=m ? (m.split(/,\s+/)) : nil
    def list
      @m
    end
    self
  end
  def ocn?
    (omit.list.inspect =~/"ocn"/) \
    ? :off
    : :na
  end
  def toc?
    (omit.list.inspect =~/"toc"/) \
    ? :off
    : :na
  end
  def manifest?
    (omit.list.inspect =~/"manifest"/) \
    ? :off
    : :na
  end
  def links_to_manifest?
    (omit.list.inspect =~/"manifest_links"|"links_to_manifest"/) \
    ? :off
    : :na
  end
  def metadata?
    (omit.list.inspect =~/"metadata"/) \
    ? :off
    : :na
  end
  def minitoc?
    (omit.list.inspect =~/"minitoc"/) \
    ? :off
    : :na
  end
  def html_minitoc?
    (omit.list.inspect =~/"html_minitoc"/) \
    ? :off
    : :na
  end
  def html_top_band?
    (omit.list.inspect =~/"html_top_band"/) \
    ? :off
    : :na
  end
  def html_navigation?
    (omit.list.inspect =~/"html_navigation"/) \
    ? :off
    : :na
  end
  def html_navigation_bar?
    (omit.list.inspect =~/"html_navigation_bar"/) \
    ? :off
    : :na
  end
  def segsubtoc?
    (omit.list.inspect =~/"segsubtoc"/) \
    ? :off
    : :na
  end
  def search_form?
    (omit.list.inspect =~/"search_form"/) \
    ? :off
    : :na
  end
  def html_search_form?
    (omit.list.inspect =~/"html_search_form"/) \
    ? :off
    : :na
  end
  def html_right_pane?
    (omit.list.inspect =~/"html_right_column"|"html_right_pane"/) \
    ? :off
    : :na
  end
  def manifest_minitoc?
    (omit.list.inspect =~/"manifest_minitoc"/) \
    ? :off
    : :na
  end
  def cover_image?
    (omit.list.inspect =~/"cover_image"/) \
    ? :off
    : :na
  end
  def home_button_image?
    (omit.list.inspect =~/"home_button_image"/) \
    ? :off
    : :na
  end
  def texpdf_font
    def main
      @h['texpdf_font'] \
      && (@h['texpdf_font']=~/\S{3,}/) \
      ? @h['texpdf_font']
      : @env.font.texpdf.main
    end
    def sans                                                             # not used
      @h['texpdf_font_sans'] \
      && (@h['texpdf_font_sans']=~/\S{3,}/) \
      ? @h['texpdf_font_sans']
      : @env.font.texpdf.sans
    end
    def serif                                                            # not used
      @h['texpdf_font_serif'] \
      && (@h['texpdf_font_serif']=~/\S{3,}/) \
      ? @h['texpdf_font_serif']
      : @env.font.texpdf.serif
    end
    def mono
      @h['texpdf_font_mono'] \
      && (@h['texpdf_font_mono']=~/\S{3,}/) \
      ? @h['texpdf_font_mono']
      : @env.font.texpdf.mono
    end
    def cjk
      @h['texpdf_font_cjk'] \
      && (@h['texpdf_font_cjk']=~/\S{3,}/) \
      ? @h['texpdf_font_cjk']
      : @env.font.texpdf.cjk
    end
    def cjk_zh
      @h['texpdf_font_cjk_zh'] \
      && (@h['texpdf_font_cjk_zh']=~/\S{3,}/) \
      ? @h['texpdf_font_cjk_zh']
      : @env.font.texpdf.cjk_zh
    end
    def cjk_ja
      @h['texpdf_font_cjk_ja'] \
      && (@h['texpdf_font_cjk_ja']=~/\S{3,}/) \
      ? @h['texpdf_font_cjk_ja']
      : @env.font.texpdf.cjk_ja
    end
    def cjk_ko
      @h['texpdf_font_cjk_ko'] \
      && (@h['texpdf_font_cjk_ko']=~/\S{3,}/) \
      ? @h['texpdf_font_cjk_ko']
      : @env.font.texpdf.cjk_ko
    end
    self
  end
  def promo
    @h['promo']
  end
  def ad
    @h['ad']
  end
  def manpage
    manpage={}
    if @h['manpage']
      if @h['manpage'] =~/;/m
        man=@h['manpage'].split(/;/m)
        man.each do |x|
          m=(x=~/=/m) ? x.split(/=/m) : nil
          if m
            manpage[m[0].strip] = m[1].split(/ \. /)
          end
        end
      end
    end
    if manpage['name']
      manpage['name']=manpage['name'].join("\n.br\n").
        gsub(/(-)/m,"\\\\\\1").
        gsub(/\A/,"\n.br\n.SH NAME\n.br\n")
    else
      manpage['name']='man page "name/whatis" information not provided, set in header @man: name=[whatis information]'
    end
    if manpage['synopsis']
      manpage['synopsis']=manpage['synopsis'].join("\n\n.br\n").
        gsub(/(-)/m,"\\\\\\1").
        gsub(/\A/,"\n.br\n.SH SYNOPSIS\n.br\n")
    else
      manpage['synopsis']=''
    end
    unless manpage['section']
      manpage['section']=1
    end
    manpage
  end
  def get_image_dimensions(img)
    imgk=SiSU_Env::SystemCall.new.imagemagick
    gmgk=SiSU_Env::SystemCall.new.graphicsmagick
    img_pth={
      sst: @env.path.image_source_include,
      pod: File.expand_path("../../../sisupod/image" )
    }
    path_img=if FileTest.file?("#{img_pth[:pod]}/#{img}")
      "#{img_pth[:pod]}/#{img}"
    elsif FileTest.file?("#{img_pth[:sst]}/#{img}")
      "#{img_pth[:sst]}/#{img}"
    else nil
    end
    if path_img
      if imgk or gmgk
        if imgk
          imgsys=`identify #{path_img}`.strip                           #system call
        elsif gmgk
          imgsys=`gm identify #{path_img}`.strip                        #system call
        end
        w,h=/(\d+)x(\d+)/m.match(imgsys)[1,2]
      else
        w,h='600','800'
      end
    else
      w,h=nil,nil
    end
    {w: w, h: h}
  end
  def home_button_text
    if @h['home_button_text']
      @h['home_button_text'].split(/\s*;\s*/)
    else nil
    end
  end
  def home_button_image
    s=nil
    s=if @h['home_button_image']
      s=@h['home_button_image'].split(/\s*;\s*/)
      s0=s[0] #if
      image={}
      s=if s0 =~/{(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?\s*}(?:(http:\/\/\S+)|image)/
        image[:home_button]=$1
        if $2
          image[:dimensions]=$2
          image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2]
        else
          d=get_image_dimensions(image[:home_button])
          image[:w],image[:h]=d[:w],d[:h]
          image[:dimensions]="#{d[:w]}x#{d[:h]}"
        end
        image[:link]=$3
        image
      end
    else nil
    end
  end
  def cover_image
    s=nil
    if @h['cover_image']
      s=@h['cover_image'].split(/\s*;\s*/)
      s=s[0] #if
      image={}
      if s =~/{\s*(\S+\.(?:jpg|png|gif))(?:\s+(\d+x\d+))?(?:\s+"(.+?)")?\s*}image/
        image[:cover]=$1
        if $2
          image[:dimensions]=$2
          image[:w],image[:h]=/(\d+)x(\d+)/m.match(image[:dimensions])[1,2]
        else
          d=get_image_dimensions(image[:cover])
          image[:w],image[:h]=d[:w],d[:h]
          image[:dimensions]="#{d[:w]}x#{d[:h]}"
        end
        image[:note]=$3
      elsif s =~/(\S+\.(?:jpg|png|gif))/
        image[:cover]=$1
        d=get_image_dimensions(image[:cover])
        image[:w],image[:h]=d[:w],d[:h]
        image[:dimensions]="#{d[:w]}x#{d[:h]}"
        image[:note]=nil
      end
      image
    else nil
    end
  end
  def footer
    if @h['footer']
      @h['footer'].split(/\s*;\s*/)
    else nil
    end
  end
  self
end


520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/sisu/dp_make.rb', line 520

def make_links
  @doc_links=@s.split(/\n%\s.+?$|[ ]*\n[ ]*/m)
  def links
    lnks,a_idx=[],0
    @doc_links.each do |doc_link|
      if doc_link=~/\{.+?\}(?:(?:https?|file|ftp):\/|\.\.)\/\S+(?:\s|$)/
        say,url=/\{\s*(.+?)\s*\}((?:(?:https?|file|ftp):\/|\.\.)\/\S+)/im.match(doc_link)[1,2]
        lnks[a_idx]={ say: say, url: url  }
        a_idx +=1
      end
    end
    lnks
  end
  def append?
    (@doc_links[0]=='+') \
      ? :yes
      : :no
  end
  self
end

#manifest?Boolean

Returns:

  • (Boolean)


263
264
265
266
267
# File 'lib/sisu/dp_make.rb', line 263

def manifest?
  (omit.list.inspect =~/"manifest"/) \
  ? :off
  : :na
end

#manifest_minitoc?Boolean

Returns:

  • (Boolean)


323
324
325
326
327
# File 'lib/sisu/dp_make.rb', line 323

def manifest_minitoc?
  (omit.list.inspect =~/"manifest_minitoc"/) \
  ? :off
  : :na
end

#manpageObject



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
# File 'lib/sisu/dp_make.rb', line 395

def manpage
  manpage={}
  if @h['manpage']
    if @h['manpage'] =~/;/m
      man=@h['manpage'].split(/;/m)
      man.each do |x|
        m=(x=~/=/m) ? x.split(/=/m) : nil
        if m
          manpage[m[0].strip] = m[1].split(/ \. /)
        end
      end
    end
  end
  if manpage['name']
    manpage['name']=manpage['name'].join("\n.br\n").
      gsub(/(-)/m,"\\\\\\1").
      gsub(/\A/,"\n.br\n.SH NAME\n.br\n")
  else
    manpage['name']='man page "name/whatis" information not provided, set in header @man: name=[whatis information]'
  end
  if manpage['synopsis']
    manpage['synopsis']=manpage['synopsis'].join("\n\n.br\n").
      gsub(/(-)/m,"\\\\\\1").
      gsub(/\A/,"\n.br\n.SH SYNOPSIS\n.br\n")
  else
    manpage['synopsis']=''
  end
  unless manpage['section']
    manpage['section']=1
  end
  manpage
end

#metadata?Boolean

Returns:

  • (Boolean)


273
274
275
276
277
# File 'lib/sisu/dp_make.rb', line 273

def metadata?
  (omit.list.inspect =~/"metadata"/) \
  ? :off
  : :na
end

#minitoc?Boolean

Returns:

  • (Boolean)


278
279
280
281
282
# File 'lib/sisu/dp_make.rb', line 278

def minitoc?
  (omit.list.inspect =~/"minitoc"/) \
  ? :off
  : :na
end

#monoObject



357
358
359
360
361
362
# File 'lib/sisu/dp_make.rb', line 357

def mono
  @h['texpdf_font_mono'] \
  && (@h['texpdf_font_mono']=~/\S{3,}/) \
  ? @h['texpdf_font_mono']
  : @env.font.texpdf.mono
end

#name_format(name) ⇒ Object



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
# File 'lib/sisu/dp_make.rb', line 82

def name_format(name)
  if name
    name=name.strip
    @name_a_h=[]
    authors=name.scan(/[^;]+/)
    authors.each_with_index do |a,i|
      b=((a =~/\s*\|\s*/) ? (a.split(/\|/)) : [a])
      if b[0] =~/"(.+?)"/
        @name_a_h << { the: $1 }
      else
        x=b[0].scan(/[^,]+/)
        if x.length==1
          @name_a_h << { the: x[0].strip }
        elsif x.length==2
          @name_a_h << { the: x[0].strip, others: x[1].strip }
        else #p x.length
        end
      end
      b.delete_at(0)
      b.each do |d|
        k,c=nil
        k,c=/^(\S+)\s+(.*)/.match(d)[1,2] if d
        @name_a_h[i][:hon]=c.strip if k=='hon'
        @name_a_h[i][:affiliation]=c.strip if k=='affiliation'
        @name_a_h[i][:nationality]=c.strip if k=='nationality'
      end
    end
    l=@name_a_h.length
    name_str=''
    @name_a_h.each_with_index do |a,i|
      name_str += if a[:others]
        z=(((l - i) > 1) ? ', ' : '')
        "#{a[:others].strip} #{a[:the].strip}" + z
      else
        z=(((l - i) > 2) ? ', ' : '')
        "#{a[:the].strip}" + z
      end
    end
    { name_a_h: @name_a_h, name_str: name_str }
  else nil
  end
end

#num_topObject



163
164
165
# File 'lib/sisu/dp_make.rb', line 163

def num_top
  @h['num_top']
end

#ocn?Boolean

Returns:

  • (Boolean)


253
254
255
256
257
# File 'lib/sisu/dp_make.rb', line 253

def ocn?
  (omit.list.inspect =~/"ocn"/) \
  ? :off
  : :na
end

#omitObject



245
246
247
248
249
250
251
252
# File 'lib/sisu/dp_make.rb', line 245

def omit
  m=@h['omit']
  @m=m ? (m.split(/,\s+/)) : nil
  def list
    @m
  end
  self
end

#plaintext_wrapObject



237
238
239
240
241
242
243
244
# File 'lib/sisu/dp_make.rb', line 237

def plaintext_wrap
  if @h['plaintext_wrap'].to_s =~/\d\d+/ \
  and @h['plaintext_wrap'].to_i > 19 \
  and @h['plaintext_wrap'].to_i < 201
    @h['plaintext_wrap'].to_i
  else nil
  end
end

#promoObject



389
390
391
# File 'lib/sisu/dp_make.rb', line 389

def promo
  @h['promo']
end

#sansObject

not used



345
346
347
348
349
350
# File 'lib/sisu/dp_make.rb', line 345

def sans                                                             # not used
  @h['texpdf_font_sans'] \
  && (@h['texpdf_font_sans']=~/\S{3,}/) \
  ? @h['texpdf_font_sans']
  : @env.font.texpdf.sans
end

#search_form?Boolean

Returns:

  • (Boolean)


308
309
310
311
312
# File 'lib/sisu/dp_make.rb', line 308

def search_form?
  (omit.list.inspect =~/"search_form"/) \
  ? :off
  : :na
end

#segsubtoc?Boolean

Returns:

  • (Boolean)


303
304
305
306
307
# File 'lib/sisu/dp_make.rb', line 303

def segsubtoc?
  (omit.list.inspect =~/"segsubtoc"/) \
  ? :off
  : :na
end

#serifObject

not used



351
352
353
354
355
356
# File 'lib/sisu/dp_make.rb', line 351

def serif                                                            # not used
  @h['texpdf_font_serif'] \
  && (@h['texpdf_font_serif']=~/\S{3,}/) \
  ? @h['texpdf_font_serif']
  : @env.font.texpdf.serif
end

#substituteObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/sisu/dp_make.rb', line 217

def substitute
  m=@h['substitute']
  if m
    w=m.scan(/\/(.+?)\/(i?,)\s*'(.+?)'(?:\s+|\s*;\s*|$)/)
    arr_hash=[]
    matches=''
    w.each do |x|
      c=(x[1] =~/[i],/) ? :i : :s
      matches=matches + x[0].gsub(/([${}])/,'\\\\\1') + '|'
      arr_hash << {
        match: x[0].gsub(/([${}])/,'\\\\\1'),
        replace: x[2],
        case_s: c
      }
    end
    matches.chop!
    { match_and_replace: arr_hash, matches: matches }
  else nil
  end
end

#texpdf_fontObject



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
# File 'lib/sisu/dp_make.rb', line 338

def texpdf_font
  def main
    @h['texpdf_font'] \
    && (@h['texpdf_font']=~/\S{3,}/) \
    ? @h['texpdf_font']
    : @env.font.texpdf.main
  end
  def sans                                                             # not used
    @h['texpdf_font_sans'] \
    && (@h['texpdf_font_sans']=~/\S{3,}/) \
    ? @h['texpdf_font_sans']
    : @env.font.texpdf.sans
  end
  def serif                                                            # not used
    @h['texpdf_font_serif'] \
    && (@h['texpdf_font_serif']=~/\S{3,}/) \
    ? @h['texpdf_font_serif']
    : @env.font.texpdf.serif
  end
  def mono
    @h['texpdf_font_mono'] \
    && (@h['texpdf_font_mono']=~/\S{3,}/) \
    ? @h['texpdf_font_mono']
    : @env.font.texpdf.mono
  end
  def cjk
    @h['texpdf_font_cjk'] \
    && (@h['texpdf_font_cjk']=~/\S{3,}/) \
    ? @h['texpdf_font_cjk']
    : @env.font.texpdf.cjk
  end
  def cjk_zh
    @h['texpdf_font_cjk_zh'] \
    && (@h['texpdf_font_cjk_zh']=~/\S{3,}/) \
    ? @h['texpdf_font_cjk_zh']
    : @env.font.texpdf.cjk_zh
  end
  def cjk_ja
    @h['texpdf_font_cjk_ja'] \
    && (@h['texpdf_font_cjk_ja']=~/\S{3,}/) \
    ? @h['texpdf_font_cjk_ja']
    : @env.font.texpdf.cjk_ja
  end
  def cjk_ko
    @h['texpdf_font_cjk_ko'] \
    && (@h['texpdf_font_cjk_ko']=~/\S{3,}/) \
    ? @h['texpdf_font_cjk_ko']
    : @env.font.texpdf.cjk_ko
  end
  self
end

#toc?Boolean

Returns:

  • (Boolean)


258
259
260
261
262
# File 'lib/sisu/dp_make.rb', line 258

def toc?
  (omit.list.inspect =~/"toc"/) \
  ? :off
  : :na
end

#validate_length(s, l, n) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/sisu/dp_make.rb', line 63

def validate_length(s,l,n)
  #s=(s.length <= l) ? s : nil
  s=if s.is_a?(String) \
  and s.length <= l
    s
  elsif s.is_a?(NilClass)
    nil
  elsif s.class !=String
    STDERR.puts "#{n} is #{s.class}: programming error, String expected #{__FILE__}:#{__LINE__}"
    s
  else
    SiSU_Screen::Ansi.new(
      'v',
      "*WARN* #{n} length #{s.length} exceeds set db field length #{l}, metadata dropped",
      @opt.fns
    ).warn unless @opt.act[:quiet][:set]==:on
    nil
  end
end