Class: Dyndoc::Ruby::TemplateManager

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/dyndoc/base/tmpl/oop.rb,
lib/dyndoc/base/tmpl/eval.rb,
lib/dyndoc/base/helpers/core.rb,
lib/dyndoc/base/tmpl/manager.rb,
lib/dyndoc/base/tmpl/rbenvir.rb,
lib/dyndoc/base/tmpl/parse_do.rb,
lib/dyndoc/base/tmpl/extension.rb,
lib/dyndoc/plugins/tex/tex_eval.rb,
lib/dyndoc/plugins/tex/tex_parse_do.rb

Constant Summary collapse

@@interactive =

attr_accessor :mark

nil
@@depth =
0
@@cmd =
["title",""]+@@cmd
@@cmdAlias =

Alias

{"unless"=>"if","out"=>"do","r<"=>"r","R<"=>"R","rb<"=>"rb","r>"=>"r","R>"=>"R","rb>"=>"rb","m<"=>"m","M<"=>"m","m>"=>"m","M>"=>"m","jl>"=>"jl","jl<"=>"jl","sh<"=>"sh","<"=>"txt","<<"=>"txt",">"=>"txt","code"=>"txt","dyn"=>"eval","r>>"=>"rverb","R>>"=>"rverb","rout"=>"rverb","rb>>" => "rbverb","jl>>" => "jlverb","saved"=>"blck","blckAnyTag"=>"blck"}
@@newBlcks =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#clean_block_without_bracket, #detect_string_inside_string, #hello!, #process_bang, #process_jl, #process_r, #process_rb

Constructor Details

#initialize(tmpl_cfg = {}, with = true) ⇒ TemplateManager

Returns a new instance of TemplateManager.



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
# File 'lib/dyndoc/base/tmpl/manager.rb', line 114

def initialize(tmpl_cfg={},with=true)
  # just in case it is not yet initialized!
  (Dyndoc.cfg_dyn[:langs] << :R).uniq! if with==true

#puts "DEBUT INIT TemplateManager"
  @tmpl_cfg=tmpl_cfg
=begin
  @cfg[:part_tag][0]=@cfg[:part_tag][0][1..-1] if !(@cfg[:part_tag].empty?) and (@partTag_add= (@cfg[:part_tag][0][0,1]=="+"))
=end
  ## default system root appended
  unless  Dyndoc.cfg_dyn[:ruby_only]
    TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R
    TemplateManager.initJulia if Dyndoc.cfg_dyn[:langs].include? :jl
  end
  rbenvir_init(binding)
  @rEnvir=["Global"]
  @envirs={}
  @fmtContainer=[]
  @echo=1
  @strip=true
#puts "FIN INIT TemplateManager"
  if Dyndoc.cfg_dyn[:devel_mode]==:test
    puts "DYNDOC SEARCH PATH:"
    puts Dyndoc.get_pathenv(Dyndoc.cfg_dyn[:root_doc]).join(":")
  end
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def args
  @args
end

#blckNameObject (readonly)

Returns the value of attribute blckName.



34
35
36
# File 'lib/dyndoc/base/tmpl/manager.rb', line 34

def blckName
  @blckName
end

#blocksObject

Returns the value of attribute blocks.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def blocks
  @blocks
end

#callsObject

Returns the value of attribute calls.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def calls
  @calls
end

#cfgObject

Returns the value of attribute cfg.



31
32
33
# File 'lib/dyndoc/base/tmpl/manager.rb', line 31

def cfg
  @cfg
end

#cfg_tmplObject

Returns the value of attribute cfg_tmpl.



31
32
33
# File 'lib/dyndoc/base/tmpl/manager.rb', line 31

def cfg_tmpl
  @cfg_tmpl
end

#docObject

Returns the value of attribute doc.



31
32
33
# File 'lib/dyndoc/base/tmpl/manager.rb', line 31

def doc
  @doc
end

#doLangBlockObject

Returns the value of attribute doLangBlock.



1887
1888
1889
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1887

def doLangBlock
  @doLangBlock
end

#dyndocModeObject

Returns the value of attribute dyndocMode.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def dyndocMode
  @dyndocMode
end

#echoObject

Returns the value of attribute echo.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def echo
  @echo
end

#envirsObject

Returns the value of attribute envirs.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def envirs
  @envirs
end

#filenameObject

Returns the value of attribute filename.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def filename
  @filename
end

#filterObject

Returns the value of attribute filter.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def filter
  @filter
end

#filterGlobalObject

Returns the value of attribute filterGlobal.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def filterGlobal
  @filterGlobal
end

#fmtObject

Returns the value of attribute fmt.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def fmt
  @fmt
end

#FmtObject

Returns the value of attribute Fmt.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def Fmt
  @Fmt
end

#fmtContainerObject

Returns the value of attribute fmtContainer.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def fmtContainer
  @fmtContainer
end

#fmtOutputObject

Returns the value of attribute fmtOutput.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def fmtOutput
  @fmtOutput
end

#globalObject

Returns the value of attribute global.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def global
  @global
end

#libsObject

Returns the value of attribute libs.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def libs
  @libs
end

#rbBlockObject

Returns the value of attribute rbBlock.



33
34
35
# File 'lib/dyndoc/base/tmpl/manager.rb', line 33

def rbBlock
  @rbBlock
end

#rbEnvirObject

Returns the value of attribute rbEnvir.



32
33
34
# File 'lib/dyndoc/base/tmpl/manager.rb', line 32

def rbEnvir
  @rbEnvir
end

#rbEnvirsObject

Returns the value of attribute rbEnvirs.



32
33
34
# File 'lib/dyndoc/base/tmpl/manager.rb', line 32

def rbEnvirs
  @rbEnvirs
end

#rEnvirObject

Returns the value of attribute rEnvir.



32
33
34
# File 'lib/dyndoc/base/tmpl/manager.rb', line 32

def rEnvir
  @rEnvir
end

#scanObject (readonly)

Returns the value of attribute scan.



34
35
36
# File 'lib/dyndoc/base/tmpl/manager.rb', line 34

def scan
  @scan
end

#stripObject

Returns the value of attribute strip.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def strip
  @strip
end

#tagsObject

Returns the value of attribute tags.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def tags
  @tags
end

#tmplObject

Returns the value of attribute tmpl.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def tmpl
  @tmpl
end

#tmpl_cfgObject

Returns the value of attribute tmpl_cfg.



31
32
33
# File 'lib/dyndoc/base/tmpl/manager.rb', line 31

def tmpl_cfg
  @tmpl_cfg
end

#varsObject

Returns the value of attribute vars.



30
31
32
# File 'lib/dyndoc/base/tmpl/manager.rb', line 30

def vars
  @vars
end

Class Method Details

.attrObject



108
109
110
111
112
# File 'lib/dyndoc/base/tmpl/manager.rb', line 108

def TemplateManager.attr
  attr={:cmd => @@cmd,:cmdAlias => @@cmdAlias, :argsSep => @@argsSep, :tags => @@tags,:prefix => @@prefix, :tagSearch => @@tagSearch, :tagModifiers => @@tagModifiers}
  attr[:tags_tex],attr[:tex_vars] = @@tags_tex,@@tex_vars if TemplateManager.class_variables.include? "@@tag_tex"
  attr
end

.initJuliaObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/dyndoc/base/tmpl/manager.rb', line 83

def TemplateManager.initJulia
  Dyndoc.logger.info "initJulia: first"
  first=require "jl4rb" #save if it the first initialization!
  Dyndoc.logger.info "initJulia: require"
  Julia.init
  Dyndoc.logger.info "initJulia: init"
  # init rb4jl stuff
  # since inside ruby, no need Ruby.start and Ruby.stop like in rb4R.
  # sort of equivalent of JLServer.init_filter (but not yet defined)!
  #Julia << "Base.include(@__MODULE__,\"ruby.jl\")"
  Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+ "\")"
  Dyndoc.logger.info "initJulia: ruby.jl"
  Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+ "\")"
  Dyndoc.logger.info "initJulia: dynArray.jl"
  #-| To debug ruby.jl and dynArray.jl => uncomment below and commnt above
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/ruby.jl")+"\")"
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/dynArray.jl")+"\")"
  Julia << "using Main.Dyndoc"
  Dyndoc.logger.info "initJulia: using Dyndoc"
  Julia << "Dyndoc.Ruby.alive(true)"
  #Julia << "global const _dynArray=DynArray()"
  Dyndoc.logger.info "Julia initialized inside dyndoc!"

end

.initRObject

Maybe better located inside server.rb



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
# File 'lib/dyndoc/base/tmpl/manager.rb', line 45

def TemplateManager.initR
  ## THIS IS JUST IMPOSSIBLE SINCE RUBY USES HOME TO EXPAND PATH
  ## NEEDS TO FIND AN ALTERNATIVE SOLUTION: R_LIBS_USER
  # For windows! R now change HOME variable by appending "/Documents" at the end. Ruby does not do that!
  if RUBY_PLATFORM =~ /mingw/ and !(File.exist? File.join(ENV["HOME"],"R","win-library")) and (File.exist? File.join(ENV["HOME"],"Documents","R","win-library"))
    ##ENV["HOME"] += "/Documents"
    if ENV["R_LIBS_USER"]
      puts "Warning (dyndoc): R_LIBS_USER already in use by dyndoc. Fix that by calling inside dyndoc .libPaths(\"#{ENV['R_LIBS_USER']}\")"
    end
    ENV["R_LIBS_USER"]=Dir[File.join(ENV["HOME"],"Documents","R","win-library","*")][-1]
    ## RMK: if R_LIBS_USER already exist then the second solution
  end

  first=require "R4rb" #save if it the first initialization!
  Dyndoc.warn "FIRST INIT OF R!!!! => #{first}"
  Array.initR
  TemplateManager.interactive
  #p "client";p Dyndoc.cfg_dyn;p interactive
  R4rb << "rm(list=ls(all=TRUE))" if !first and !@@interactive #remove all initial variables if previous documents session
  R4rb << ".dynStack<-new.env()" #used for R variables used by dyndoc
  RServer.init_envir
  RServer.init_filter
  ## ruby and R init for dynArray stuff
  require "dyndoc/common/dynArray"
  dyndocToolsR = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocTools.R").gsub('\\','/')
  ## WD is introduced by Msys and ConEmuDir by ConEmu
  dyndocToolsRoot = RUBY_PLATFORM =~ /msys/ ? (ENV['WD'] || ENV['ConEmuDir']).split('\\')[0...-2].join(File::Separator) : ""
  R4rb << "source('"+dyndocToolsRoot+dyndocToolsR+"',chdir=TRUE)"
  if RUBY_PLATFORM =~ /msys/
    dyndocMsys2R = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocMsys2.R").gsub('\\','/')
    R4rb << "source('"+dyndocToolsRoot+dyndocMsys2R+"',chdir=TRUE)"
  end
  if RUBY_PLATFORM =~ /mingw/
    require File.join(ENV["DYNDOC_HOME"],"bin","msys2","file_tools.rb") if ENV["DYNDOC_HOME"]
  end
  Dyndoc.logger.info "R initialized inside dyndoc!"
end

.interactiveObject



39
40
41
42
# File 'lib/dyndoc/base/tmpl/manager.rb', line 39

def TemplateManager.interactive
  @@interactive=Dyndoc.cfg_dyn[:dyndoc_session]==:interactive unless @@interactive
  @@interactive
end

Instance Method Details

#add_dtag(dtag, cmdAlias = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 35

def add_dtag(dtag,cmdAlias=nil)
  @scan=DevTagScanner.new(:dtag) unless @scan
  if dtag
   @scan.merge_tag(dtag)
   @@cmd += dtag[:instr]
  end
  if cmdAlias
    @@cmdAlias[dtag[:instr][0]]=cmdAlias
  end
  #p @@cmd;p @@cmdAlias
end

#aggregate_newBlck(blck, aggrItems, allAggrItems, from) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/extension.rb', line 224

def aggregate_newBlck(blck,aggrItems,allAggrItems,from)
  res,newBlck=blck[0...from],nil
  ##puts "debut aggr";p res;p aggrItems;p allAggrItems
  resAggr=[] #to save the different elements in the right order
  (from..(blck.length-1)).each do |i|
    if newBlck
      if allAggrItems.include? blck[i]
        if aggrItems.include? blck[i]
          resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]})
        else
          newBlck = nil
          resAggr << blck[i]
        end
      else
        newBlck[:blck] << blck[i]
      end
    else
      if aggrItems.include? blck[i]
        resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]})
      else
        resAggr << blck[i]
      end
    end
  end

  ## if defaultFmtCotainer defined use it as block starter!
  start=@defaultFmtContainer ? @defaultFmtContainer : :>
  ##puts "start";p start
  #puts "resAggr";p resAggr
  resAggr.each {|e|
    if e.is_a? Hash
      res << e[:tag] << ((e[:blck][1].is_a? Symbol) ? e[:blck] : [:blck,start]+e[:blck][1..-1])
    else
      res << e
    end
  }
  ##puts "result";p res
  res

end

#append_to_begin_document(filter, content) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/dyndoc/plugins/tex/tex_eval.rb', line 59

def append_to_begin_document(filter,content)
  ## _BEGINDOC_ already declared in DefaultPre_tmpl.tex
  if  filter.envir.global["_BEGINDOC_"]
    filter.envir.global["_BEGINDOC_"][:val][0] << "\n" unless filter.envir.global["_BEGINDOC_"][:val][0].empty?
    filter.envir.global["_BEGINDOC_"][:val][0] << content
  end
end

#as_default_tmpl_mngr!Object

to set the current tmpl_mngr as the default one accessed via Dyndoc.tmpl_mngr and used in #R> #rb> block



163
164
165
# File 'lib/dyndoc/base/tmpl/manager.rb', line 163

def as_default_tmpl_mngr!
  Dyndoc.tmpl_mngr=self unless Dyndoc.tmpl_mngr == self
end

#blckMode_normal?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/dyndoc/base/tmpl/extension.rb', line 220

def blckMode_normal?
  (@@newBlcks.keys & @blckDepth).empty?
end

#blockFormatObject



301
302
303
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 301

def blockFormat
  @fmtContainer[0] ? (@fmtContainer[0].to_s)[0...-1] : nil
end

#cache(cache_ = {}) ⇒ Object

Make more readable the creation of newBlck



142
143
144
145
# File 'lib/dyndoc/base/tmpl/manager.rb', line 142

def cache(cache_={})
  return @vars[blckName[-1]] if cache_.empty?
  @vars[blckName[-1]]=cache_
end

#clean_as_is(out) ⇒ Object



346
347
348
# File 'lib/dyndoc/base/tmpl/manager.rb', line 346

def clean_as_is(out)
  out.gsub!(Dyndoc::AS_IS,"")
end

#completed_newBlck(cmd, blckname, blck, filter) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/extension.rb', line 265

def completed_newBlck(cmd,blckname,blck,filter)
  ### IMPORTANT: blckname==nil means inside sub-blck :blckAnyTag and then no init performed as :pre and :post preprocess!
  ## As in [#rb>] for (i in 1..3) {#>][#bar]....[#} !!!! No blckname here!
  if blckname
    filter.envir["blckname"]=blckname
  end
  #Dyndoc.warn "completed_newBlck: blck init",[blckname,blck]
  i=(blckname ? 2 : 1)
  ## blckAnyTag behaves like the previous tag in @@newBlcks.keys (all the user-defined commands)
  cmd=@blckDepth.reverse.find{|e| @@newBlcks.keys.include? e} if cmd=="blckAnyTag"
  #Dyndoc.warn "extension",[i,cmd,@@newBlcks[cmd],@blckDepth]
  items=(@@newBlcks[cmd].keys)-[":pre",":post",:aggregate]
  #Dyndoc.warn "completed:items",items
  if @@newBlcks[cmd][:aggregate] #and blckname
    blck=aggregate_newBlck(blck,@@newBlcks[cmd][:aggregate].map{|e| e.to_sym},items.map{|e| e.to_sym},i)
    ##Dyndoc.warn "aggregate",blck
  end
  ## first replace :"," by :"="
  while blck[i]==:","
    blck[i]= :"="
    i+=2
  end
  ## prepend the pre code if it exists!
  ##Dyndoc.warn "blck.length(BEFORE pre)",[blckname,cmd,blck.length,blck]
  if @@newBlcks[cmd][":pre"] and blckname
    blck.insert(i,*(@@newBlcks[cmd][":pre"]))
    i+=@@newBlcks[cmd][":pre"].length
  end
  ##Dyndoc.warn "blck.length",[blck.length,blck]
  while i < blck.length-1
    item=blck[i].to_s
    #Dyndoc.warn "item",[cmd,item]
    if items.include? item
      if @@newBlcks[cmd][item][:pre]
        blck.insert(i,*(@@newBlcks[cmd][item][:pre]))
        i+=@@newBlcks[cmd][item][:pre].length
      end
      if @@newBlcks[cmd][item][:do_code] and blck[i+1].respond_to? "[]" and blck[i+1][0]==:named
        blck.insert(i,blck[i+1])
        blck.insert(i,:"=")
        i+=2
      elsif !@@newBlcks[cmd][item][:do_code]
        blck[i]=(blck[i+1][0]==:named ? :"=" : :">")
      end
      i+=2
      if @@newBlcks[cmd][item][:post]
        #puts "post";p blck[i-1];p blck[i];p blck[i+1];p *(@@newBlcks[cmd][item][:post])
        blck.insert(i,*(@@newBlcks[cmd][item][:post]))
        i+=@@newBlcks[cmd][item][:post].length
      end
    else
      i+=1
    end
    #Dyndoc.warn "completed_newBlck: blck iter",blck
  end
  #Dyndoc.warn "completed_newBlck: blck before end",blck
  ## prepend the pre code if it exists!
  if @@newBlcks[cmd][":post"] and blckname
    blck.insert(i+1,*(@@newBlcks[cmd][":post"]))
    i+=@@newBlcks[cmd][":post"].length
  end
  #p blck
  ## find tag
  #p @@newBlcks[cmd]
  #Dyndoc.warn "completed_newBlck: blck end",blck
  return blck
end

#currentFormatObject



297
298
299
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 297

def currentFormat
  (@curFmtContainer.to_s)[0...-1]
end

#defaultFormatObject



293
294
295
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 293

def defaultFormat
  (@defaultFmtContainer.to_s)[0...-1]
end

#do_blck(tex, blck, filter) ⇒ Object



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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 310

def do_blck(tex,blck,filter)
#begin puts "do_blck";p @curCmd;p blck; end if @curCmd=="blck"
  i=0 #blck[0]==:blck
  #New mode (071108): save and restore named block!
  curCmd,blckname=@curCmd,nil

  if blck[1].is_a? Array
      ## Fix blckAnyTag when starting with text => add :>
      if  blck[0] == :blckAnyTag and blck[1][0]==:main
        blck.insert(1,:>)
      else
        blckname=parse([blck[1]],filter).strip
      end
  end
  ##Dyndoc.warn :blckname,[blckname,blck]
  if curCmd=="saved"
    ####################################################################
    ## TODO: all the stuff generated has to be saved!
    ## tex records all the generated content but what about the files!
    ## Maybe, keep tracks of all files generated! By default put it inside inside .dyn_out directory
    ## but also records which files have been generated in the saved mode!
    ####################################################################
    #blckname=parse([blck[1]],filter).strip
    ##puts "blckname";p blckname
    return if blckname.empty?
    unless blck[2]
      #p Utils.dyndoc_raw_var_ls
      #p blckname
      if Utils.dyndoc_raw_var_ls.include? blckname
        tex << Utils.dyndoc_raw_var_content(blckname,self)
      end
    else
      ## fetch the result from the saved result if it exists or force regeneration at the command line!
      res=Utils.saved_content_get(blckname,self,true) #true here is very important since input user is checked first to know if content needs to be regenerated!
      #puts "direct:res";p res
      unless res
        res=parse([blck[2..-1].unshift(:blck)],filter)
        #puts "created:res";p res
        ## saved_contents_file does not not contain this block!
        Utils.saved_content_add_as_variable(blckname,res,@filename)
      end
      tex << res ## stop here!
    end
  else #curCmd=="blck"
    @blckDepth ||= []
    @blckDepth << curCmd
    #puts "blckDepth";p @blckDepth;p @@newBlcks.keys
    if !(cmdBlcks=@@newBlcks.keys & @blckDepth).empty?
      #puts "cmdBlcks";p cmdBlcks
      #puts "blckDepth";p @blckDepth
      #p blck
      @newBlckMode=true
      (["blckAnyTag"]+cmdBlcks).each do |cmd|
        #Dyndoc.warn "cmd",[cmd.to_sym,blck[0]]
        if blck[0]==cmd.to_sym
          # Fix bug when calling newBlck with no space at the beginning
          # blckname==nil only for blckAnyTag
          if !blckname and cmd!="blckAnyTag"
            blckname=""
            blck=blck[0,1]+[[:main,""]]+blck[1..-1]
          end
          #Dyndoc.warn "BEFORE COMPLETED_BLCK",[cmd,blckname,blck]
          blck=completed_newBlck(cmd,blckname,blck,filter)
          #Dyndoc.warn "AFTER COMPLETED_BLCK",blck
        end
      end

    elsif blck[1].is_a? Array
     #blckname=parse([blck[1]],filter).strip
     to_end=!blckname.empty?
     if blck[2] and to_end
       mode,to_exec=:normal,nil
       if ["+",">","$"].include? blckname[0,1]
         mode,blckname = :append,blckname[1..-1].strip
       elsif ["^","<"].include? blckname[0,1]
         mode,blckname = :prepend,blckname[1..-1].strip
       end
       to_exec,blckname=true,blckname[0...-1] if blckname[-1,1]=="!"
#Dyndoc.warn "to_exec",[to_exec,blckname]
       @savedBlocks[blckname]= ( mode==:normal ? blck[2..-1].unshift(:blck) : ( mode==:append ? @savedBlocks[blckname]+blck[2..-1] : (blck[2..-1]+@savedBlocks[blckname][1..-1]).unshift(:blck) ) )
       tex << parse([@savedBlocks[blckname]],filter) if to_exec
     elsif to_end
  #p @savedBlocks[blckname]
  #puts "blck #{blckname}"
       tex << parse([@savedBlocks[blckname]],filter) if @savedBlocks[blckname]
     end
  #p to_stop;p blck
     return if to_end
    end
    # normal (old) mode
    cond,cond_tag=true,true
    condArch=[]

    #p blck if curCmd=="tabbar"
    if @@newBlcks.keys.include? @blckDepth[-1]
      @blckName ||= []
      tmp=blck[1][1].strip
      @blckName << (tmp.empty? ? `uuidgen`.strip : tmp)
      #puts "blckNAME";p @blckName
    end

    begin
      case (current_block_tag=blck[i+=1])
     when :"%"
       i,*b2=next_block(blck,i)
     when :"?"
       i,*b2=next_block(blck,i)
       if cond_tag
         filter.outType=":rb"
##Dyndoc.warn "do_block:?:b2",b2
         code=parse_args(b2[0],filter).strip
  #puts "do_block:?:code"; p code
         mode=code.downcase
  #puts "do_block:?:mode";p mode
         if ["!","else"].include? mode
           cond = !cond
         elsif ["*","all","end"].include? mode
           cond,condArch=true,[]
         elsif mode=~/^prev/
           nbPop=mode.scan(/ \d*$/)
           nbPop=(nbPop.empty? ? 1 : nbPop[0].to_i)
           nbPop.times{cond=condArch.pop}
         else
           mode,code=code[0,1],code[1..-1] if ["&","|"].include? code[0,1]
           cond2=@rbEnvir[0].eval(code)
           condArch << cond
           if mode=="&"
            cond=  cond & cond2
           elsif mode=="|"
            cond=  cond |  cond2
           else
            cond=cond2
           end
         end
         filter.outType=nil
       end
  #puts "cond in block #{code}=";p cond
     when :tag,:"??"
  ## Dyndoc.warn "tag:blck",blck
       i,*b2=next_block(blck,i)
  ## Dyndoc.warn "tag:b2",b2
       code=parse(b2,filter).strip.downcase
  ## Dyndoc.warn "tag",code
       if ["!","else"].include? code
         cond_tag = !cond_tag
       elsif ["*","all","end"].include? code
         cond_tag=true
       else
         mode=nil
         mode,code=code[0,1],code[1..-1] if ["&","|","-"].include? code[0,1]
  ## Dyndoc.warn "mode and code",[mode,code]
         tags=TagManager.make_tags(code)
  ## Dyndoc.warn "tags, @tags",[tags,@tags]

         cond2_tag=TagManager.tags_ok?(tags,@tags)
  #puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag
         if mode=="&"
  #puts "tags, @tags";p tags;p @tags
  #puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag; p cond_tag.class;p cond2_tag.class;p cond_tag and  cond2_tag
  #RMK: a=0 and nil => a=0 because a stays to be a FixNum.
          cond_tag=  (cond_tag and  cond2_tag ? 0 : nil)
  #puts "INTER cond_tag->";p cond_tag
         elsif mode=="|"
          cond_tag =  (cond_tag or  cond2_tag ? 0 : nil)
         elsif mode=="-"
          cond_tag =  !cond2_tag
         else
          cond_tag = cond2_tag
         end
  #puts "FINAL cond_tag->";p cond_tag
       end
  #puts "cond_tag in block #{code}=";p cond_tag
      when :do,:<
        i,*b2=next_block(blck,i)
        parse(b2,filter) if cond_tag and cond
      when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<",:"sh<"
        # if current_block_tag==:"jl<"
        #   ##p "iciiiii"
        # end
        newblck=blck[i]
  #puts "newblock";p newblck;p blck
        i,*b2=next_block(blck,i)
  #p b2
         code=b2[0][1..-1]
##p code
          #need to be cleaned with no bracket at the beginning and the end of the block!
          clean_block_without_bracket(code)
         if cond_tag and cond
            b2=[code.unshift(newblck)]
##puts "r<;rb<";p b2
            filter.outType=":"+(blck[i].to_s)[0...-1]
            #Dyndoc.warn "rb,jl,R block",filter.outType
            parse(b2,filter)
            filter.outType=nil
    	    end
      #equivalent of :var but DO NOT USE :var
    when :"=",:"tex=",:"md=",:"adoc=",:"txtl=",:"html=",:"rb=",:"R=",:"jl="
  	    i,*b2=next_block(blck,i)
  	    if cond_tag and cond
  #puts "=:b2";p b2
  	      b=make_var_block(b2.unshift(:var),filter)
  #puts "=:b";p b
  	      eval_VARS(b,filter)
  	    end
      when :"-"
        i,*b2=next_block(blck,i)
  	    if cond_tag and cond
  #puts "-:b2"
          parse(b2,filter).strip.split(",").each{|key| @vars.remove(key)}
  	    end
  	  when :+,:"tex+",:"md+",:"adoc+",:"txtl+",:"html+",:"rb+",:"R+",:"jl+"
  ##Dyndoc.warn "+:-1:block",[i,blck]
  	    i,*b2=next_block(blck,i)
  ##Dyndoc.warn "+:0:i,b2",[i,b2]
  	    if cond_tag and cond
  	      var,pos=b2[0][1].split(",")
  ## Dyndoc.warn "+:1:var,pos",[var,pos]
  	      pos = -1 unless pos
  	      pos=pos.to_i
  	      var=filter.apply(var)
  	      varObj=@vars.extract_raw(var)
  ## Dyndoc.warn "+:2:var",[var,varObj,(varObj.is_a? Array)]
  	      if varObj
  		      if varObj.is_a? Array
  		        pos=varObj.length+pos+1 if pos<0
  		        varNew=var+".#{pos}"
  		        #new element
              ## Needs to deep dup (dup is not enough!)
              b2dup=Marshal.load( Marshal.dump(b2) )
  		        b2dup[0][1]="::ADDED_ELT"
  ## Dyndoc.warn "+:3:b2,b2dup,blck",[b2,b2dup,blck]
  		        b=make_var_block(b2dup.unshift(:var),filter)
  ## Dyndoc.warn  "b",b
  		        eval_VARS(b,filter)
  		        type=@vars.extract_raw("::ADDED_ELT").class
  		        res={:val=>[""]}
  		        res=[] if type==Array
  		        res={} if type==Hash
  		        varObj.insert(pos,res)
  ## Dyndoc.warn "varObj",[varObj,b2]
  		        b2dup[1][1]=varNew
  		        b=make_var_block(b2dup,filter)
  ## Dyndoc.warn "+:4:b2,b2dup,blck",[b2,b2dup,blck]
  		        eval_VARS(b,filter)
  		      elsif varObj.is_a? Hash and varObj[:val]
  ## Dyndoc.warn "+:else1:blck",blck
              ## Needs to deep dup (dup is not enough!)
              b2dup=Marshal.load( Marshal.dump(b2) )
  		        b2dup[0][1]="::ADDED_ELT"
  ## Dyndoc.warn "+:3else:b2",[b2,b2dup]
  ## Dyndoc.warn "+:else2:blck",blck
  ## Dyndoc.warn "+:else2:b2.unshift(:var)",b2dup.unshift(:var)
  		        b=make_var_block(b2dup.unshift(:var),filter)
  ## Dyndoc.warn "+:4else:b",b
  ## Dyndoc.warn "+:else2:blck",blck
  		        eval_VARS(b,filter)
  		        res=@vars.extract_raw("::ADDED_ELT")
  		        varObj[:val][0].insert(pos,res[:val][0])
  ## Dyndoc.warn "+:5else:varObj",[varObj,b]
  		      end
  #puts "varNew:#{var}";p @vars.extract_raw(var)
  	      end
  	    end
      when :out,:>,:">!" # :>! is in some sense equivalent of :set
              i,*b2=next_block(blck,i)
  #puts "block >, cond_tag, cond";p cond_tag ;p cond
  	     if cond_tag and cond and !b2.empty?
  #puts "do_blck:out";p b2
  #p blck
              vars,b2=get_named_blck(b2,filter)
#Dyndoc.warn "do_blck:out, >!",[vars,b2] if current_block_tag==:">!"
  #p b2
  #p current_block_tag
  #p current_block_tag==:">!"
              make_named_blck(tex,filter,vars,b2,current_block_tag==:">!") if b2
  	     end
        when :"_<"
          i,*b2=next_block(blck,i)
          val=parse(b2,filter).strip
          @defaultFmtContainer=(val+">").to_sym if ["","html","tex","txtl","ttm","md","adoc"].include? val
        when :"txtl>",:"ttm>",:"tex>",:"html>",:"_>",:"__>",:"md>",:"adoc>"
            newblck=blck[i]
            @curFmtContainer=:"tex>" unless @curFmtContainer
            if newblck==:"__>"
              newblck=@curFmtContainer #the previous one
            elsif newblck==:"_>"
              newblck=(@defaultFmtContainer ? @defaultFmtContainer : @curFmtContainer) #the default one
            else
              @curFmtContainer=nil #to redefine at the end
            end
            i,*b2=next_block(blck,i)
            if cond_tag and cond and !b2.empty? #if b2 empty nothing to do!
              @fmtContainer.unshift newblck
              val=parse(b2,filter)
              if @fmtContainer[1] and @fmtContainer[1]==@fmtContainer[0] #no need to convert!
                tex << val
              else #convert
                ##Dyndoc.warn "txtl formats",[@fmtContainer[0],@fmtOutput,@fmtContainer[1]]
                ##Dyndoc.warn :val, val
                tex << Dyndoc::Converter.convert(val,@fmtContainer[0],@fmtOutput,@fmtContainer[1]) #last parameter: true means to protect
              end
              @curFmtContainer=@fmtContainer[0] unless @curFmtContainer
              @fmtContainer.shift
            end

        when :"r>",:"rb>",:"R>",:"m>",:"M>",:"jl>"
              newblck=blck[i]
              i,*b2=next_block(blck,i)
  #puts "RB>";p b2;p i;p blck
  	        if cond_tag and cond and !b2.empty? #if b2 empty nothing to do!
              vars,b2=get_named_blck(b2,filter)
              if b2
                b2=[b2.unshift(newblck)]
                filter.outType=":"+(blck[i].to_s)[0...-1]
                make_named_blck(tex,filter,vars,b2)
                filter.outType=nil
              end
  	         end
  	  when :"r>>",:"R>>",:rout,:rverb
  	    newblck=blck[i]
              i,*b2=next_block(blck,i)
  	    if cond_tag and cond
              vars,b2=get_named_blck(b2,filter)
              if b2
                b2=[b2.unshift(newblck)]
                filter.outType=":r" #+(blck[i].to_s)[0...-1]
=begin
  	      val=parse(b2,filter)
  #puts "make_named_blck:val";p val
  	      val=Utils.format_blocktext(val)
  #puts "format_blocktext:val";p val
  	      if vars
  		vars.split(",").each{|var|
  		eval_SET(var.strip,val,filter)
  	      }
  	      else
  		tex << val
  	      end
=end
                make_named_blck(tex,filter,vars,b2)
                filter.outType=nil
              end
  	    end
      when :"jl>>",:jlverb,:"rb>>",:rbverb
        newblck=blck[i]
              i,*b2=next_block(blck,i)
        if cond_tag and cond
              vars,b2=get_named_blck(b2,filter)
              if b2
                b2=[b2.unshift(newblck)]
                filter.outType=newblck.to_s[0,2].to_sym  #":jl" #+(blck[i].to_s)[0...-1]
=begin
          val=parse(b2,filter)
  #puts "make_named_blck:val";p val
          val=Utils.format_blocktext(val)
  #puts "format_blocktext:val";p val
          if vars
      vars.split(",").each{|var|
      eval_SET(var.strip,val,filter)
          }
          else
      tex << val
          end
=end
                make_named_blck(tex,filter,vars,b2)
                filter.outType=nil
              end
        end
            when :>>
              i,*b2=next_block(blck,i)
  	    if cond_tag and cond
              file,b2=get_named_blck(b2,filter)
              if b2 and file
                mode=:save
                case file[-1,1]
                when "?"
                  mode=:exist
                  file=file[0...-1]
                when "!"
                  mode=:nothing
                  file=file[0...-1]
                end
                mode=(File.exist?(file) ? :nothing : :save ) if mode==:exist
                tex2=parse(b2,filter)
  	            tex2==Utils.format_blocktext(tex2)
                if mode==:save
                  File.open(file,"w") do |f|
                    f << tex2
                  end
                end
  	    end
              end
            when :nl,:"\\n"
              i,*b2=next_block(blck,i)
  	    if cond_tag and cond
              tex << "\n" << parse(b2,filter)
  #puts "nl";p tex
  	    end
            when :yield #only inside a {#def] block!
              i,*b2=next_block(blck,i)
  	    if cond_tag and cond
  	    codename=parse(b2,filter).strip
  #p codename
  #p @def_blck
              make_yield(tex,codename,filter)
  	    end
  	  when :<< #input without variable entries
  	    i,*b2=next_block(blck,i)
  	    if cond_tag and cond
  #p b2
          var,b2=get_named_blck(b2,filter)
          #p var;p b2
  	      tmpl=parse(b2,filter).strip
  #p tmpl
          val=eval_INPUT(tmpl,[],filter)
          if var
            eval_SET(var.strip,val,filter)
          else
  	       tex << val
          end
  	    end
      else
        i,*b2=next_block(blck,i)
        blckCmd=(current_block_tag.is_a? Symbol) ?  ("do_blck_"+curCmd+"_"+current_block_tag.to_s).to_sym : nil
        #Dyndoc.warn :blckCmd,[current_block_tag,blckCmd,(methods.include? blckCmd),methods.sort]
        blckCmd=nil if blckCmd and !(methods.include? blckCmd)
        #Dyndoc.warn :blckCmd2,blckCmd
        if cond_tag and cond and blckCmd
          #Dyndoc.warn :blck_command #, [blckCmd,b2]
          method(blckCmd).call(tex,b2,filter)
        end
      end
    end while i<blck.length-1
    @blckName.pop if @blckName and @@newBlcks.keys.include? @blckDepth[-1]
    @blckDepth.pop
    @newBlckMode=nil
  end
end

#do_call(tex, blck, filter) ⇒ Object



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1241

def do_call(tex,blck,filter)
#Dyndoc.warn "do_call",blck
  call=parse_args(blck[1],filter)
#puts "do_call";p call
#p args
  #this corrects a bad behavior of the scanner when the call directive is called directly.
  if blck[2]==:","
	var_block= blck[3..-1].unshift(:var)
  else
	var_block=blck[2..-1].unshift(:var)
  end
#puts "var_block";p var_block
  var,code=make_call(var_block,filter)
#puts "VAR"
#p code
#Dyndoc.warn "do_call:var",var

#p var
=begin
  if @meths.include? call
    @meth_var=(var[3..-1] ? var[0,1]+var[3..-1] : nil)
    var=var[0..1]
  end
=end
#puts "VAR2";p blck[2..-1].unshift(:var)
#puts "var block (AV)";p var

  #19/10/08: this complete the method name if necessary in order to provide args! Now, meth may be used with partial argument completed in the R spirit!
  call4args,vars4args=call.dup,[]
  isMeth=CallFilter.isMeth?(call)
##puts "#{call} isMeth => #{isMeth}!!!"
  if isMeth
#puts "meth:call=#{call}"
   obj=parse((var[1][0]==:named ? var[1][2..-1] : [var[1]] ),filter)
#puts "obj=#{obj}"
   if @vars.extract(obj) and @vars.extract(obj).respond_to? "keys"
#puts "extract obj";p @vars.extract(obj).keys
     vars4args=(@vars.extract(obj).keys.select{|e| e.is_a? String} - ["Renvir","ObjectName","Class"]).map{|e| "."+e}
	  #obj=parse([blck[2]],filter)
#p @vars[obj+".Class"]
     get_method(call4args,@vars[obj+".Class"].split(",")) if @vars[obj+".Class"]
     #=> call4args is modified inside get_method!!!
   end
  end

#puts "call4args=#{call4args}"
#p @args[call4args]
  args=(@args[call4args] ? @args[call4args].dup : nil)
  args+=vars4args if args
#puts "args";p args
#TODO: for method, args has to be initialized by finding the class of the object! Pb: how to know that it is a method => make a method in Call???
  b=(var.length==1 ? [] : make_var_block(var,filter,args))
#puts "var block (AP)";p b
  b,meth_args_b=CallFilter.argsMeth(call,b)
#puts "call";p call
#p @calls[call]
#Dyndoc.warn "var2 block",b
#p meth_args_b

#Dyndoc.warn "call:out",eval_CALL(call,b,filter)
  tex << eval_CALL(call,b,filter,meth_args_b,code)
end

#do_case(tex, blck, filter) ⇒ Object



1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1673

def do_case(tex,blck,filter)
  choices=parse_args(blck[1],filter).strip
#puts "choices";p choices
#p blck
  var="__elt_case__"
  tmp=choices.scan(/(^\w*):(.*)/)[0]
  var,choices=tmp[0].strip,tmp[1].strip if tmp
  choices=choices.split(",").map{|e| e.strip}
  choices.each{|choice|
    i=1
    todo,cond,all=true,false,false
    begin
      case blck[i+=1]
      when :when
#puts "when";p blck[i]
        c=parse_args(blck[i+=1],filter).strip.split(",").map{|e| e.strip}
#p "#{choice} in #{c.join(",")}"
        cond=(c.include? choice)
        all |= cond
      when :else
        cond=!all
      end
      i,*b2=next_block(blck,i)
      @vars[var]=choice
      tex << parse(b2,filter) if cond
#if cond
#  puts "tex in case";p tex
#end
    end while todo and i<blck.length-1
  }
#puts "tex in case";p tex
end

#do_def(tex, blck, filter) ⇒ Object



1115
1116
1117
1118
1119
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1115

def do_def(tex,blck,filter)
  call,code,rbEnvir=make_def(blck,filter)
#puts "do_def";p call;p code;p rbEnvir
  eval_func(call,code,rbEnvir)
end

#do_do(tex, blck, filter) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 181

def do_do(tex,blck,filter)
  i=-1
  begin
    case blck[i+=1]
      when :do,:<
        i,*b2=next_block(blck,i)
        parse(b2,filter)
      when :out,:>
        i,*b2=next_block(blck,i)
        tex << parse(b2,filter)
      when :nl,:"\\n"
        i,*b2=next_block(blck,i)
        tex << "\n" << parse(b2,filter)
    end
  end while i<blck.length-1
end

#do_document(tex, blck, filter) ⇒ Object



1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1469

def do_document(tex,blck,filter)
  i=0
#puts "document:blck"
#p blck
  begin
  	var,mode="",""
  	to_parse=true
#p i;p blck[i+1]
    case blck[i+=1]
    ########################## Commands
    when :main,:content
      var,mode=nil,:view
   when :require
     var,mode=nil,:load
    when :helpers
      var,mode,to_parse=nil,:helpers,true
    when :path
      var,mode=nil,:path
    when :first
#p blck[i+=1]
      var,mode,to_parse=nil,:first,false
    when :last
      var,mode,to_parse=nil,:last,false
    when :texinputs ## Latex
      var,mode,to_parse=nil,:texinputs,true
    when :optclass  ## Latex
      var,mode,to_parse=nil,:optclass,true
   ################################ MODEL VARIABLES
    when :class     ## Latex
     var,mode="_DOCUMENTCLASS_",""
    when :preamble
     var,mode="_PREAMBLE_","+"
   when :postamble
     var,mode="_POSTAMBLE_","+"
   when :style
     var,mode="_STYLEDOC_","+"
   when :package
     var,mode="_USEPACKAGE_","+"
   when :title
     var,mode="_TITLE_","+"
    when :before
      var,mode="_BEGINDOC_","+"
    when :after
      var,mode="_ENDDOC_","+"
    ### specific for HTML! Different from tilt mode!
    when :js
      var,mode="_JSDOC_","+"
    when :css
      var,mode="_STYLEDOC_","+"
    when :header
      var,mode="_HEADER_","+"
    when :footer
      var,mode="_FOOTER_","+"
    when :default
      var,mode=nil,:default
    when :cfg
      var,mode=nil,:cfg
   end
   i,*b2=next_block(blck,i)
#p b2
    res=parse(b2,filter) if to_parse
#p var
#puts "res";p res
   unless var
     case mode
     when :view
       tex << res
      when :default, :cfg
           ## nothing to do: used in document.rb
     when :load
       #puts "document:require";p  res
       eval_LOAD(res.strip.split("\n"),filter)
      when :helpers
        eval_LOAD_HELPERS(res.strip.split("\n"),filter)
     when :path
#Dyndoc.warn "document:path",res
        Dyndoc.user_root_doc=res.strip.split("\n").map{|e| e.strip unless e.strip.empty?}.compact.join(Dyndoc::PATH_SEP) unless res.strip.empty?

#### OBSOLETE from 27/09/2016!!!
### TODO: - operation possibly in init/config.rb
#           unless res.strip.empty?
# #p paths
# #Dyndoc.warn "root_doc",@tmpl_cfg[:root_doc]
# 	            rootpaths=@tmpl_cfg[:root_doc].split(Dyndoc::PATH_SEP)
# #Dyndoc.warn "rootpaths",rootpaths
# 	            newpaths=[]
# 	            paths.each{|e|
# 		            #if File.exist?(e)
# 		            #  newpaths << e
# 		            #els
#                 if e[0,1]=="-" and File.exist?(e[1..-1])
# 		              rootpaths.delete(e[1..-1])
# 		            elsif (ind=e.to_i)<0
# 		              rootpaths.delete_at(-ind-1)
#                 else
#                   newpaths << e
# 		            end
# 	            }
# 	            rootpaths=newpaths+rootpaths
# #Dyndoc.warn :last, rootpaths
# 	            @tmpl_cfg[:root_doc]=rootpaths.join(Dyndoc::PATH_SEP)
#	          end
     when :first
       Dyndoc.dyn_block[:first]=[] unless Dyndoc.dyn_block[:first]
       Dyndoc.dyn_block[:first]+=b2
#Dyndoc "firstblock#{i}",Dyndoc.dyn_block[:first]
     when :last
       Dyndoc.dyn_block[:last]=[] unless Dyndoc.dyn_block[:last]
       Dyndoc.dyn_block[:last]+=b2
#Dyndoc "lastblock#{i}",Dyndoc.dyn_block[:last]
      when :texinputs
        sep=(RUBY_PLATFORM=~/mingw32/ ? ";" : ":")
        ENV["TEXINPUTS"]="" unless ENV["TEXINPUTS"]
        ENV["TEXINPUTS"]+=sep+res.strip.split("\n").join(sep)
      when :optclass
        optclass=res.strip.split("\n").join(",").split(",").map { |e| "\""+e.strip+"\"" }.join(",")
        #puts "optclass";p optclass
        eval_RbCODE("_optclass_ << ["+optclass+"]",filter)
     end
   else
      res=res.strip if var=="_DOCUMENTCLASS_"
     eval_GLOBALVAR(var,res,filter,mode)
     eval_TEX_TITLE(filter) if  var=="_TITLE_" and @cfg[:format_doc]==:tex
   end
  end while i<blck.length-1
end

#do_eval(tex, blck, filter) ⇒ Object



963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 963

def do_eval(tex,blck,filter)
  i=0
#puts "do_eval";p blck
#puts '#{code}';p @vars["code"]
  i,*b2=next_block(blck,i)
  code=parse(b2,filter)
#puts "do_eval: code";p code
  Utils.escape_delim!(code)
#puts "do_eval2: code";p code
  mode=[]
  while code=~/^(atom|test|pre|last|raw)\|.*/
    code = code[($1.length+1)..-1]
    mode << $1.to_sym
  end
  code=Dyndoc::Utils.dyndoc_raw_text(code) if mode.include? :test
  code=Dyndoc::Utils.unprotect_dyn_block_for_atom(code) if mode.include? :atom
  #puts "do_eval:mode";p mode;p code
  #PUT THE FOLLOWING IN THE DOCUMENTATION:
  #puts "WARNING: {#dyn] accept :last and :raw in this order!" unless (mode - [:last,:raw]).empty?
  if mode.include? :pre
   tex2=prepare_output(code)
#puts "TOTO";p output_pre_model;p @pre_model
#puts "do_eval:PRE tex2";p tex2
  else
   code="{#document][#main]"+code+"[#}"
#puts "do_eval:code";p code
   tex2=parse(code,filter)
  end
  Utils.dyndoc_raw_text!(tex2) if mode.include? :last
#puts  "do_eval:tex2";p tex2
  tex2=Utils.dyndoc_raw_text_add(tex2) if mode.include? :raw
  tex << tex2
  if i<blck.length-1 and blck[i+=1]==:to
    i,*b2=next_block(blck,i)
    file=parse(b2,filter)
    unless file.empty?
      File.open(file,"w") do |f|
        f << tex2
      end
    end
  end
end

#do_for(tex, blck, filter) ⇒ Object

BIENTOT OBSOLETE!



1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1648

def do_for(tex,blck,filter)
  filter.outType=":rb"
  code=""
  # @forFilter is here to make available the dyn variables!
  @cptRbCode,@rbCode,@texRbCode,@forFilter=-1,{},{},filter unless @rbCode
  code << "if res; for " << parse_args(blck[1],filter).strip << " do\n"
  cpt=(@cptRbCode+=1) #local value to delete later!
#p cpt
  @rbCode[cpt]=[blck[2..-1].unshift(:blck)]
  @texRbCode[cpt]=tex
  code << "@texRbCode[#{cpt}] << parse(@rbCode[#{cpt}],@forFilter)\n"
  code << "end;end\n"
#p code
#puts "titi";p filter.envir.local
#p @rbCode[cpt]
#Dyndoc.warn :for_code,[code.encoding,code,__ENCODING__]
  @rbEnvir[0].eval(code)
  @rbCode.delete(cpt)
#p @rbCode
  @texRbCode.delete(cpt)
  filter.outType=nil
end

#do_format(tex, blck, filter) ⇒ Object



750
751
752
753
754
755
756
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 750

def do_format(tex,blck,filter)
  i=0
  i,*b2=next_block(blck,i)
  format=parse(b2,filter).strip
  puts "format=#{format}"
  @fmtOutput=format
end

#do_func(tex, blck, filter) ⇒ Object



1043
1044
1045
1046
1047
1048
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1043

def do_func(tex,blck,filter)
  call=parse_args(blck[1],filter)
  code=blck[2..-1]
#p "code func";p code
  eval_func(call,code)
end

#do_get(tex, blck, filter) ⇒ Object



2426
2427
2428
2429
2430
2431
2432
2433
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2426

def do_get(tex,blck,filter)
  blckname=filter.apply(blck[1][1])
  codename=filter.apply(blck[3][1])
  if @def_blck[-1] and @def_blck[-1].keys.include? codename
    @savedBlocks[blckname]=@def_blck[-1][codename]
#puts "do_get";p @savedBlocks[blckname]
  end
end

#do_hide(tex, blck, filter) ⇒ Object



915
916
917
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 915

def do_hide(tex,blck,filter)
  ## nothing to do!!!
end

#do_if(tex, blck, filter) ⇒ Object

## PB! never stop whenever condition is true => ex: if false (not exec), elsif true (exec), elsif false (not exec), else (is then exec)

def do_if(tex,blck,filter)
  i,cond=-1,true

#p blck

begin
  filter.outType=":rb"
  case blck[i+=1]
    when :if

#puts “do_if:blck”;p blck

      cond=eval_args(blck[i+=1],filter)
    when :unless
      cond=!eval_args(blck[i+=1],filter)
    when :elsif
      cond= (!cond and eval_args(blck[i+=1],filter))
      #p blck[i]
      #p eval_args(blck[i],filter)
      #p cond
    when :else
      cond= !cond
  end
  filter.outType=nil
  i,*b2=next_block(blck,i)
  tex << parse(b2,filter) if cond
end while i<blck.length-1

#puts “tex”;p tex

end


1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1625

def do_if(tex,blck,filter)
  i,cond=-1,nil
#p blck
  begin
    filter.outType=":rb"
    case blck[i+=1]
      when :if, :elsif
#puts "do_if:blck[i+1]";p blck[i+1]
        cond=eval_args(blck[i+=1],filter)
      when :unless
        cond=!eval_args(blck[i+=1],filter)
      when :else
        cond= true
    end
    filter.outType=nil
    i,*b2=next_block(blck,i)
    tex << parse(b2,filter) if cond
  end while !cond and i<blck.length-1
#puts "tex";p tex
end

#do_ifndef(tex, blck, filter) ⇒ Object



1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1006

def do_ifndef(tex,blck,filter)
  i=0
  i,*b2=next_block(blck,i)
  file=parse(b2,filter).strip
#p file
  if File.exist?(file)
    tex << File.read(file)
  elsif blck[i+=1]==:<<
#p blck[(i+1)..-1]
    tex2=parse(blck[(i+1)..-1],filter)
#p tex2
    file=file[1..-1] if file[0,1]=="!"
    File.open(file,"w") do |f|
      f << tex2
    end
    tex << tex2
  end
end

#do_input(tex, blck, filter) ⇒ Object



1025
1026
1027
1028
1029
1030
1031
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1025

def do_input(tex,blck,filter)
  tmpl=parse_args(blck[1],filter)
#p tmpl
  b=make_var_block(blck[2..-1].unshift(:var),filter)
#puts "do_input:b";p b
  tex << eval_INPUT(tmpl,b,filter)
end

#do_jl(tex, blck, filter) ⇒ Object



2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2138

def do_jl(tex,blck,filter)
  return unless Dyndoc.cfg_dyn[:langs].include? :jl
  ## jlBlock stuff
  ## Dyndoc.warn "do_jl",blck
  as_default_tmpl_mngr! if
  dynBlock=dynBlock_in_doLangBlock?(blck)
  if dynBlock
    @doLangBlock=[] unless @doLangBlock
    @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]}
    jlBlockId=@doLangBlock.length-1
  end
  ## Dyndoc.warn "do_jl";p blck
  filter.outType=":jl"
  # i=0
  # i,*b2=next_block(blck,i)
  # code=parse(b2,filter)
  blck=make_do_lang_blck(blck,jlBlockId,:jl)
  ## Dyndoc.warn "do_jl",blck
  code = parse_args(blck,filter)
  ## Dyndoc.warn "DO_JL",code
  ## Dyndoc.warn "@doLangBlock",@doLangBlock[0][:code] if @doLangBlock[0]
  process_jl(code)
  ## Dyndoc.warn "code_jl",code
  if [:"jl>"].include? blck[0]
    as_default_tmpl_mngr!
    tex << JLServer.outputs(code,:block => true)
  else
    JLServer.outputs(code)
  end
  ## revert all the stuff
  if dynBlock
    @doLangBlockEnvs -= @doLangBlock[jlBlockId][:env] #first remove useless envRs
    @doLangBlock.pop
  end
  filter.outType=nil
end

#do_jlverb(tex, blck, filter) ⇒ Object



1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1851

def do_jlverb(tex,blck,filter)
#      require 'pry'
#      binding.pry
  newblck=blck[0]
  filter.outType=":jl"
  i=0
  i,*b2=next_block(blck,i)
#puts "rverb:b2";p b2
  code=parse(b2,filter)
  i+=1

  mode=@cfg[:mode_doc]
  #p [mode,@fmt,@fmtOutput]
  mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
  mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
  if blck[i]==:mode
    i,*b2=next_block(blck,i)
    mode=parse(b2,filter).strip.to_sym
  end

  process_jl(code)
#puts "rverb:rcode";p code
  res=JLServer.echo_verb(code,@@interactive ? :raw : mode)
  require "dyndoc/common/uv" if @@interactive
  warn_level = $VERBOSE;$VERBOSE = nil
  tex << (@@interactive ? Uv.parse(res, "xhtml", File.join(Uv.syntax_path,"julia.syntax") , false, "solarized",false) : res )
  $VERBOSE = warn_level
#puts "rverb:result";p res

  filter.outType=nil
end

#do_keys(tex, blck, filter) ⇒ Object



2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2228

def do_keys(tex,blck,filter)
  arg=parse_args(blck[1],filter).strip
#puts "do_keys: @keys";p @keys
  #Register!
  if arg[0..8]=="register:"
#puts ">>>>>>>>> Keys->Register";p arg
#puts "@keys:";p @keys
   $dyn_keys={} unless $dyn_keys
   unless $dyn_keys[:crit]
     $dyn_keys[:crit]={:pre=>[],:user=>[]}
     $dyn_keys[:index]=$dyn_keys[:crit][:user]
     ## predefined
     $dyn_keys[:crit][:pre]=["order","required"]
     $dyn_keys["order"]={:type=>:order}
     $dyn_keys["required"]={:type=>:required}
     ## user defined
     $dyn_keys[:alias]=[]
     $dyn_keys[:current]=[]
     $dyn_keys[:begin]=[]
     $dyn_keys[:end]=[]
   end
   arg[9..-1].split(":").each{|e|
     type=e.split("=").map{|e2| e2.strip}
     res={:type=>type[1].to_sym}
     crit,*aliases=type[0].split(",").map{|e2| e2.strip}
     $dyn_keys[:index] << crit
     $dyn_keys[crit]=res
     #which criteria need some further treatments
     $dyn_keys[:begin] << crit if [:section].include? res[:type]
     $dyn_keys[:end] << crit if [:section].include? res[:type]
     unless aliases.empty?
       $dyn_keys[:alias]+=aliases
       aliases.each{|e| $dyn_keys[e]=crit}
     end
   }
   $dyn_keys[:index] << "order" << "required"
#puts "$dyn_keys";p $dyn_keys
#puts "Before: @keys:";p @keys
#p @init_keys
   @keys.merge!(KeysManager.make_keys(@init_keys)) if @init_keys
#puts "After make_keys: @keys";p @keys #if @tmpl_cfg[:debug]
#p @init_keys
  #Set!
  elsif arg[0..3]=="set:"
##puts ">>>>>>>>> Keys->Set"
   @init_keys=KeysManager.init_keys([arg[4..-1].strip])
   @keys.merge!(KeysManager.make_keys(@init_keys))
  #Require!
  elsif arg[0..7]=="require:"
##puts ">>>>>>>>> Keys->Require"
   $dyn_keys[:require]=":"+arg[8..-1]

  #Select!
  else
#puts ">>>>>>>>> Keys->Select"
   to_merge=(arg[0,1]=="+")
   if $dyn_keys[:current].empty?
     mode_keys=:init
     $dyn_keys[:cpt]=0
     $dyn_keys[:tex]={}
     lock_parent=nil unless to_merge
   else
     mode_keys=:fetch
     lock_parent=$dyn_keys[:current][-1] unless to_merge
     $dyn_keys[:cpt]+=1
   end

#puts "mode_keys";p mode_keys
#p arg
   arg=arg[1..-1] if to_merge
   lock=KeysManager.make(arg)
   lock=KeysManager.var_names(lock)
   KeysManager.simplify(lock) #simplify default value!
   lock_keys_orig=lock.keys
   if to_merge
     KeysManager.merge(lock)
   elsif lock_parent
     KeysManager.merge(lock,lock_parent)
   end
#p lock
   KeysManager.make_title(lock)
#p $dyn_keys[:title]

#puts "do_keys:lock";p lock
   # remember the last lock!
   $dyn_keys[:lastlock]=lock
   $dyn_keys[:current] << lock
##IMPORTANT: put here and not after the parsing otherwise cpt increases abnormally.
   unless mode_keys==:init
     tex << "__DYNKEYS#{$dyn_keys[:cpt]}__"
   end
   KeysManager.begin(lock_keys_orig,lock,@keys)
   @lock=lock #to use inside dyndoc!
   $dyn_keys[:tex][$dyn_keys[:cpt]] = {:lock=>lock,:content=>parse([blck[2..-1].unshift(:blck)],filter)}
   if mode_keys==:init
#puts "$dyn_keys[:tex]";p $dyn_keys[:tex]
     texAry=keys_recurse($dyn_keys[:tex][0])
#puts "texAry";p texAry
      texAry=[texAry] unless texAry.is_a? Array
     keys_print(tex,texAry)
   end
   KeysManager.end(lock_keys_orig,lock,@keys)
   $dyn_keys[:current].pop
  end
end

#do_list(tex, blck, filter) ⇒ Object



19
20
21
# File 'lib/dyndoc/plugins/tex/tex_parse_do.rb', line 19

def do_list(tex,blck,filter)

end

#do_loop(tex, blck, filter) ⇒ Object



1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1447

def do_loop(tex,blck,filter)
  ## last executing !!!
  ## To think about environment!!!
  cond=true
#p blck
  while cond
    i=-1
    begin

      case blck[i+=1]
      when :loop
        i,*b2=next_block(blck,i)
        tex << parse(b2,filter)
      when :break
        cond=!eval_args(blck[i+=1],filter)
        i,*b2=next_block(blck,i)
        tex << parse(b2,filter) if cond
	  end
	end while cond and i<blck.length-1
  end
end

#do_m(tex, blck, filter) ⇒ Object



2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2184

def do_m(tex,blck,filter)
  newblck=blck[0]
# Dyndoc.warn "do_m";p blck
  filter.outType=":m"
  i=0
  i,*b2=next_block(blck,i)
  code=parse(b2,filter)

  #p ["Mathematica",code]
  code='TeXForm['+code+']' if blck[0]==:"M>"
  tex2=Dyndoc::Converter.mathlink(code)
  if [:"M>",:"m>"].include? blck[0]
    tex << (blck[0]==:"M>" ? ('$'+tex2+'$').gsub("\\\\","\\") : tex2 )
  end
  filter.outType=nil
end

#do_main(tex, b, filter) ⇒ Object



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 758

def do_main(tex,b,filter)
  #OLD: @userTag.evalUserTags(tex,b[1],filter)
  #NEW: simply apply the filter on the text
  #b[1]="" unless b[1]
#puts "do_main";p b[1]
  res=filter.apply(b[1])
  unless res.scan(/^__RAW__/).empty?
    res=Utils.protect_format_blocktext(res)
  else
  res=Utils.format_blocktext(res)
  end
#puts res
  tex << res
  #TODO: maybe propose a language like textile to be converted in any format
end

#do_meth(tex, blck, filter) ⇒ Object



1121
1122
1123
1124
1125
1126
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1121

def do_meth(tex,blck,filter)
#puts "do_meth";p blck
  call,code=make_def(blck,filter)
#puts "do_meth";p call;p code
  eval_meth(call,code)
end

#do_new(tex, blck, filter) ⇒ Object



1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1128

def do_new(tex,blck,filter)
  #first declaration of the object
#puts "do_new";p blck
  var=parse_args(blck[1],filter).strip
  var = var[1..-1] if var[0,1]==":"
  i=2
  if blck[i]==:of
    i,*b2=next_block(blck,2)
    klass=parse(b2,filter).split(",").map{|e| e.strip}.join(",")
  else
    return
  end
  i+=1
  inR=@rEnvir[0]
  if blck[i]==:in
    i,*b2=next_block(blck,i)
#p b2
#p filter.envir.local["self"]
    inR=parse(b2,filter).strip
#p inR
    inR,parentR=inR.split("<").map{|e| e.strip}
    parentR=@rEnvir[0] unless parentR or  RServer.exist?(parentR)
#p parentR
    RServer.new_envir(inR,parentR) unless RServer.exist?(inR)
    i+=1
  end
#puts "do_new:var,klass";p var;p klass
=begin
  b2=blck[4..-1].map{|e|
    if e.is_a? Array and e[0]==:named
      e[1]=var+"."+e[1]
    end
    e
  }
=end
  b2=[[:named,var+".Class",[:main,klass]]]
  b2+=[:",",[:named,var+".Renvir",[:main,inR]]]
#puts "do_new:b2";p b2
  b=make_var_block(b2.unshift(:var),filter)
#puts "do_new:var";p b
  eval_VARS(b,filter)
#puts "do_new:eval_VARS";p filter.envir.local
  # and then call of the initialize method here called new.(Class)
=begin
  call="new"
  bCall=get_method(call,get_klass(klass))
p call
=end
  b2=[] << :call<< [:args,[:main,"new"]] << [:named,"self",[:main,var]]
#p blck[4..-1]
  b2+=blck[i..-1]
#puts "do_new:new b2";p b2
  tex << parse([b2],filter)
  #tex << eval_CALL("new",b,filter)
end

#do_newBlck(tex, b, filter) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/extension.rb', line 151

def do_newBlck(tex,b,filter)
  blckMngr=BlckMngr.new(self,b,tex,filter)
  blckname=b[1][1].strip
  ##p blckname
  if ["saved"].include? blckname
    Dyndoc.warn "Warning: Impossible to redefine an existing instruction!"
  end
  #puts "new_blck:b";p b
  blckMngr.pos=1
  items=[]
  return unless [:blck,:aggregate].include? blckMngr.next_tag
  @@newBlcks[blckname]={}
  if blckMngr.next_tag==:aggregate
    blckMngr.next_tag!
    @@newBlcks[blckname][:aggregate]= blckMngr.next_tag![1].strip.split(",")
  end
  while blckMngr.next_tag! == :blck and !blckMngr.at_end?
    items << (item=blckMngr.next_tag![1].strip)
    blcks=[]
    while (blckMngr.next_tag != :blck) and !blckMngr.at_end?
      blcks << blckMngr.next_tag!
    end
    if [":pre",":post"].include? item
      @@newBlcks[blckname][item]=blcks
    else
      i,subBlcks=-1,{}
      while ([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1)

        subname=blcks[i+=1]
        subBlcks[subname]=[]
        while !([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1)
          subBlcks[subname] << blcks[i+=1]
        end
      end
      @@newBlcks[blckname][item]=subBlcks
    end

  end

  ## declare the new block!
  add_dtag({
  :instr=>[blckname],
  :keyword_reg=>{
    blckname.to_sym=> '[%.\w,><?=+:-]+'
  },
  :with_tagblck=>[blckname.to_sym],
  },"blck") #alias of blck!
#=begin
  (items-[":pre",":post"]).each do |item|
    #p @@newBlcks[blckname][item]

    if @@newBlcks[blckname][item][:do_code]
      blckRbCode=
%Q[def do_blck_#{blckname}_#{item}(tex,blck,filter)
##Dyndoc.warn :newBlck, blck
  blckMngr=BlckMngr.new(self,blck,tex,filter)
  ## the next code is automatically generated!
  #{@@newBlcks[blckname][item][:do_code][0][1]}
end]
      #Dyndoc.warn :blckRbCode, blckRbCode
      Dyndoc::Ruby::TemplateManager.module_eval(blckRbCode)
      #Dyndoc.warn :methods, methods.sort
    end
  end
#=end
  #p methods.sort
  #Dyndoc.warn "newBlck[\"#{blckname}\"]",@@newBlcks[blckname]
end

#do_opt(tex, blck, filter) ⇒ Object



2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2397

def do_opt(tex,blck,filter)
#p blck
#p parse(blck[1..-1],filter)
#p parse(blck[1..-1],filter).split(",").map{|e| e.strip}
#p @tags
  taglist=parse(blck[1..-1],filter).strip

  taglist.split(",").map{|e| e.strip}.each{|tag|
    if tag[0,1]=="-"
      @tags.delete(TagManager.init_input_tag(tag[1..-1]))
    else
    tag=tag[1..-1] if tag[0,1]=="+"
    @tags << TagManager.init_input_tag(tag)
    end
  }
#puts "ici";p @tags
end

#do_part(tex, blck, filter) ⇒ Object



2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2442

def do_part(tex,blck,filter)
  i=0
  i,*b2=next_block(blck,i)
  file=parse(b2,filter).strip
  # prepare the filename
  file,part=file.split("|").map{|e| e.strip}
  file,out=file.split("#").map{|e| e.strip}
  out=(out ? out.to_sym : @cfg[:format_doc])
  out=:dyn if [:*,:all].include? out
  file=File.join("part",file+"_part"+Dyndoc::EXTS[out])
  # part tags prepended by "part:"
  part=TagManager.make_tags(part.split(",").map{|e| "part:"+e}.join(",")) if part
  #
  if File.exist?(file) and (!part or !TagManager.tags_ok?(part,@tags))
  	puts "partial #{file} loaded"
  	tex << File.read(file)
  else
  	puts "partial #{file} generated"
  	tex2=parse([blck[(i+1)..-1].unshift(:blck)],filter)
  	#puts tex2
  	Dyndoc.make_dir("part")
  	File.open(file,"w") do |f|
      f << tex2
    end
    tex << tex2
  end
end

#do_r(tex, blck, filter) ⇒ Object



1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1706

def do_r(tex,blck,filter)
  newblck=blck[0]
#puts "do_r";p blck
  filter.outType=":r"
  i=0
  i,*b2=next_block(blck,i)
  code=parse(b2,filter)
  inR=nil
  if blck[i+=1]==:in
    i,*b2=next_block(blck,i)
    inR=parse(b2,filter).strip
    RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
  end
  @rEnvir.unshift(inR) if inR
#puts "do_r:code";p code;p eval_RCODE(code,filter,true,true) if newblck==:"r>"
  if newblck==:"r>"
    tex2=eval_RCODE(code,filter,:pretty=> true,:capture=> true)
    ## Dyndoc.warn "rrrrrrrrrrrrrrr: tex2", tex2
    tex << tex2
  else
	# pretty is put to false because prettyNum does not accept empty output or something like that!
    eval_RCODE(code,filter,:pretty=> false)
  end
  @rEnvir.shift if inR
  filter.outType=nil
end

#do_R(tex, blck, filter) ⇒ Object



2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2076

def do_R(tex,blck,filter)
  ## rBlock stuff
  # Dyndoc.warn "do_R",blck
  dynBlock=dynBlock_in_doLangBlock?(blck)
  if dynBlock
    @doLangBlock=[] unless @doLangBlock
    @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]}
    rBlockId=@doLangBlock.length-1
  end
  ## this is R code!
  filter.outType=":r"
  ## Dyndoc.warn "do_R",filter.envir.local
  blck=make_do_lang_blck(blck,rBlockId,:R) #true at the end is for R!
  ## Dyndoc.warn "do_R",blck
  code = parse_args(blck,filter)
  ## Dyndoc.warn "R code="+code
  process_r(code)
  ## Dyndoc.warn "R CODE="+code

  if blck[0]==:"R>"
    ## Dyndoc.warn "R>",code
    as_default_tmpl_mngr!
    tex2=eval_RCODE(code,filter,:blockR => true)
    ## Dyndoc.warn "RRRRRRRRRRRRRRRR: tex2",tex2
    tex << tex2
  else
    # pretty is put to false because prettyNum does not accept empty output or something like that!
    eval_RCODE(code,filter,:pretty=> false)
  end
  ## revert all the stuff
  if dynBlock
    @doLangBlockEnvs -= @doLangBlock[rBlockId][:env] #first remove useless envRs
    @doLangBlock.pop
  end
  filter.outType=nil
  ## Dyndoc.warn "SORTIE R!",dynBlock,blck,tex2
end

#do_rb(tex, blck, filter) ⇒ Object

begin NEW STUFF!!!



2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2005

def do_rb(tex,blck,filter)
  require 'stringio'
  @rbIO=[] unless @rbIO
  @rbIO << (blck[0]==:"rb>" ? StringIO.new : STDOUT)
  $stdout=@rbIO[-1]

  ## Dyndoc.warn "blck",blck
  ## Dyndoc.warn "do_rb binding",binding,local_variables
  dynBlock=dynBlock_in_doLangBlock?(blck)
  if dynBlock
    @doLangBlock=[] unless @doLangBlock
    @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} #@filterRbBlock}
    rbBlockId=@doLangBlock.length-1
  end
  ## this is ruby code!
  filter.outType=":rb"
  ## Dyndoc.warn "do_rb",filter.envir.local
  blck=make_do_lang_blck(blck,rbBlockId)
  ## Dyndoc.warn "do_rb",blck
  code = parse_args(blck,filter)
  ## Dyndoc.warn "rb code="+code
  process_rb(code) if Utils.raw_code_to_process
  ## Dyndoc.warn "rb CODE="+code
  as_default_tmpl_mngr! if blck[0]==:"rb>"
  res=eval_RbCODE(code,filter)

  if blck[0]==:"rb>"
    tex2=@rbIO.pop.string
#Dyndoc.warn "res",res
#Dyndoc.warn "RbRbRbRbRbRbRb:", (tex2.empty? ? res : tex2)
    tex << (tex2.empty? ? res : tex2)
  else
    @rbIO.pop
  end

  ## revert all the stuff
  if dynBlock
    @doLangBlockEnvs -= @doLangBlock[rbBlockId][:env] #first remove useless envRs
    @doLangBlock.pop
  end
  $stdout=@rbIO.empty? ? STDOUT : @rbIO[-1]

  filter.outType=nil
  ## Dyndoc.warn "SORTIE RB!",dynBlock,blck,tex2
end

#do_rbverb(tex, blck, filter) ⇒ Object



1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1818

def do_rbverb(tex,blck,filter)
#      require 'pry'
#      binding.pry
  newblck=blck[0]
  filter.outType=":rb"
  i=0
  i,*b2=next_block(blck,i)
#puts "rverb:b2";p b2
  code=parse(b2,filter)
  i+=1

  mode=@cfg[:mode_doc]
  #p [mode,@fmt,@fmtOutput]
  mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
  mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
  if blck[i]==:mode
    i,*b2=next_block(blck,i)
    mode=parse(b2,filter).strip.to_sym
  end

  process_rb(code)
  ## Dyndoc.warn "rverb:rcode";p code
  res=RbServer.echo_verb(code,@@interactive ? :raw : mode,@rbEnvir[0])
  ## Dyndoc.warn "rbverb:res",res
  require "dyndoc/common/uv" if @@interactive
  warn_level = $VERBOSE;$VERBOSE = nil
  tex << (@@interactive ? Uv.parse(res, "xhtml", File.join(Uv.syntax_path,"ruby.syntax") , false, "solarized",false) : res )
  $VERBOSE = warn_level
#puts "rverb:result";p res

  filter.outType=nil
end

#do_renv(tex, blck, filter) ⇒ Object



1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1733

def do_renv(tex,blck,filter)
  inR=parse_args(blck,filter).strip
#p inR
  mode=:ls
  case inR[-1,1]
  when "+"
    mode=:attach
    inR=inR[0...-1]
  when "-"
    mode=:detach
    inR=inR[0...-1]
  when "?"
    mode=:show
    inR=inR[0...-1]
  end
  unless [:detach,:ls].include? mode
#puts "#{inR} EXIST?";p RServer.exist?(inR);"print(ls(.GlobalEnv$.env4dyn))".to_R
    RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
  end
  case mode
  when :ls
    unless inR.empty?
      begin
        inRTmp=eval(inR)
        inR=(inRTmp.is_a? Regexp) ? inRTmp : /#{inR}/
      rescue
        inR=/#{inR}/
      end
    end
    tex << ((inR.is_a? Regexp) ? @rEnvir.select{|rEnv| rEnv=~ inR} : @rEnvir ).join(",")
  when :attach
    @rEnvir.unshift(inR) unless inR.empty?
  when :detach
    if inR.empty?
      @rEnvir.shift
    else
      if w=@rEnvir.index(inR)
        @rEnvir.delete_at(w)
      end
    end
  when :show
    tex << (inR.empty? ? @rEnvir[0] : (@rEnvir[0]==inR).to_s)
  end
end

#do_require(tex, blck, filter) ⇒ Object



1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1033

def do_require(tex,blck,filter)
  ## just load and parse : read some FUNCs and EXPORT some variables
  ## in the header
#Dyndoc.warn "do_require",blck
#p parse_args(blck,filter)
  tmpl=parse_args(blck,filter).strip.split("\n")
#Dyndoc.warn "require",tmpl
  eval_LOAD(tmpl,filter)
end

#do_rverb(tex, blck, filter) ⇒ Object



1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1778

def do_rverb(tex,blck,filter)
#      require 'pry'
#      binding.pry
  newblck=blck[0]
  filter.outType=":r"
  i=0
  i,*b2=next_block(blck,i)
#Dyndoc.warn "rverb:b2",b2
  code=parse(b2,filter)
  i+=1
  inR=nil
  if blck[i]==:in
    i,*b2=next_block(blck,i)
    inR=parse(b2,filter).strip
    RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR)
    i+=1
  end
  mode=@cfg[:mode_doc]
  #p [mode,@fmt,@fmtOutput]
  mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput
  mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode
  if blck[i]==:mode
    i,*b2=next_block(blck,i)
    mode=parse(b2,filter).strip.to_sym
  end
  mode=:default if  newblck==:rout #or newblck==:"r>>"
  @rEnvir.unshift(inR) if inR
  process_r(code)
#Dyndoc.warn "rverb:rcode",code,@@interactive
  res=RServer.echo_verb(code,@@interactive ? :raw : mode,@rEnvir[0], prompt: (@@interactive ? "R" : ""))
  require "dyndoc/common/uv" if @@interactive

  warn_level = $VERBOSE;$VERBOSE = nil
  tex << (resUV=(@@interactive ? Uv.parse(res.force_encoding("utf-8"), "xhtml", File.join(Uv.syntax_path,"r.syntax") , false, "solarized",false) : res.force_encoding("utf-8") ))
  $VERBOSE = warn_level
#Dyndoc.warn "rverb:result",resUV
  @rEnvir.shift if inR
  filter.outType=nil
end

#do_set(tex, blck, filter) ⇒ Object



907
908
909
910
911
912
913
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 907

def do_set(tex,blck,filter)
  i,*b2=next_block(blck,1)
#puts "set";p blck[1]
#p b2
#p parse_args(blck[1],filter)
  eval_SET(parse_args(blck[1],filter),parse(b2,filter),filter) #,true)
end

#do_sh(tex, blck, filter) ⇒ Object



2175
2176
2177
2178
2179
2180
2181
2182
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2175

def do_sh(tex,blck,filter)
#Dyndoc.warn "do_sh: blck ";p blck[1..-1]
  filter.outType="none"
  code=parse(blck[1..-1],filter)
  %x[ #{code} ]
#Dyndoc.warn "do_sh: code ";p code
  filter.outType=nil
end

#do_style(tex, blck, filter) ⇒ Object



1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1355

def do_style(tex,blck,filter)
  call=parse_args(blck[1],filter)
#p call
  call=call.split(":")
#puts "style:call";p call
#p @styles
#p blck[2..-1]
  if call[0][0,1]=~/[A-Z]/
  	# style declaration
  	unless call[1]
  	  # instance of new object
  	  b=make_style_new(call[0],blck[2..-1])
  	  do_new(tex,b,filter)
  	  style=parse_args(b[1],filter)
  #p style
  	  register_style_cmds(@styles[:class][call[0]],style)
  	else
  	  case call[1]
  	  when "new"
  	    # constructor style method called instance is demanded
  	    register_style_init
  	    b=make_style_meth("new",call[0],blck[2..-1])
        #p b
  	    do_meth(tex,b,filter)
  	    b=make_style_new(call[0],[[:main,call[0][0,1].downcase+call[0][1..-1] ]]) #,:<])
        #p b
        #p filter.envir
  	    do_new(tex,b,filter)
        #p filter.envir
  	  else
        #puts "register style meth:#{call[1]}.#{call[0]}"
  	    # style cmd method
  	    b=make_style_meth(call[1],call[0],blck[2..-1])
  	    do_meth(tex,b,filter)
  	    # register a new meth for this new Style Class
  	    register_style_meth(call[0],call[1])
  	    register_style_cmds([call[1]],call[0][0,1].downcase+call[0][1..-1])
  	  end
  	end
  elsif call[0]=="style"
  	if call[1]=="cmds"
  	  style=blck[2][1].strip
  	  cmds=(blck[4] ? blck[4][1] : nil)
  	  cmds=cmds.split(",").map{|cmd| cmd.strip} if cmds
  	  if @vars[style+".Class"]
  	    klass=@vars[style+".Class"][5..-1]
  	    cmds=(cmds ? cmds & @styles[:class][klass] : @styles[:class][klass] )
  	    register_style_cmds(cmds,style,true)
  	  end
  	elsif call[1]=="alias" and @styles
  	    aliases=parse([blck[2]],filter).split(",")
  	    value=parse([blck[4]],filter)
  	    aliases.each{|a|
  	      @styles[:alias][a]=value
  	    }
  	end
  else
  	# cmd style call
  	no_obj=call.length==1
  	obj,cmds=(no_obj ? [nil]+call : call)
=begin
  	if obj and !@vars[obj+".Class"]
  	  cmds.unshift(obj)
  	  obj=nil
  	end
=end
  	#recursive alias replacement

  ##TODO: it seems that no call in new is possible!
  #p cmds
  #register_style_init
  #p @styles
  	while !(aliases=(cmds.split("|") & @styles[:alias].keys)).empty?
  	  aliases.each{|a| cmds.gsub!(a,@styles[:alias][a])}
  	end
  #puts "cmds";p cmds
  	cmds=cmds.split("|")
  #puts "cmds2";p cmds
  #TODO: facility to define alias for style!?!?!
  	b=blck[2..-1]
  #p cmds
  	cmds.reverse.each{|cmd|
  	  obj=@styles[:cmd][cmd] if no_obj
  #p @filter.envir
  	  b=make_style_call(cmd,obj,b)
  #p b
  	}
  #puts "style:call";p b
  	do_call(tex,b,filter)
  end
end

#do_super(tex, blck, filter) ⇒ Object



1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1184

def do_super(tex,blck,filter)
  #first declaration of the object
  var=parse_args(blck[1],filter).strip
  i=2
  parent=1
  if blck[i]==:parent
    i,*b2=next_block(blck,2)
    parent=parse(b2,filter).to_i
    parent=1 if parent==0
    i+=1
  end
  #find next class!
  super_meth=get_super_method(parent)
#p super_meth
  return "" unless super_meth
  #build the updtaed block
  b2=[] << :call<< [:args,[:main,super_meth]] << [:named,"self",[:main,var]]
  b2+=blck[i..-1]
#puts "super b2";p b2
  tex << parse([b2],filter)
  #tex << eval_CALL("new",b,filter)
end

#do_tags(tex, blck, filter) ⇒ Object



2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2201

def do_tags(tex,blck,filter)
  i=0
#puts "do_tags"
#p @tags
#p blck.length
  if blck.length==1
    ##p @tags.map{|t| t.inspect}.join(",")
    tex << @tags.map{|t| t.inspect}.join(",")
    return
  end
  begin
    case blck[i+=1]
    when :when
      tags=TagManager.make_tags(parse_args(blck[i+=1],filter).strip)
    else
      puts "ERROR! Only [#when] tag! ";p blck[i]
    end
#p part_tag
    i,*b2=next_block(blck,i)
    # fparse if allowed!
    if TagManager.tags_ok?(tags,@tags)
#p b2
      tex << parse(b2,filter)
    end
  end while i<blck.length-1
end

#do_title(tex, blck, filter) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dyndoc/plugins/tex/tex_parse_do.rb', line 8

def do_title(tex,blck,filter)
=begin
  mode=""
  mode=filter.apply(splitter.key[i].strip).downcase if splitter.key[i]
  ## apply R filtering
  txt=filter.apply(b[1...-1].join("\n"))
  ## _TITLE_ is redefined!
  eval_TITLE(txt,filter,mode)
=end
end

#do_txt(tex, blck, filter) ⇒ Object



919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 919

def do_txt(tex,blck,filter)
#p blck
  code=blck[1].dup
#puts "do_txt:code";p code
##p @curCmd

  ## to name some code block!
  #name=""
  ##JUST IN CASE, OLD: if code=~ /^\s*([\w\.\-_:]*)\s*\[(.*)\]\s*$/m #multiline!
  if code=~ /^\s*([\w\.\-_:]+)\s*\[(.*)\]\s*$/m #multiline!
    name,code=$1.strip,$2
    ##code="["+code+"]" if name.empty?
  end
  #puts "do_txt:name,code";p [name,code]
  ##
  @unprotected_txt=code
  @protected_txt=Utils.protect_txt_block(code)
#puts "do_txt:@protected_code";p @protected_code
#puts "do_txt2:code";p name;p code
  res = (@curCmd=="txt" ? code : @protected_txt )
  #puts "res";p res
  if name #unless name.empty?
#Dyndoc.warn "txt:name",[name,code]
    ## the following is only applied when @curCmd==">" or maybe ">>"
    filter.envir[name]=[code]
    outType=nil
    outType=filter.outType+"=" if filter.outType
    tex << filter.convert(name+"!",outType) if @curCmd==">"  #useful for templating as in Table.dyn
  else
#Dyndoc.warn  "res",res
    tex << res
  end
end

#do_var(tex, blck, filter) ⇒ Object



899
900
901
902
903
904
905
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 899

def do_var(tex,blck,filter)
#p blck
  b=make_var_block(blck,filter)
#puts "do_var:b";p b
#puts "do_var:filter.local";p filter.envir.local
  eval_VARS(b,filter)
end

#do_verb(tex, blck, filter) ⇒ Object



953
954
955
956
957
958
959
960
961
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 953

def do_verb(tex,blck,filter)
  i=0
  i,*b2=next_block(blck,i)
  code=parse(b2,filter)
  Utils.escape!(code,[["{","__OPEN__"],["}","__CLOSE__"]])
  tex << Dyndoc::VERB[@cfg[:format_doc]][:begin] << "\n"
  tex << code.strip << "\n"
  tex << Dyndoc::VERB[@cfg[:format_doc]][:end] << "\n"
end

#do_yield(tex, blck, filter) ⇒ Object



2435
2436
2437
2438
2439
2440
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2435

def do_yield(tex,blck,filter)
#p blck
#p parse(blck[1..-1],filter)
  codename=parse(blck[1..-1],filter)
  make_yield(tex,codename,filter)
end

#dynBlock_in_doLangBlock?(blck) ⇒ Boolean

Returns:

  • (Boolean)


1883
1884
1885
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1883

def dynBlock_in_doLangBlock?(blck)
  blck.map{|b| b.respond_to? "[]" and [:>,:<,:<<].include? b[0] }.any?
end

#dyndoc_mode=(mode) ⇒ Object



192
193
194
# File 'lib/dyndoc/base/tmpl/manager.rb', line 192

def dyndoc_mode=(mode)
  @dyndocMode=mode
end

#echo_verb(txt, verbatim = true, env = "Global") ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/dyndoc/plugins/tex/tex_eval.rb', line 12

def echo_verb(txt,verbatim=true,env="Global")
  txtout=Dyndoc::RServer.echo(txt,env)
  header= verbatim and txtout.length>0
  out=""
  out << BEGINVERB << "\n" if header
  out << txtout
  out << ENDVERB << "\n" if header
  out
end

#eval_args(blck, filter) ⇒ Object



150
151
152
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 150

def eval_args(blck,filter)
  @rbEnvir[0].eval(parse(blck[1..-1],filter))
end

#eval_BINDING(env, b, filter) ⇒ Object



40
41
42
43
44
# File 'lib/dyndoc/base/tmpl/eval.rb', line 40

def eval_BINDING(env,b,filter)
  eval_VARS(b,filter)
  @envirs[env]=filter.envir.local
#p "BINDING#{env}";p filter; p "\n"
end

#eval_CALL(call, b, filter, meth_args_b = nil, blckcode = nil) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 259

def eval_CALL(call,b,filter,meth_args_b=nil,blckcode=nil)
  txt=""
#puts "eval_CALL:call,b,filter,@calls";p call;p b
#p filter.envir
#p @calls
#p @calls.keys.sort
#puts "meth_args_b"; p meth_args_b
  call,export=call[0...-1],true if call[-1,1]=="!"
  if @calls.keys.include? call
    # envir task
   b2=b.map{|e| filter.apply(e)} if b and b.length>0
#puts "b2 init";p b2
   dict2={:prev=>filter.envir.local}

   if b and b.length>0
#puts "b2";p b2;p b2.map{|e| e.split("\n")}.flatten
     dict=FilterManager.eval_dict(b2.map{|e| e.split("\n")}.flatten)
#puts "dict";p dict
     dict.each{|k,v| 
       dict2[k.to_s]=v
     }
   end
#puts "dict2";p dict2
#p dict2["envir"] #if dict2["envir"]
    ## local consideration: special ":envir"
    dict2[:prev]=@envirs[dict2["envir"][0]] if dict2["envir"] and (dict2["envir"][1].include? :local) and @envirs[dict2["envir"][0]] and (@envirs[dict2["envir"][0]].is_a? Hash)
#p dict2 if dict2["envir"] and (dict2["envir"][1].include? :local) and @envirs[dict2["envir"][0]] and (@envirs[dict2["envir"][0]].is_a? Hash)
#puts "CALL:#{call}";p @global
#puts "dict2[\"envir\"]?";p dict2
    # new filter to evualate the call
   filter2=FilterManager.new({:global=>@global},self)

#puts "filter2.envir";p filter2.envir

    # init body call
    bCall=@calls[call]
    #is a method ? 
    tmpCall=call.split(".")
    isMeth=(bCall==:meth) or (tmpCall.length==2 and (@meths.include? tmpCall[0]))
    # assign self if exists in :prev?
#puts "Assign";p dict2["self"]; p dict2[:prev]
#puts "isMeth?";p isMeth
    if isMeth and dict2["self"]
#puts "dict2";p dict2 
#and dict2[:prev][objName=dict2["self"][0]]
      objName=dict2["self"][0]
#puts "objName";p objName
      objName=objName[1..-1] if objName[0,1]==":"
      objName="self"+objName if objName[0,1]=="."
#puts "objName2";p objName
      #filter2.envir.local["self"]=dict2[:prev][objname]
      objKeys=Envir.to_keys(objName)
#puts "objKeys";p objKeys
#puts "dict2[:prev]";p dict2[:prev]
#puts "Envir.keys_defined.";p Envir.keys_defined?(dict2[:prev],objKeys)
	  # RMK: 5/9/08 it seems that Envir.get_elt! is only used here and replaced by Envir.keys_defined? newly created!
	  #Envir.get_elt!(dict2[:prev],objKeys)

     # find in dict2[:prev] and their sub :prev
     dictObj=dict2[:prev]
     begin
       objEnv=Envir.elt_defined?(dictObj,objKeys)
       dictObj=dictObj[:prev]
     end while !objEnv and dictObj
#p @klasses  
#p @global
#puts "objEnv(local)";p objEnv
     # otherwise, find in @global envir
     objEnv=Envir.elt_defined?(@global,objKeys) unless objEnv
#puts "objEnv(global)";p objEnv 
     # otherwise return empty env
     objEnv={} unless objEnv
#puts "objEnv";p objEnv #at least {} and then nonempty!
#puts "objKeys[0]";p objKeys[0]
      if objKeys[0]=="self"
#p dict2
#p @vars
        objName=([dict2[:prev]["self"]["ObjectName"][:val][0]]+objKeys[1..-1]).join(".")
#puts "objName4Self";p objName 
      end
##PB HERE: objEnv does not return the right envir because the object is in :prev and then objEnv[objKeys[-1]] is not correct!
# filter2.envir.local["self"] is then unset!
#puts "objKeys[-1]";p objKeys[-1]
#puts "objEnv";p objEnv
#p objEnv[objKeys[-1]]
      filter2.envir.local["self"]=objEnv[objKeys[-1]] 
#puts 'filter2.envir.local["self"]';p filter2.envir.local["self"]
      dict2.delete("self")
#puts "dict2Self";p dict2

      #attempt of autobuilding of object! (10/03/08)
      elt={}
      #test if it is an internal Dyn Object (DynVar, Array, ) i.e. if Class is a field?
#puts "filter2.local";p filter2.envir.local["self"]
      if !objEnv.empty? and filter2.envir.local["self"]
       if filter2.envir.local["self"].is_a? Array #is an Array object
         elt["content"]=objEnv[objKeys[-1]]
         elt["Class"]={:val=>["Array,Object"]}
        elsif !filter2.envir.local["self"]["Class"] #no Class specified => A DynVar or List object 
         if filter2.envir.local["self"][:val] #is a DynVar object
          elt["content"]= filter2.envir.local["self"]
          elt["Class"]={:val=>["DynVar,Object"]}
         else #is a List object
#puts "List";p objEnv[objKeys[-1]]
          elt["content"]=objEnv[objKeys[-1]]
          elt["Class"]={:val=>["List,Object"]}
         end
       end
       elt["ObjectName"]={:val=>[objName]} unless elt.empty?
#puts "class";p elt["Class"]
#puts "content";p elt["content"]
      end
      if objEnv.empty? or !filter2.envir.local["self"]
        if (elt=AutoClass.find(objName)).empty? 
          #is a String Vector i.e. of the form 
          # name1,name2,...,nameN
          vals=objName.split(",").map{|e| e.strip}.map{|e| {:val=>[e]}}
         elt["content"]={"value"=>{:val=>[objName]},"ary"=>vals}
          elt["Class"]={:val=>["String,Object"]}
         elt["ObjectName"]={:val=>[nil]} #empty ObjectName used in inspect method!
        end
      end
#puts "Elt:";p elt
      #creation of the new object!
      filter2.envir.local["self"]=elt unless elt.empty?
#p filter2.envir.local
      filter2.envir.local["self"]["ObjectName"]={:val=>[objName]} unless objName=="self" or filter2.envir.local["self"]["ObjectName"]
    end
#puts "filter2";p filter2.envir
#puts "dict2[:prev](???)";p dict2[:prev]
   #Really IMPORTANT: for pointer tricks: first import :prev environment 
   filter2.import_dict({:prev=>dict2[:prev]})
   dict2.delete(:prev)
#puts "dict2";p dict2
#puts "filter2a";p filter2.envir
	#Really IMPORTANT: and then pointers could be recognized!
    filter2.import_dict(dict2)
#puts "filter22";p filter2.envir

    inR=nil
    if isMeth
      if bCall==:meth
#p filter2.envir
#puts "extract self";p call;p filter2.envir.extract("self")

#ICI: tester si l'objet a un champ Klass sinon faire comme avant et le déclarer en 

        klass=get_klass(filter2.envir.extract("self")["Class"])
#puts "call";p call
#puts "klass";p klass
#p @calls.keys
=begin
        i,bCall=-1,nil
        bCall=@calls[call+"."+klass[i+=1]] until bCall
        call+="."+klass[i]
=end
        bCall=get_method(call,klass)
#puts "call meth";p call;p klass
#p bCall
        #puts some raise Error! return "" unless bCall
       unless bCall
         puts "DYN WARNING: Method #{call} undefined for class #{klass} (object: #{objName})"
       return ""
     end
      #init the parameter of the true method!
      if (args=@args[call])
          args=args[1..-1]
          args=nil if args.empty? 
#p args

          if meth_args_b
#puts "ICI1";p meth_args_b
            CallFilter.parseArgs(call,meth_args_b,true)
#puts "eval CALL meth_b";p call;p meth_args_b

#p meth_args_b
            b2=meth_args_b.map{|e| filter.apply(e)} if meth_args_b and meth_args_b.length>0

#puts "call(2)";p call;p b2
            dict=FilterManager.eval_dict(b2)
#puts "dict(eval_CALL)";#p dict
#IMPORTANT: (19/10/08) remove self from dict because already imported!
        		dict.map!{|e| e if e[0]!="self"}.compact!

#puts "Import dict in filter2"
#p dict
#puts "eval_CALL:filter2.envir";p filter2.envir
            filter2.import_dict(dict) 
#puts "self";p filter2.envir.local["self"]
#p filter2.envir.local
          end
        end
      end

      # R envir
      inR=filter2.envir.extract("self")["Renvir"]
#p inR

#p @args[call]
#p b2
#p filter2
    end
	# deal with blckcodes
#puts "<<def_blck #{call}"
#p blckcode
#puts "av:";p @def_blck
    @def_blck << blckcode if blckcode and !blckcode.empty?
#puts "ap:";p @def_blck
#p blckcode

    ## Tex part
    ### this is wondeful (10/08/04)
    ## apply filter2 for fragment before parsing
    @rEnvir.unshift(inR) if inR
=begin
if call=="new.TotoIn"
puts "AVANT"
p bCall
p filter2.envir.local["self"]
end 
=end
	# deal with _args_ argument 
#puts "filter2.local";p filter2.envir.local
#p filter2.envir.local["_args_"]
#p Envir.is_listElt?(filter2.envir.local["_args_"])
	if filter2.envir.local["_args_"] and Envir.is_listElt?(filter2.envir.local["_args_"])
#puts "IICCII"
	  filter2.envir.local["_args_"].each{|key,val| filter2.envir.local[key]=val}
	  filter2.envir.local.delete("_args_")
	end
#puts "filter2.local";p filter2.envir.local
#puts "bCall";p bCall
#puts "call binding";p filter2.envir.local
#Dyndoc.warn "rbEnvir tricks", [filter2.envir.extract("binding"),@rbEnvir4calls]
  inRb=filter2.envir.extract("binding") #first the call parameter
  inRb=@rbEnvir4calls[call] unless inRb #second, the tag binding
  rbenvir_go_to(inRb)
#puts "eval_CALL:bCall";p bCall
	txt=parse(bCall,filter2)
#puts "eval_CALL:txt";p txt
  rbenvir_back_from(inRb)
#p filter2.envir.local
=begin
if call=="new.TotoIn"
puts "APRES"
p filter2.envir.local["self"]
end
=end
#puts ">>def_blck #{call}"
#puts "av";p @def_blck;p blckcode
    @def_blck.pop if blckcode and !blckcode.empty?
#puts "ap";p @def_blck;
    ## post-filtering
	txt=filter2.apply(txt,:post,false) ##IMPORTANT: EST-CE VRAIMENT UTILE??? VOIR vC!!!!
    @rEnvir.shift if inR
	filter.envir.local=filter2.envir.local if export
  end
#puts "FIN CALL" 
 return txt
end

#eval_ENVIR(env, filter) ⇒ Object



51
52
53
54
# File 'lib/dyndoc/base/tmpl/eval.rb', line 51

def eval_ENVIR(env,filter)
  filter.envir.local=@envirs[env] if @envirs[env]
#p "ENVIR#{env}";p filter; p "\n"
end

#eval_FUNC(bloc, b) ⇒ Object



248
249
250
251
252
253
254
255
256
257
# File 'lib/dyndoc/base/tmpl/eval.rb', line 248

def eval_FUNC(bloc,b)
  bloc,code=Utils.end_line(bloc,b)
##p bloc;p code
  key,args=bloc.strip.split(/[|:]/)
  key.strip!
#p "@calls[#{key}]"
  @args[key]=args.split(",").map{|e| e.strip} if args
#p @args[key];p code
  @calls[key]=code
end

#eval_func(call, code, rbEnvir) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/dyndoc/base/tmpl/eval.rb', line 520

def eval_func(call,code,rbEnvir)
##p call;p code
  key,args=call.strip.split(/\|/) #no longer ":"
  key.strip!
#p "@calls[#{key}]"
  @args[key]=args.split(",").map{|e| e.strip} if args
#p @args[key];p code
  @calls[key]=code
  @rbEnvir4calls={} unless @rbEnvir4calls
  @rbEnvir4calls[key]=rbEnvir if rbEnvir
#p @rbEnvir4calls
end

#eval_GLOBALVAR(var, txt, filter, mode = "") ⇒ Object



567
568
569
570
571
572
573
574
575
576
# File 'lib/dyndoc/base/tmpl/eval.rb', line 567

def eval_GLOBALVAR(var,txt,filter,mode="")
  return unless filter.envir.global[var]
  ## texvar already declared in DefaultPre_tmpl.tex
  if mode.empty? or !(["add","append","+"].include? mode)
    filter.envir.global[var][:val][0]=""
  else
     filter.envir.global[var][:val][0] << "\n" unless filter.envir.global[var][:val][0].empty?
  end
  filter.envir.global[var][:val][0] << txt
end

#eval_INPUT(tmpl, b, filter) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 120

def eval_INPUT(tmpl,b,filter)
  ## register tmpl in @blocks to avoid next the same call!!!
#=begin TO REMOVE
  tmpl,tags,rest=tmpl.split(/\((.*)\)/)
  tags=TagManager.init_input_tags(tags.split(",").map{|e| e.strip.downcase}) if tags
#=end
  tmpl,export=tmpl[0...-1],true if tmpl[-1,1]=="!"
#p tmpl;p tags;p rest
  tmpl_name=tmpl
  tmpl_orig=Dyndoc.doc_filename(tmpl.strip)
  tmpl=Dyndoc.directory_tmpl? tmpl_orig
  #TO REMOVE: init_dtag(tmpl)
#p tmpl
  block=tmpl #TO REMOVE: +(partTag.empty? ? "" : "("+partTag.join(',')+")")
  unless @blocks.keys.include? block
    #TO REMOVE: input=PartTag.part_doc(File.read(tmpl),partTag2)
#puts "inside INPUT";p tmpl
    return "Dyndoc Error: "+tmpl_name+" is not reacheable!!! " unless tmpl
  	input=Dyndoc.read_content_file(tmpl,{:doc => @doc})
  	@blocks[block]=input
#p block;p @blocks[block]
  end
  ## apply R filtering
  b2=b.map{|e| filter.apply(e)} if b.length>0
  dict2={:prev=>filter.envir.local}
  if b.length>0
  	dict=FilterManager.eval_dict(b2) ###eval("{"+b2.join(",")+"}")
  	dict.each{|k,v| dict2[k.to_s]=v}
  end
  filter2=FilterManager.new({:global=>@global},self)
  filter2.import_dict(dict2)
  ###################################
  # added to set the current filename 
  # of the template in the local environment
  # _FILENAME_ is maybe obsolete now 
  # (see also "parse" in parse_do.rb file)
  ###################################
  filter2.envir["_FILENAME_CURRENT_"]=tmpl.dup
  filter2.envir["_FILENAME_"]=tmpl.dup #register name of template!!!
  #####################################
  filter2.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!!
  filter2.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!!
=begin
  Envir.set_textElt!(["_FILENAME_"],tmpl.dup,filter2.envir.local) #register name of template!!!
  Envir.set_textElt!(["_PWD_"],File.dirname(tmpl),filter2.envir.local) #register name of template!!!
=end
  ## Text part
  ## pre-filtering
  b2=@blocks[block]
  @current_tmpl=block
#puts "eval_INPUT:tags";p tags
  txt=parse(b2,filter2,tags)
#puts "eval_INPUT:txt";p txt
  ## post-filtering
  txt=filter2.apply(txt,:post,false)
  txt.strip! ##clean whitespace 
  txt += "\n" ##need one at the end!!!
  filter.envir.local=filter2.envir.local if export
  return txt
end

#eval_LOAD(b, filter) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 181

def eval_LOAD(b,filter)
  ## just load and parse : read some FUNCs and EXPORT some variables
  ## in the header
  if b.length>0
    b2=b.map{|e| filter.apply(e)}
#puts "b2";p b2
#Dyndoc.warn "LOAD",b2
    b2.each{|lib|
      lib,tags,rest=lib.split(/\((.*)\)/)
#p lib;p tags;p rest
      tags=tags.split(",").map{|e| e.strip.downcase} if tags
#puts "lib";p lib
      tmpl_orig=Dyndoc.doc_filename(lib.strip)
      tmpl=Dyndoc.directory_tmpl? tmpl_orig
#puts "tmpl";p tmpl
      #TO REMOVE: init_dtag(tmpl)
=begin TO REMOVE
      [email protected]
      PartTag.append(partTag2,partTag)
      input=PartTag.part_doc(File.read(tmpl),partTag2) 
#p input
=end
  	  # REPLACEMENT of  ABOVE!
  	  unless @libs.keys.include? tmpl
  	    input=Dyndoc.read_content_file(tmpl)
  	    @libs[tmpl]=input
  	    filter.envir["_FILENAME_"]=tmpl.dup #register name of template!!!
  	    filter.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!!
  	    filter.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!!
  	    txt=parse(@libs[tmpl],filter,tags)
  	  end
    }
  end 
end

#eval_LOAD_HELPERS(b, filter) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 216

def eval_LOAD_HELPERS(b,filter)
  ## just load and parse
  ## in the header
  if b.length>0
    b2=b.map{|e| filter.apply(e)}
#p b2
    pathenv=File.read(File.join(Dyndoc.cfg_dir[:home],"helpers")).strip
    helpers = ""
    
    b2.each{|lib|
#p lib
      filename=lib.strip
      unless filename[0,1]=="#"
        dirname,filename=File.split(filename)
        filename=File.basename(filename,"*.rb")+".rb"
        filename=File.join(dirname,filename) unless dirname=="."
#p filename
#p pathenv
        filename2=Dyndoc.absolute_path(filename,pathenv)
#puts "names";p names
        if filename2
         helpers << File.read(filename2) << "\n"
        else
          puts "WARNING: helper #{filename} is unreachable in #{pathenv}!"
        end 
      end
    }
#p helpers
    Dyndoc::Ruby::Helpers.module_eval(helpers)
  end 
end

#eval_meth(call, code) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 533

def eval_meth(call,code)
#p call
  key,args=call.strip.split(/\|/) #no longer ":"
  args=(args ? "self,"+args : "self")
  key.strip!
  key2,klass=key.split(".")
#p "@calls[#{key}]"
#p key2;p klass
  @args[key]=args.split(",").map{|e| e.strip}
#p @args[key]
#p code
  @calls[key]=code
  #this is a method!
  @calls[key2]=:meth 
  @meths << key2
  @meths.uniq!
#p @meths
  @args[key2]=["self"]
=begin
  #update method parameters
  if @args[key2]
    #update (only the first common parameters, the rest have to be named to be used)
    ok=true
    @args[key2]=(0...([@args[key].length,@args[key2].length].min)).map{|i| ok&=(@args[key][i]==@args[key2][i]);@args[key][i] if ok }.compact
  else
    #first init
    @args[key2]=@args[key]
  end
=end
#p @calls
#puts "args[new]";p @args["new"]
#p @meths
end

#eval_PARENT(env, filter) ⇒ Object



46
47
48
49
# File 'lib/dyndoc/base/tmpl/eval.rb', line 46

def eval_PARENT(env,filter)
  filter.envir.local[:prev]=@envirs[env] if @envirs[env]
#p "PARENT#{env}";p filter; p "\n"
end

#eval_RbCODE(code, filter, opts = {}) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dyndoc/base/tmpl/eval.rb', line 102

def eval_RbCODE(code,filter,opts={})
#p @rbEnvir[0];p filter.apply(code)
#puts "code";p code
  if code[0,1]=="<"
   i=(code=~/>/)
   envir,code=code[1...i],code[(i+1)..-1]
#p envir
#p code
   envir=(envir.empty? ? TOPLEVEL_BINDING : eval(envir))
#p envir
    opts[:error] = "RbCode Error"
   return filter.convert(RbServer.output(code,envir,opts),"#")
  else
    opts[:error] = "RbCode Error"
   return filter.convert(RbServer.output(code,@rbEnvir[0],opts),"#")
  end
end

#eval_RCODE(code, filter, opts = {:pretty => true}) ⇒ Object

pretty=true,capture=nil)



87
88
89
90
91
92
93
94
# File 'lib/dyndoc/base/tmpl/eval.rb', line 87

def eval_RCODE(code,filter,opts={:pretty => true}) #pretty=true,capture=nil)
#Dyndoc.warn "eval_RCODE",p code
#Dyndoc.warn "rEnvir[0]",@rEnvir[0] #;"print(ls(.env4dyn$#{@rEnvir[0]}))".to_R
#Dyndoc.warn "output",RServer.output(code.strip,@rEnvir[0],pretty)
  Utils.clean_eol(code)
  #puts "eval_RCODE";p RServer.safe_output(code,@rEnvir[0],pretty,capture)
  return filter.convert(RServer.safe_output(code,@rEnvir[0],opts),"#")
end

#eval_rout(code, filter) ⇒ Object



96
97
98
99
100
# File 'lib/dyndoc/base/tmpl/eval.rb', line 96

def eval_rout(code,filter)
#p code
  Utils.clean_eol(code)
  return RServer.rout(code,@rEnvir[0])
end

#eval_SET(var, txt, filter, newline = nil) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/eval.rb', line 56

def eval_SET(var,txt,filter,newline=nil)
  ## apply R filtering
#puts "SET";p var; p txt
  key=filter.apply(var)
  key,opt=key.scan(/([#{FilterManager.letters}]+)\s*(!?\+?\??)/).flatten
  key=filter.envir.keyMeth(key)
#puts "SET:key";p key;p Envir.to_keys(key);p opt
#p filter.envir.local
#p filter.envir.elt_defined?(Envir.to_keys(key))
  txt=filter.apply(txt)
#puts "SET:txt";p txt
  curElt=((opt.include? "!") ?  filter.envir.elt_defined?(Envir.to_keys(key),true) :  Envir.elt_defined?(filter.envir.local,Envir.to_keys(key),true) )
#puts "curElt"; p curElt
#puts "curElt if opt?"; p curElt if opt.include? "?"
  return if curElt and opt.include? "?"
  if key and curElt 
    if opt.include? "+"
      curElt[:val][0] << txt
    else
      txt=[txt] if curElt[:attr] and curElt[:attr].include? :array
      curElt[:val][0] =txt
    end
    curElt[:val][0] << "\n" if newline and !(curElt[:attr] and curElt[:attr].include? :array)
  else
    #unless ! in opt only local 
    key=":"+key unless opt.include? "!"
#puts "SET:new key";p key;p txt
    filter.envir[key]=txt
  end
end

#eval_TEX_TITLE(filter) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/dyndoc/plugins/tex/tex_eval.rb', line 51

def eval_TEX_TITLE(filter)
  ## _BEGINDOC_ already declared in DefaultPre_tmpl.tex
  if  filter.envir.global["_BEGINDOC_"] and filter.envir.global["_BEGINDOC_"][:val][0].scan(/\\maketitle/).empty?
    filter.envir.global["_BEGINDOC_"][:val][0] << "\n" unless filter.envir.global["_BEGINDOC_"][:val][0].empty?
    filter.envir.global["_BEGINDOC_"][:val][0] << "\\maketitle"
  end
end

#eval_TXT(b, filter, strip = @strip) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dyndoc/base/tmpl/eval.rb', line 8

def eval_TXT(b,filter,strip=@strip)
  b.delete_if{|s| !s.scan(/^\s*%%%/).empty?} unless @echo>0
  if b.length>0
    txt=b.map{|l|
	  l2=filter.apply(l)
	  if (l.strip).scan(/^\#\{.*\}$/).empty?
 l2
	  else
        ## do not deal with empty result!!!
 l2 unless l2.empty?
	  end
    }.compact
#p "txt";p txt
    txt.map!{|l| l.lstrip} if strip
#p "txt2";p txt
    txt=txt.join("\n")
  else
    txt=nil
  end
  return txt
end

#eval_VARS(b, filter) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/dyndoc/base/tmpl/eval.rb', line 30

def eval_VARS(b,filter)
 ## apply R filtering
 ##b=b.map{|e| filter.apply(e)} -> apply to each line!!
 ## read the bloc
 dict=FilterManager.eval_dict(b,true)
#puts "eval_VARS:dict";p dict
 filter.import_dict(dict)
#puts "eval_VARS:filter";p filter.envir.local
end

#evalJlBlock(id, cpt, tag, lang = :jl) ⇒ Object



2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2114

def evalJlBlock(id,cpt,tag,lang=:jl)
  ## Dyndoc.warn "evalJlBlock!!!"
  ## this deals with the problem of newBlcks!
  ## Dyndoc.warn "block_normal",blckMode_normal?
  ## Dyndoc.warn "@doLangBlock",@doLangBlock
  code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
  ## Dyndoc.warn "codeJL",code
  ## Dyndoc.warn "filter",@doLangBlock[id][:filter]
  @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
  ## Dyndoc.warn "code2JL",@doLangBlock[id][:out]
  ## Dyndoc.warn tag
  if tag == :>
    outcode=@doLangBlock[id][:out] #.gsub(/\\/,'\\\\\\\\') #to be compatible with R
    outcode='print("'+outcode+'")'
    ## Dyndoc.warn "outcode",outcode
    Julia.exec outcode,:get=>nil # CLEVER: directly redirect in R output that is then captured
  end
  if tag == :<<
    return ( lang==:jl ? JLServer.eval(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
  else
    return @doLangBlock[id][:out]
  end
end

#evalRbBlock(id, cpt, tag, lang = :rb) ⇒ Object



1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1939

def evalRbBlock(id,cpt,tag,lang=:rb)
## Dyndoc.warn "@doLangBlock[#{id.to_s}][:code][#{cpt.to_s}]",@doLangBlock[id][:code][cpt]#,@doLangBlock[id][:filter]
  ## this deals with the problem of newBlcks!
  ##puts "block_normal";p blckMode_normal?
  code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
  #puts "code";p code
  @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
  ##Dyndoc.warn "evalRbBlock:doLangBlock",[id,code,@doLangBlock[id][:out]] if tag == :>

  #########################################
  ## THIS IS FOR OLD
  ##@doLangBlock[id][:tex] << @doLangBlock[id][:out] if tag == :>
  ## THIS IS NEW
  print @doLangBlock[id][:out] if tag == :>
  ##
  #Dyndoc.warn "EVALRBBLOCK: @doLangBlock[id][:out]",@doLangBlock[id][:out] if tag == :>
  #######################################

  if tag == :<<
    return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
  else
    return @doLangBlock[id][:out]
  end
end

#evalRBlock(id, cpt, tag, lang = :R) ⇒ Object



2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2053

def evalRBlock(id,cpt,tag,lang=:R)
  ## this deals with the problem of newBlcks!
  ## Dyndoc.warn "block_normal",blckMode_normal?
  code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" )
  ## Dyndoc.warn "codeR",code
  @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter])
  ## Dyndoc.warn "code2R", @doLangBlock[id][:out]
  if tag == :>
    outcode=@doLangBlock[id][:out].gsub(/\\/,'\\\\\\\\') #to be compatible with R
    outcode=outcode.gsub(/\'/,"\\\\\'")
    #Dyndoc.warn
    outcode='cat(\''+outcode+'\')'
    #Dyndoc.warn "outcode",outcode
    outcode.to_R # CLEVER: directly redirect in R output that is then captured
  end
  if tag == :<<
    return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) )
  else
    return @doLangBlock[id][:out]
  end
end

#extract_var(id) ⇒ Object



147
148
149
# File 'lib/dyndoc/base/tmpl/manager.rb', line 147

def extract_var(id)
  @vars.extract(id)
end

#format(which = :all) ⇒ Object

format helpers



278
279
280
281
282
283
284
285
286
287
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 278

def format(which=:all)
  formats={
    :output => outputFormat,
    :blck => blockFormat,
    :parent => parentFormat,
    :default => defaultFormat,
    :current => currentFormat
  }
  which==:all ? formats : formats[which]
end

#format_output=(format) ⇒ Object



188
189
190
# File 'lib/dyndoc/base/tmpl/manager.rb', line 188

def format_output=(format)
  @fmtOutput=format
end

#get_klass(klass) ⇒ Object



6
7
8
# File 'lib/dyndoc/base/tmpl/oop.rb', line 6

def get_klass(klass) 
  return klass.split(",").map{|e| e.strip}
end

#get_method(call, klass0) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dyndoc/base/tmpl/oop.rb', line 10

def get_method(call,klass0)
  i,bCall=-1,nil
  klass=klass0+["Object"]
#p call;p klass;p call+"."+klass[i+1];p @calls.keys
  bCall=@calls[call+"."+klass[i+=1]] until bCall or i==klass0.length
  if bCall
    @meth,@klasses= call.dup,klass
    @called = call << "."+ (@meth_klass=klass[i])
  end
  return bCall
end

#get_named_blck(b2, filter) ⇒ Object

new syntax: [#>] tag1,tag2,… > var […]



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 222

def get_named_blck(b2,filter)
  vars=nil #default: no named block!
  if b2[0][0]==:named
    vars=filter.apply(b2[0][1].strip)
    vars.gsub!("#",@Fmt)
    b2=b2[0][2..-1]
    if vars.include? ">"
      fmts,vars=vars.split(">")
      b2=nil unless  fmts.split(",").map{|e| e.strip}.include? @fmt
	  #TODO: changer et mettre la condition sur les tags!!!! et non uniquement sur le format!
	  #HOWTO: b2 non nil s'il existe un document pour lequel cette partie est à évaluer!
    else
      #if a variable ends with FORMATS element
      if (ind=vars.rindex(/(#{Dyndoc::FORMATS.join("|")})$/))
        #do not evaluate unless right format
        b2=nil unless vars[ind..-1]==@Fmt
      end
    end
  end
  return [vars,b2]
end

#get_named_blck_simple(b2, filter) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 244

def get_named_blck_simple(b2,filter)
  vars=nil #default: no named block!
  if b2[0][0]==:named
    vars=filter.apply(b2[0][1].strip)
    b2=b2[0][2..-1]
  end
  return [vars,b2]
end

#get_super_method(parent = 1) ⇒ Object



22
23
24
# File 'lib/dyndoc/base/tmpl/oop.rb', line 22

def get_super_method(parent=1)
  (@klasses.map{|e| @meth+"."+e} & @calls.keys)[parent]
end

#init_doc(doc_cfg) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/dyndoc/base/tmpl/manager.rb', line 167

def init_doc(doc_cfg)
  @cfg=doc_cfg
  # register format
  @fmt=@cfg[:format_doc].to_s.downcase
  @Fmt=@fmt.capitalize
  ##Dyndoc.warn "@cfg",@cfg
  @fmtOutput=@cfg[:format_output].to_s if @cfg[:format_output]
  @fmtOutput=@fmt if @fmt and ["html","tex","odt","tm"].include? @fmt
  @dyndocMode=:cmdline
  @global={}
  @filterGlobal=FilterManager.global(self) #global filter needed to affect object before parsing the main document!
  @blocks,@libs,@calls,@args,@meths,@def_blck={},{},{},{},[],[]
  CallFilter.init(self,@calls,@args,@meths)
  @filter=nil
  @tags=[]
  @keys={}
  @alias={}
  @savedBlocks={}
  require_first if @@interactive
end

#init_dtag(tmpl) ⇒ Object

TO REMOVE????



306
307
308
309
310
# File 'lib/dyndoc/base/tmpl/manager.rb', line 306

def init_dtag(tmpl)
  dtag=tmpl.scan(/(?:#{@cfg[:dtags].map{|e| "_#{e}_" }.join("|")})/)[0]
#p dtag
  return @dtag=(dtag ? dtag[1...-1].to_sym : @cfg[:dtag])
end

#init_keysObject



221
222
223
224
# File 'lib/dyndoc/base/tmpl/manager.rb', line 221

def init_keys
  @init_keys=KeysManager.init_keys((@cfg[:keys_doc]+@tmpl_cfg[:keys_tmpl]).uniq)
#puts "Manager:init_keys";p @init_keys
end

#init_model(input) ⇒ Object



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
# File 'lib/dyndoc/base/tmpl/manager.rb', line 227

def init_model(input)
  @pre_doc,@post_doc,@pre_model,@post_model=[],[],[],[]
  if @cfg[:model_doc] and Dyndoc.cfg_dir[:tmpl_path][@cfg[:format_doc]]
    @cfg[:model_doc]="Default" if @cfg[:model_doc].downcase=="default"
    model_doc=File.join("Model",Dyndoc.cfg_dir[:tmpl_path][ @cfg[:format_doc]],@cfg[:model_doc])
    @pre_model << File.read(Dyndoc.doc_filename(model_doc+"Pre"))
    @post_model = [File.read(Dyndoc.doc_filename(model_doc+"Post"))]
#p @pre_model
#p @post_model
  end

  ## sort with respect to priority number and filter
  @cfg[:pre_doc] += input.scan(/\[\#(?:plugin|preload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten
#p @cfg[:pre_doc]
  input.gsub!(/\[\#(?:plugin|preload)\][^\[]*/m,"")
  @cfg[:pre_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten!
  ## sort with respect to priority number and filter
  @cfg[:post_doc] += input.scan(/\[\#(?:postload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten
  input.gsub!(/\[\#(?:postload)\][^\[]*/m,"")
  @cfg[:post_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten!

#p @cfg[:pre_doc]
  if @cfg[:pre_doc]
    @cfg[:pre_doc].uniq.each{|t|
      @pre_doc << File.read(Dyndoc.doc_filename(t))
    }
  end
#p @pre_doc

  if @cfg[:post_doc]
    @cfg[:post_doc].uniq.each{|t|
      @post_doc << File.read(Dyndoc.doc_filename(t))
    }
  end

end

#init_path(input) ⇒ Object

init output



201
202
203
204
205
# File 'lib/dyndoc/base/tmpl/manager.rb', line 201

def init_path(input)
   ##read in the main doc paths to include!
  Dyndoc.setRootDoc(@cfg[:rootDoc],input.scan(/%%%path\((.*)\)/).flatten.map{|e| e.split(",")}.flatten.map{|e| e.strip.downcase}.join(":"))
  p @cfg[:rootDoc] if @cfg[:cmd]==:cfg
end

#init_tags(input) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/dyndoc/base/tmpl/manager.rb', line 207

def init_tags(input)
  ## read the global aliases (config files alias)
  TagManager.global_alias(@alias) # @alias increased
  ## read the local aliases (in the main doc)
  TagManager.local_alias(@alias,input) # @alias increased
  #init @partTag
  @tags=TagManager.init_input_tags(([@fmt]+@cfg[:tag_doc]+@tmpl_cfg[:tag_tmpl]).uniq)
#p @alias
#
Dyndoc.warn "init_tags",@tags
  #To deal later: TagManager.apply_alias(@tags,@alias)
  p [:init_tags, @tags] if @cfg[:cmd]==:cfg
end

#keys_compare(e1, e2) ⇒ Object



2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2364

def keys_compare(e1,e2)
  i,res=0,0
#p @keys["order"]
 while res ==0 and i<@keys["order"].length
   a=@keys["order"][i]
#puts "a";p a
   res=a[:order]*(e1[:lock][a[:val]] <=> e2[:lock][a[:val]])
   i+=1
 end
 #because of pb of sort to deal with equality!
 res=e1[:index]<=>e2[:index] if res==0
 res
end

#keys_print(tex, texAry) ⇒ Object



2387
2388
2389
2390
2391
2392
2393
2394
2395
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2387

def keys_print(tex,texAry)
  #keys_show(texAry.flatten) if @tmpl_cfg[:debug]
  texAry=keys_select(texAry.flatten)
  keys_show(texAry) if @tmpl_cfg[:debug]
  texAry=keys_sort(texAry) if @keys["order"]
  #puts "SORTED"
  #keys_show(texAry)
  texAry.each{|e| tex << e[:content]}
end

#keys_recurse(tex) ⇒ Object



2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2334

def keys_recurse(tex)
#puts "keys_recurse: tex";p tex
  texAry=tex[:content].split(/__DYNKEYS(\d+)__/,-1)
  if texAry.length==1
   tex
  else
   (0...texAry.length).map do |i|
     if i%2==1
       keys_recurse($dyn_keys[:tex][texAry[i].to_i])
     else
       {:lock=>tex[:lock],:content=>texAry[i]}
     end
   end
  end
end

#keys_select(texAry) ⇒ Object



2358
2359
2360
2361
2362
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2358

def keys_select(texAry)
  texAry.find_all{|e|
   KeysManager.unlocked?(e[:lock],@keys)
  }
end

#keys_show(texAry) ⇒ Object



2350
2351
2352
2353
2354
2355
2356
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2350

def keys_show(texAry)
  puts "@keys";p @keys
  texAry.each{|e|
   p e[:lock]
   p e[:content]
  }
end

#keys_sort(texAry) ⇒ Object



2378
2379
2380
2381
2382
2383
2384
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2378

def keys_sort(texAry)
  texAry.each_with_index{|e,i| e[:index]=i}
  texAry.sort{|e1,e2|
#p e1;p e2
	keys_compare(e1,e2)
  }
end

#make_call(blck, filter) ⇒ Object



1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1207

def make_call(blck,filter)
  code,codename,var={"default"=>[:blck]},"default",[]
  i=-1
  begin
    case blck[i+=1]
      when :blck, :"->"
        #todo: change codename with the arg of blck
        i,*b2=next_block(blck,i)
        codename=parse(b2,filter).strip
        code[codename]=[:blck]
      when :do,:<,:out,:>,:"r<",:"R<",:"rb<",:"r>",:"R>",:"R>>",:"rb>",:nl,:"\n",:>>,:"?",:tag,:"??",:"=",:"+",:<<,:"%",:"html>",:"tex>",:"txtl>",:"md>",:"adoc>" #NO :yield because of infinite loops
        code[codename] << blck[i]
        i,*b2=next_block(blck,i)
        code[codename] += b2
      when :var,:","
        var << blck[i]
        i,*b2=next_block(blck,i)
#puts "var et ,";p b2
        var += b2
	  else
 var << :","
 res=[:named,blck[i].to_s]
 i,*b2=next_block(blck,i)
 res += b2
 var << res
#p var
    end
  end while i<blck.length-1
  ## IMPORTANT: special treatment for default empty block to avoid infinit loop
  code["default"] << :out << [:main,""] if code["default"].length==1
  code.each_key{|k| code.delete(k) if code[k].length==1 }
  return [var,code]
end

#make_def(blck, filter) ⇒ Object



1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1050

def make_def(blck,filter)
  call=parse_args(blck[1],filter)
  code,arg,var,rbEnvir=nil,[],[:var],nil
  i=1
  begin
    case blck[i+=1]
      when :binding
        i,*b2=next_block(blck,i)
        rbEnvir=b2[0][1].strip
      when :do,:<,:out,:>,:"r<",:"rb<",:"r>",:"R>",:"R<",:"r>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:"jl>",:"jl<",:"sh<",:"rb>",:"?",:tag,:"??",:yield,:>>,:"=",:"+",:<<,:"txtl>",:"md>",:"adoc>",:"ttm>",:"html>",:"tex>",:"_>"
        code = blck[i..-1].unshift(:blck)
      when :","
        i,*b2=next_block(blck,i)
#p blck;p b2
        #deal with
        b2=b2[0]
        if b2[0]==:named
=begin
if false
#Old one!
#puts "b2";p b2
          b2 << [:main,""] unless b2[2]
          arg << b2[1]
          var0=b2[2..-1]
          var0[0][1]= ":"+b2[1]+"[?]=>" + var0[0][1]
   var << :"," unless var.length==1
#p var0
   var += var0
#next: New one
else
=end
#puts "b2";p b2
   # 151108: Adding "!" at the end of the parameter name disables the default ability. This is completed with
   arg << (b2[1][-1,1]=="!" ? b2[1][0...-1]+"-USER-" : b2[1])
#p arg
   b2[1]+="?"
   b2 << [:main,""] unless b2[2]
#p b2
          var << :"," unless var.length==1
          var << b2
#end
 elsif b2[0]==:main
#puts "make_def";p call
   parse([b2],filter).split(",").map{|v| v.strip}.each{|v|
		var << :"," unless var.length==1
		var << [:named, v+"?" , [:main, ""]]
		arg << v
   }
#p var
   #var << b2
        end
      else #just after the arg is a comment and not dealt
        i,*b2=next_block(blck,i)
    end
  end while i<blck.length-1 and !code
  #if no block code is provided (possible for method) nothing to do is represented by the following code!
  code=[:blck, :<]  unless code
  code=[code]
#puts "var";p var
  code.unshift(var) unless var.length==1
#puts "code def #{call}";p code
  call+= ((call.include? "|") ? "," : "|")+arg.join(",") unless arg.empty?
  return [call,code,rbEnvir]
end

#make_do_lang_blck(blck, id, lang = :rb) ⇒ Object



1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1889

def make_do_lang_blck(blck,id,lang=:rb)
  #p blck
  cptCode=-1
## Dyndoc.warn "make_do_lang_blck",blck
  blck2=blck.map{|b|
## Dyndoc.warn "b",b
    if b.respond_to? "[]" and [:>,:<,:<<].include? b[0]
      cptCode+=1
      @doLangBlock[id][:code][cptCode]=Utils.escape_delim!(b[1])
      codeLangBlock = "Dyndoc.tmpl_mngr.eval"+ lang.to_s.capitalize+"Block(#{id.to_s},#{cptCode.to_s},:#{b[0].to_s},:#{lang})"

      @doLangBlockEnvs=[0] unless @doLangBlockEnvs #never empty?
      @doLangBlockEnvs << (doLangBlockEnv=@doLangBlockEnvs.max + 1)
      @doLangBlock[id][:env] << doLangBlockEnv

      ## NEW: Special treatment for R code because environment is different from GlobalEnv
      case lang
      when :R
        # first, get the environment
        codeLangBlock="{.GlobalEnv$.env4dyn$rbBlock#{doLangBlockEnv.to_s} <- environment();.rb(\""+codeLangBlock+"\");invisible()}"
        # use it to evaluate the dyn block with R stuff! (renv)
        @doLangBlock[id][:code][cptCode]= "[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}+[#}[#>]"+@doLangBlock[id][:code][cptCode]+"[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}-[#}"
      when :jl
        # Nothing since no binding or environment in Julia
        # Toplevel used
        codeLangBlock="begin Ruby.run(\""+codeLangBlock+"\") end"
        @doLangBlock[id][:code][cptCode]= "[#>]"+@doLangBlock[id][:code][cptCode]
      when :rb
        ##DEBUG: codeRbBlock="begin $curDyn.tmpl.rbenvir_go_to(:rbBlock#{rbBlockEnv.to_s},binding);p \"rbBlock#{doBlockEnv.to_s}\";p \"rbCode=#{codeRbBlock}\";$result4BlockCode="+codeRbBlock+";$curDyn.tmpl.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end"
        codeLangBlock="begin Dyndoc.tmpl_mngr.rbenvir_go_to(:rbBlock#{doLangBlockEnv.to_s},binding);$result4BlockCode="+codeLangBlock+";Dyndoc.tmpl_mngr.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end"
      end
      case lang
      when :R
        process_r(@doLangBlock[id][:code][cptCode])
      when :jl
        # TODO
        process_jl(@doLangBlock[id][:code][cptCode])
      when :rb
        process_rb(@doLangBlock[id][:code][cptCode])
      end
      [:main,codeLangBlock]
    else
      b
    end
  }
## Dyndoc.warn  "cptRb",cptRb
## Dyndoc.warn "blck2",blck2
  blck2
end

#make_named_blck(tex, filter, vars, b2, bang = false) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 253

def make_named_blck(tex,filter,vars,b2,bang=false)
#puts "make_named_blck:b2";p b2
  val=parse(b2,filter)
#puts "make_named_blck:val";p val
  # NB: bang is processed only at the end and not in the recursive process of parsing!
  # The reason is that maybe the form <NAME>! is not correct in some old document!
#Dyndoc.warn "make_named_blck:val",[val,process_bang(val),filter.rbEnvir] if bang
#DEBUG ONLY: val2=val if bang
  val=parse(process_bang(val),filter) if bang
#Dyndoc.warn "make_named_blck:val2",[val2,val]      if bang
  val=Utils.format_blocktext(val)
#puts "format_blocktext:val";p val
  if vars
    vars.split(",").each{|var|
      eval_SET(var.strip,val,filter)
    }
  else
    tex << val.force_encoding("utf-8")
  end
end

#make_outR(tex, b, i, splitter, filter, header = true) ⇒ Object



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
# File 'lib/dyndoc/plugins/tex/tex_eval.rb', line 22

def make_outR(tex,b,i,splitter,filter,header=true)
  normal= splitter.key[i].nil?
  if !normal
    filename=filter.apply(splitter.key[i]).strip 
    normal =  ["#","%"].include? filename[0,1]
  end
  if normal
    txt=filter.apply(b[1...-1].map{|l| l.strip}.join("\n"))
    txt=echo_verb(txt,header)
  else    
    filename=File.expand_path(filename)
    if (!File.exists?(filename))
      require 'fileutils'
      tmp=File.dirname(filename)
      FileUtils.mkdir_p(tmp) unless File.exists? tmp
      f=File.open(filename,"w")
      txt=filter.apply(b[1...-1].join("\n"))
      txt=echo_verb(txt,header)
      f << txt
      f.close
    else 
      txt=File.read(filename)
    end 
  end
  tex << "%%" << b[0] << "\n" if @echo>0
  tex << txt unless @echo<0
  tex << "%%" << b[-1] << "\n" if @echo>0  
end

#make_style_call(call, obj, blck) ⇒ Object



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1324

def make_style_call(call,obj,blck)
  b=[:call, [:args, [:main, name_style(call)]], [:main, obj]]
  unless blck.empty? #call not of the form {@toto@}
  	b += [:","]
  	#if only a block is given without parameter => no comma! => THIS IS NOT POSSIBLE BECAUSE OF THE CODE ARGUMENT!
  #puts "make_style_call:blck";p blck
  	b += ((blck[0].is_a? Array) ? blck : [blck])
  end
#puts "make_style_call";p b
  b
end

#make_style_meth(meth, klass, blck) ⇒ Object



1305
1306
1307
1308
1309
1310
1311
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1305

def make_style_meth(meth,klass,blck)
  b=[:meth, [:args, [:main, "#{name_style(meth)}.Style#{klass}"]]]
  b += [:","] if ((blck[0].is_a? Array) and ([:main,:named].include? blck[0][0]))
  b += blck
#p b
  return b
end

#make_style_new(klass, blck) ⇒ Object



1313
1314
1315
1316
1317
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1313

def make_style_new(klass,blck)
  b=[:new, [:args,blck[0]],:of, [:main, "Style#{klass}"]]+blck[1..-1]
#puts "make_style_new";p b
  return b
end

#make_var_block(blck, filter, dict = nil) ⇒ Object

def do_TXT(tex,b,i,splitter,filter)

out = eval_TXT(b,filter)

#p “OUT”;p out

  return unless out
  tex << out << "\n" unless @echo<0
end


783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 783

def make_var_block(blck,filter,dict=nil)
  b,i,go=[],-1,true
  cpt=0
#p blck
  begin
#p blck[i+1]
    case blck[i+=1]
    when :var, :","
#p blck[i]
      i,*b2=next_block(blck,i)
#puts "make_var";p i;p b2
#deal with
      unless b2.empty?
        name=nil
        if b2[0][0]==:named
          b2=b2[0]
          if b2[0]==:named
            b2 << [:main,""] unless b2[2]
            var=b2[2..-1]
            name=filter.apply(b2[1])
#puts "make_var_block:name";p name
#p dict
            if dict and (name2=dict.find{|v| v=~/^#{name}/})
              name=name2
              dict.delete(name)
            end
            b2=var
          end
        end

      end
#p name
#p b2
#p dict
	  # DO NOT remove lstrip! Otherwise, there is an error of compilation in test/V3/testECO2.dyn! => README.250808: OK now! The explanation was that is was needed only by @varscan (solved now)! The __STR__ escape the first and last whitespaces
#p b2
      b2=parse(b2,filter) #.lstrip #.split("\n")
#puts "name";p name
#puts "b2222";p b2

     sep=(dict ? "__ELTS__" : "\n" )
      #OLD: unless b2.empty? or b2=~/^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/
     unless b2=~ /^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/
#puts "ICCIII";p b2
        name=(dict ? dict.shift : "var#{cpt+=1}" ) unless name
        if name
#puts "name0";p name
#p name[0,1]==":"
#puts "name";p name
         modif,affect="","=>"
         if name[-1,1]=="?"
          name=name[0...-1]
          if name[-1,1]=="!"
            name=name[0...-1]
#p filter.envir.local
            keys2=Envir.to_keys((name[0,1]=="." ? "self"+name : name)+"-USER-" )
#p keys2
            env=Envir.elt_defined?(filter.envir.local,keys2)
#p env
            if env=Envir.elt_defined?(filter.envir.local,keys2)
              env[keys2[-1][0..-7]]=env[keys2[-1]]
              env.delete(keys2[-1])
              modif=nil
              b2=nil
            end
#p env
#p filter.envir.extract(name)
          else
            modif="?"
          end
         end
         if modif
          if name[-1,1]=="+"
            name=name[0...-1]
            modif+="+"
          end
          if name[-1,1]=="!"
#p "!!!!";p name
            name=name[0...-1]
            affect="==>"
          end
          name=":"+name unless name[0,1]==":"
          affect="["+modif+"] "+affect unless modif.empty?
#p b2.strip
          if (arr=@varscan.build_vars(b2.strip)) #the stuff for parsing  array
#puts "arr";p arr
#p b2
            b2=arr.map{|k,v|
              name+"."+k+affect+Utils.protect_blocktext(v)
            }.join(sep)
              ## add the order!
              ## ONLY for list not array!
              #b2+=sep+name+"._order_"+affect+Utils.protect_blocktext(arr.map{|k,v| k}.join(","))
              #p b2
          else
#puts "named";p b2
            b2=name+affect+Utils.protect_blocktext(b2) #see README.250808!
          end
#p b2
         end
       else
#puts "b2";p b2
         b2=Utils.protect_blocktext(b2) #see README.250808!
#p b2
        end
      end
#puts "b2:#{name}";p b2
#p b2.split(sep)
      b += b2.split(sep) if b2
#puts "b";p b
    end
  end while i<blck.length-1
#puts "make_var_block";p b
 return b
end

#make_yield(tex, codename, filter) ⇒ Object



2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 2415

def make_yield(tex,codename,filter)
  if @def_blck[-1] and @def_blck[-1].keys.include? codename
	#codename="default" unless @def_blck[-1].keys.include? codename
#p codename
#p @def_blck[-1][codename]
#p parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename]
    tex << parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename]
#p filter.envir.local["self"]
   end
end

#name_style(call) ⇒ Object

this allows us to consider independently the calls {#p] and {@p] for user-defined only methods!!!!



1320
1321
1322
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1320

def name_style(call)
  call=="new" ? call : "_style_"+call
end

#next_block(blck, i) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 154

def next_block(blck,i)
  b=[]
  while (i+1<blck.length and blck[i+1].is_a? Array)
   i+=1
   b << blck[i]
  end
  return b.unshift(i)
end

#next_block_until(blck, i, tagset) ⇒ Object



163
164
165
166
167
168
169
170
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 163

def next_block_until(blck,i,tagset)
  b=[]
  while (i+1<blck.length and !(tagset.include? blck[i+1]))
   i+=1
   b << blck[i]
  end
  return b.unshift(i)
end

#next_block_while(blck, i, tagset) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 172

def next_block_while(blck,i,tagset)
  b=[]
  while (i+1<blck.length and (tagset.include? blck[i+1]))
   i+=1
   b << blck[i]
  end
  return b.unshift(i)
end

#output(input, fromfile = nil) ⇒ Object

output the result after parsing txt



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
# File 'lib/dyndoc/base/tmpl/manager.rb', line 367

def output(input,fromfile=nil)
  @filename=@tmpl_cfg[:filename_tmpl]
  input=Dyndoc.input_from_file(@filename=input) if fromfile
  input=@tmpl_cfg[:lib_dyn_content]+"[#main][#>]"+input unless @tmpl_cfg[:lib_dyn_content].empty?
  ## fetch the contents of all saved variables! This fasten the compilation!
  Utils.saved_content_fetch_variables_from_file(@filename,self)

#p @filename
  init_path(input)
  init_tags(input)
  init_keys
  init_model(input)
#p input
  ## add the tag document in order to replace the user tag preamble and etc. Introduction of styles because of the odt format and the new convention in general to use styles even in latex.
  #txt="{#document][#content]"+input+"[#}"
  txt=input
#p txt
  prepare_user_input
  ## parse the content txt
  out=prepare_output(txt)
  prepare_last_output(out)
  clean_as_is(out)
##p [:output,out]
  return out
end

#output_post_modelObject

input = pre_doc.join(“n”) + “n” + input unless pre_doc.empty?

input = input + "\n" + post_doc.join("\n") unless post_doc.empty?
return input


286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/dyndoc/base/tmpl/manager.rb', line 286

def output_post_model
 #post_doc
  out_post=""
  #puts "output_post_model:post doc";p @post_doc
  unless @post_doc.empty?
    post_doc="\n"+@post_doc.join("\n")
    txt= post_doc
    parse(txt)
  end
  unless @post_model.empty?
    post_model="\n"+@post_model.join("\n")
    txt= post_model
    out_post << parse(txt)
  end
#p [:out_post,out_post]
  return out_post
end

#output_pre_modelObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/dyndoc/base/tmpl/manager.rb', line 264

def output_pre_model
  #pre_doc
  out_pre=""
  unless @pre_model.empty?
    pre_model=@pre_model.join("\n") + "\n"
    txt= pre_model
    out_pre << parse(txt)
  end
  unless @pre_doc.empty?
    pre_doc=@pre_doc.join("\n") + "\n"
    txt= pre_doc
    parse(txt,@filterGlobal) ##Style declares objects before compiling the document! Object are created in the global envir!
  end
##p [:out_pre,out_pre]
  return out_pre
end

#outputFormatObject



289
290
291
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 289

def outputFormat
  @fmtOutput
end

#parentFormat(level = 1) ⇒ Object



305
306
307
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 305

def parentFormat(level=1)
  @fmtContainer[level] ? (@fmtContainer[level].to_s)[0...-1] : nil
end

#parse(texblock, filterLoc = nil, tags = nil) ⇒ Object

insert text between start and stop marks the text is automatically loaded from



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
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 49

def parse(texblock,filterLoc=nil,tags=nil)
  #Dyndoc.warn "texblock",texblock
  @scan=DevTagScanner.new(:dtag) unless @scan
  @varscan=VarsScanner.new unless @varscan
#puts "parse";p texblock
  if texblock.is_a? String
    texblock=texblock.force_encoding("utf-8")
    ## Dyndoc.warn "parse",texblock
    if @@interactive
      Utils.parse_dyn_block_for_interactive!(texblock)
    else
      Utils.parse_raw_text!(texblock,self)
    end
    #Dyndoc.warn "After parse_raw_text",texblock
    #puts "raw_key and raw_text";p Utils.dyndoc_raw_text
    #escape accolade every time a new text is scanned!
    Utils.escape!(texblock,CHARS_SET_FIRST)
    Utils.clean_bom_utf8!(texblock)
    Utils.silence_warnings do
      texblock=@scan.process("{#document][#content]" + texblock + "[#document}")
    end
    ##Dyndoc.warn "parsed",texblock
  end
#p "texblock";p texblock
  unless filterLoc
   filterLoc=FilterManager.new({:global=>@global},self)
    filterLoc.envir["_FILENAME_CURRENT_"]=@filename.to_s if @filename
   Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_"],@filename.to_s) if @filename
   Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_ORIG_"], @tmpl_cfg[:filename_tmpl_orig].to_s) if @tmpl_cfg[:filename_tmpl_orig]
   Envir.set_textElt!(filterLoc.envir.global,["_PWD_"],Dir.pwd) if @filename
#puts "filterLoc";p @filename;p filterLoc.envir["_PWD_"]
  end
  Dyndoc.cfg_dir[:current_doc_path]=filterLoc.envir["_PWD_"] || ""
  ##Dyndoc.warn :current_doc_path,Dyndoc.cfg_dir[:current_doc_path]
  ##partTag tricks
  tagsOld=@tags.dup if tags #save @tags
  @tags+=tags if tags

  @vars,varsOld=filterLoc.envir,@vars
  Dyndoc.vars=@vars
  @filter=filterLoc unless @filter ##root filter
  out=""
#p texblock
  texblock.map{|b|
#p b
    cmd=b[0].to_s
    @curCmd=cmd
    cmd=@@cmdAlias[cmd] if @@cmdAlias.keys.include? cmd
#Dyndoc.warn "parse:cmd,b",[cmd,b]
    @@depth+=1
    ###TO temporarily AVOID RESCUE MODE:
    ###
    if true; method("do_"+cmd).call(out,b,filterLoc); else
    begin
      ## Dyndoc.warn "cmd",[cmd,b]
      method("do_"+cmd).call(out,b,filterLoc)
      ## Dyndoc.warn [:out,out] if cmd=="eval"
    rescue
      puts "=> Leaving block depth #{@@depth}: "
      codeText=b.inspect
      ##Dyndoc.warn "codeText",codeText
      nbChar=(Dyndoc.cfg_dyn[:nbChar_error]) ? Dyndoc.cfg_dyn[:nbChar_error] : 80
      if codeText.length > nbChar
        codeText=codeText[0..((nbChar*2/3).to_int)]+" ...... "+codeText[(-(nbChar/3).to_int)..-1]
      end
      puts codeText
      if @@depth==1
        puts "=> Exiting abnormally!\n"
        raise SystemExit
      else
        raise RuntimeError, "Dyn Runtime Error"
      end
    ensure
      @@depth -= 1
    end
    ###TO temporarily AVOID RESCUE MODE:
    ###
    end
  }
  ##restore old partTag and vars
  @tags=tagsOld if tags
  @tags.uniq!
  @vars=varsOld
  Dyndoc.vars=@vars
#Dyndoc.warn "parse:out",out
  return out
end

#parse_args(blck, filter) ⇒ Object



145
146
147
148
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 145

def parse_args(blck,filter)
  ## Dyndoc.warn "parse_args",blck
  parse(blck[1..-1],filter)
end

#parse_string(input, filterLoc = @filter, tags = []) ⇒ Object

same as parse except that input is a string and the filterLoc is the current one. Rmk: used in String::to_dyn



139
140
141
142
143
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 139

def parse_string(input,filterLoc=@filter,tags=[])
  init_tags(input)
  txt=input
  return parse(txt,filterLoc,tags)
end

#prepare_last_output(out) ⇒ Object

only once!!! Not like prepare_output which is called in {#dyn]pre:



338
339
340
341
342
343
344
# File 'lib/dyndoc/base/tmpl/manager.rb', line 338

def prepare_last_output(out)
  #puts "DYNDOC_RAW_TEXT! BEFORE";p out
  #p Utils.dyndoc_raw_text
  Utils.dyndoc_raw_text!(out,:clean=>true)
  #puts "DYNDOC_RAW_TEXT! AFTER";p out
  return out
end

#prepare_output(txt) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/dyndoc/base/tmpl/manager.rb', line 312

def prepare_output(txt)
  ## parse the content txt
  out=output_pre_model
#p out
#p Dyndoc.dyn_block[:first]
  ## dyn_block[:first] called in preloaded libraries!
  out << parse(Dyndoc.dyn_block[:first]) if Dyndoc.dyn_block[:first]
#puts "prepare_output";p out
  out << parse(txt)
#puts "prepare_output";p out
  ## dyn_block[:last] (for example, used to record some information)
  out << parse(Dyndoc.dyn_block[:last]) if Dyndoc.dyn_block[:last]
  out << output_post_model
  ## escape=true at the end in order to transform undefined variables in Latex!!!
##puts "prepare output: BEFORE apply";puts out
  out=@filter.apply(out,:post,false,true) if [:tex,:odt,:ttm,:html].include? @cfg[:format_doc]
##p [:prepare_output, out]
  #escape accolade!
  Utils.escape!(out,CHARS_SET_LAST)
##puts "prepare output: AFTER Utils.escape!";puts out
  out=Utils.unprotect_format_blocktext(out)
##p [:prepare_output, out]
  return out
end

#prepare_user_inputObject



350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/dyndoc/base/tmpl/manager.rb', line 350

def prepare_user_input
  ##puts "input";p @cfg[:input];p Dyndoc.cfg_dyn[:user_input]
  if @cfg[:input]
    @global["_"]={} unless @global["_"]
    @cfg[:input].each{|k,v|
      @global["_"][k.to_s] = {:val=>[v]}
    }
  end
  if Dyndoc.cfg_dyn[:user_input]
    @global["_"]={} unless @global["_"]
    Dyndoc.cfg_dyn[:user_input].each{|k,v|
      @global["_"][k.to_s] = {:val=>[v]}
    }
  end
end

#query_library(libname) ⇒ Object

## DONE: put in Document class

## writing in final file
def write(file)
  #@cfg[:append]="" unless @cfg[:append]
  out = output(file,true)

#puts out

  f=File.open(@cfg[:filename_doc],"w")
  f << out
  f.close
end


406
407
408
409
410
411
# File 'lib/dyndoc/base/tmpl/manager.rb', line 406

def query_library(libname)
  init_doc({:format_doc=>:tex})
  parse(Dyndoc.input_from_file(libname))
  p @calls.keys.sort
  p @meths.sort
end

#rbenvir_back_from(inRb) ⇒ Object



29
30
31
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 29

def rbenvir_back_from(inRb)
  @rbEnvir.shift if inRb
end

#rbenvir_currentObject



47
48
49
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 47

def rbenvir_current
  @rbEnvirs.keys.select{|b| @rbEnvirs[b]==@rbEnvir[0]}
end

#rbenvir_get(rbEnvir = nil) ⇒ Object



40
41
42
43
44
45
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 40

def rbenvir_get(rbEnvir=nil)
  rbEnvir=@rbEnvir[0] unless rbEnvir #the current if nil
  rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol
  rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer
  rbEnvir
end

#rbenvir_go_to(inRb, envir = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 16

def rbenvir_go_to(inRb,envir=nil)
  if inRb
    #puts "rbenvir_go_to #{inRb.inspect}"
    inRb=":new" if ["new","none",":none","nil"].include? inRb
    @rbEnvirs={} unless @rbEnvirs
#p inRb
    @rbEnvirs[inRb]=rbenvir_new if inRb==":new" or !@rbEnvirs[inRb]
    @rbEnvirs[inRb]=envir if envir and inRb!=":new"
#puts "rbenvir_go_to";p envir
    @rbEnvir.unshift(@rbEnvirs[inRb])
  end
end

#rbenvir_init(envir) ⇒ Object



6
7
8
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 6

def rbenvir_init(envir)
  @rbEnvir=[envir] 
end

#rbenvir_ls(rbEnvir = nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 33

def rbenvir_ls(rbEnvir=nil)
  rbEnvir=@rbEnvir[0] unless rbEnvir
  rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol
  rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer
  eval("local_variables",rbEnvir)
end

#rbenvir_newObject



10
11
12
13
14
# File 'lib/dyndoc/base/tmpl/rbenvir.rb', line 10

def rbenvir_new
  #l'objectif est que comme c'est une méthode toutes les 
  #fonctions de parsing de l'objet sont connues! 
  binding
end

#register_style_cmds(cmds, style, force = nil) ⇒ Object



1347
1348
1349
1350
1351
1352
1353
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1347

def register_style_cmds(cmds,style,force=nil)
  ## register cmds
  register_style_init
  cmds.each{|cmd|
    @styles[:cmd][cmd]=style if force or !@styles[:cmd][cmd]
  }
end

#register_style_initObject



1336
1337
1338
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1336

def register_style_init
  @styles={:cmd=>{},:class=>{},:alias=>{}} unless @styles
end

#register_style_meth(klass, meth) ⇒ Object



1340
1341
1342
1343
1344
1345
# File 'lib/dyndoc/base/tmpl/parse_do.rb', line 1340

def register_style_meth(klass,meth)
  register_style_init
  @styles[:class][klass]=[] unless @styles[:class][klass]
  @styles[:class][klass] << meth
  @styles[:class][klass].uniq!
end

#reinitObject



196
197
198
# File 'lib/dyndoc/base/tmpl/manager.rb', line 196

def reinit
  @blocks,@libs={},{}
end

#require_dyndoc_libs(libs) ⇒ Object



156
157
158
159
# File 'lib/dyndoc/base/tmpl/manager.rb', line 156

def require_dyndoc_libs(libs)
  libs="{#require]\n"+libs.split("\n").map{|lib| lib.split(",")}.flatten.uniq.join("\n")+"\n[#}\n"
  parse(libs,@filterGlobal)
end

#require_firstObject

equivalent to :pre_doc for not interactive document



152
153
154
# File 'lib/dyndoc/base/tmpl/manager.rb', line 152

def require_first
  require_dyndoc_libs("Dyn/Base")
end