dyndoc-ruby-core 1.2.6 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 959ac04a47a0a747a74d9fc9412693de2f16e3bb
4
- data.tar.gz: 1656c0ea29f80098f637aaf16b66774728e6d59a
2
+ SHA256:
3
+ metadata.gz: 37c974a007f31e6b20f6b08a58059b0bc9fa3985f0c1942d827cc9790e562186
4
+ data.tar.gz: d1dd34fd772846afa17963341fcb13d54fc66452a1370efe5c146b707cb361b0
5
5
  SHA512:
6
- metadata.gz: 92513ff73b9d2028e87848b27b8b8a9124d1a0c80e1c36574d3caf3cb9b1da7e942c8d6c549d8ee0bb972a1bbabcbb82bbc268fa10f4d78a56b3052789a61e83
7
- data.tar.gz: 2e0f677656d6b279cc85d4b7eda91740ee774b25702f01070e7b435fca73fe4df12993195a474600b6b050ba5df037f405b40b0093ae6be1e8295b3a209aeaa1
6
+ metadata.gz: 50a41020a4dd69fe0d261b416f80e6a8d3a78728599564850f65542fd64f5f1e8f8459d3e567edb3c6306789e70d587674fa822e09a4a55cc1ba73d17c6852c5
7
+ data.tar.gz: 9f0f7cf7f5f39015606e2c2c14bbfea6fb24b118b9a8222414e1e17bffc9eb1d5ba1b9213658e9055f07a1fb7d80e4ef4084f0756fed008684bfacdeaac9f3b2
@@ -0,0 +1,28 @@
1
+ [#rb<]
2
+ $jlfig=0
3
+ $jlfig_exts={:png=>".png",:jpeg =>".jpg",:pdf=>".pdf"}
4
+ [#<]
5
+
6
+ {#def]imgJL[#,] jlcode[] [#,] img[]
7
+ [#,] widthR[15] [#,] heightR[15][#,] unitR[cm][#,] resR[72][#,] optR[]
8
+ [#,] optTex[scale=0.75]
9
+ [#,] newR[TRUE]
10
+ [#=]delete[FALSE]
11
+ [#?]Dyndoc.tmpl_mngr.fmtOutput == "tex"[#<]
12
+ {#if]#{0?img}[#=]img[:{File.join($dyn_rsrc,"img","jlfig_:{$jlfig+=1}:{$jlfig_exts[:png]}")}]
13
+ [#else][#<]
14
+ {#if]File.dirname(#{=img})=="."[#>]img[:{File.join($dyn_rsrc,"img",#{=img})}][#if}
15
+ [#if}
16
+ [#?]Dyndoc.tmpl_mngr.fmtOutput == "html"[#<]
17
+ {#if]#{0?img}[#=]img[#r{gsub("\\\\","/",tempfile(fileext=".png"))}][#=]delete[TRUE][#if}
18
+ [#?]#{+?jlcode}[#<]#{jlcode}[#?]end
19
+ [#R<]require(base64)
20
+ #print(#{=img})
21
+ codeimg<-img(#{=img})
22
+ #print(codeimg)
23
+ if(#{delete}) unlink(#{=img})
24
+ [#?]Dyndoc.tmpl_mngr.fmtOutput == "html"
25
+ [#>][#r{codeimg}]
26
+ [#?]Dyndoc.tmpl_mngr.fmtOutput == "tex"
27
+ [#>][\includegraphics[#{optTex}]{#{img}}]
28
+ [#}
@@ -30,6 +30,9 @@ Settings.define 'cfg_dyn.cmd_pandoc_options', :type => Array, :default => []
30
30
  Settings.define 'cfg_dyn.options.pdflatex_nb_pass', :type => Integer, :default => 1
31
31
  Settings.define 'cfg_dyn.options.pdflatex_echo', :type => :boolean, :default => false
32
32
  Settings.define 'cfg_dyn.debug', :type => :boolean, :default => false
33
+ Settings.define 'cfg_dyn.parse_rescue', :type => :boolean, :default => true
34
+ Settings.define 'cfg_dyn.parse_rescue_mode', :type => Symbol, :default => :simple
35
+ Settings.define 'cfg_dyn.ruby_only', :type => :boolean, :default => false
33
36
 
34
37
  Settings.define 'cfg_dyn.dyndoc_session', :type => Symbol, :default => :normal #or :interactive
35
38
 
@@ -44,6 +47,7 @@ Settings.define 'cfg_dyn.devel_mode', :type=> Symbol, :default=> :none
44
47
  Settings.define 'cfg_dyn.ruby_debug', :type=> Symbol, :default=> :none
45
48
 
46
49
  Settings.define 'cfg_dyn.model_doc', :default => "default"
50
+ Settings.define 'cfg_dyn.exec_mode', :default => "no"
47
51
  Settings.define 'cfg_dyn.format_doc', :default => :tex
48
52
  Settings.define 'cfg_dyn.pandoc_filter', :default => ""
49
53
 
@@ -61,7 +65,7 @@ require 'dyndoc/init/config'
61
65
  Dyndoc.init_dyndoc_library_path
62
66
  Dyndoc.init_rootDoc
63
67
  Dyndoc.add_logger
64
- Dyndoc.logger.info("dyndoc-core loaded!")
68
+ ## Dyndoc.logger.info("dyndoc-core loaded!")
65
69
  ## Dyndoc.logger.info(".dyndoc.yml: "+File.join(ENV["HOME"],".dyndoc.yml"))
66
70
 
67
71
  CqlsDoc=Dyndoc #for compatibity
@@ -395,7 +395,7 @@ module Dyndoc
395
395
  when "@"
396
396
  return txt if @mode==:pre
397
397
  res=CallFilter.output(txt,self)
398
- when "#","##"
398
+ when "#","##","%"
399
399
  #p @envir
400
400
  #p @envir.output(txt,@mode,@escape)
401
401
  #p @envir.output(in_type+"{"+txt2+"}",@mode,@escape)
@@ -575,7 +575,7 @@ module Dyndoc
575
575
  else
576
576
  res.to_s
577
577
  end
578
- when "=","@=","#=","##=" ,"none="
578
+ when "=","@=","#=","%=","##=" ,"none="
579
579
  #puts "convert [=]";p res
580
580
  if res.is_a? Array
581
581
  res.join(",")
@@ -587,7 +587,7 @@ module Dyndoc
587
587
  "%Q{"+res2+"}"
588
588
  end
589
589
  end
590
- when "","@","#","##","none","#F"
590
+ when "","@","#","%","##","none","#F"
591
591
  if res.is_a? Array
592
592
  res.join(",")
593
593
  else
@@ -93,7 +93,9 @@ module Dyndoc
93
93
  end
94
94
 
95
95
  rescue SyntaxError
96
- puts "RbServer syntax error in: "+code
96
+
97
+ $outRbError="RbServer syntax error in: "+code
98
+ puts $outRbError
97
99
  raise SystemError if Dyndoc.cfg_dyn[:dyndoc_mode]==:normal and Dyndoc.cfg_dyn[:ruby_debug]!=:none
98
100
  if Dyndoc.cfg_dyn[:dyndoc_mode]!=:normal
99
101
  $dyn_logger.write("\nERROR Ruby Syntax:\n"+code+"\n")
@@ -104,10 +106,30 @@ module Dyndoc
104
106
  out
105
107
  end
106
108
 
109
+ def RbServer.redirect
110
+ if block_given?
111
+ require 'stringio'
112
+ begin
113
+ # redirect output to StringIO objects
114
+ oldstdout,oldstderr=$stdout, $stderr
115
+ stdout, stderr = StringIO.new, StringIO.new
116
+ $stdout, $stderr = stdout, stderr
117
+ yield
118
+ ensure
119
+ # restore normal output
120
+ $stdout, $stderr = oldstdout,oldstderr
121
+ end
122
+ return {stdout: stdout.string, stderr: stderr.string}
123
+ else
124
+ return {stdout: "", stderr: ""}
125
+ end
126
+
127
+ end
128
+
107
129
  def RbServer.capture(code,rbEnvir=nil)
108
130
 
109
131
  require 'stringio'
110
- require 'ostruct'
132
+ require 'ostruct'
111
133
 
112
134
  begin
113
135
  # redirect output to StringIO objects
@@ -273,10 +295,10 @@ module Dyndoc
273
295
  short[0]=short[0].to_i
274
296
  short[2]=short[2].to_i
275
297
  ## Dyndoc.warn "short",[short,txt]
276
- (0...short[0]).each{|i| txtout << txt[i].force_encoding("utf-8") << "\n"}
298
+ (0...short[0]).each{|i| txtout << (txt[i] ? txt[i].force_encoding("utf-8") : "") << "\n"}
277
299
  txtout << short[1] << "\n"
278
300
  le = txt.length
279
- ((le-short[2])...le).each{|i| txtout << txt[i].force_encoding("utf-8") << "\n"}
301
+ ((le-short[2])...le).each{|i| txtout << (txt[i] ? txt[i].force_encoding("utf-8") : "") << "\n"}
280
302
  else
281
303
  txt=txt.map{|e| e.force_encoding("utf-8")}
282
304
  txtout << txt.join("\n")
@@ -808,59 +830,73 @@ module Dyndoc
808
830
  @@initVerb=nil
809
831
 
810
832
  def JLServer.initVerb
811
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
833
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
834
+ Julia << "push!(Libdl.DL_LOAD_PATH,\"/usr/lib\");push!(Libdl.DL_LOAD_PATH,\"/usr/local/lib\")"
812
835
  @@initVerb=true
813
836
  end
814
837
 
815
838
  def JLServer.inputsAndOutputs(code,hash=true)
816
839
  JLServer.initVerb unless @@initVerb
817
- res=(Julia << 'capture_julia('+code.strip.inspect+')')
818
- ## Dyndoc.warn "JLServer.inputsAndOutputs",res
819
- res.map!{|input,output,output2,error,error2|
840
+ Dyndoc.logger.info("JLServer.inputsAndOutputs: "+code.strip)
841
+ res=(Julia << 'capture_output_julia('+code.strip.inspect.gsub("$","\\$")+')')
842
+ Dyndoc.logger.info("JLServer.inputsAndOutputs:"+res.inspect)
843
+ res.map!{|input,output,output2,error,error2|
820
844
  {:input=>input,:output=>output,:output2=>output2,:error=>error,:error2=>error2}
821
845
  } if res and hash
822
846
  res
823
847
  end
824
848
 
825
849
  def JLServer.eval(code)
826
- Julia.eval(code)
850
+ Julia.eval("capture_output_julia("+code.strip.inspect.gsub("$","\\$")+")")
827
851
  end
828
852
 
829
853
  def JLServer.output(code,opts={})
830
- opts={:print=>true}.merge(opts)
854
+ #opts={:print=>true}.merge(opts)
831
855
  ## Dyndoc.warn "jlserv",code+"|"+Julia.eval(code,:print=>opts[:print]).to_s
832
- Julia.eval(code,:print=>opts[:print]).to_s
856
+ #Julia.eval(code,:print=>opts[:print]).to_s
857
+
858
+ res=JLServer.inputsAndOutputs(code,false)
859
+ Dyndoc.warn "jlserv.output",[code,res]
860
+ return "" unless res
861
+ res=res.map{|input,output,output2,error,error2|
862
+ #Dyndoc.warn "output",output
863
+ output
864
+ }
865
+ res.length==0 ? "" : res[-1]
833
866
  end
834
867
 
835
868
  def JLServer.outputs(code,opts={}) #may have more than one lines in code
836
869
  ## Dyndoc.warn "JLServer.outputs opts",opts
837
- ## Dyndoc.warn "JLServer code",code
870
+ ##
871
+ Dyndoc.warn "JLServer code",code
872
+ res=JLServer.inputsAndOutputs(code,false)
838
873
  if opts[:block]
839
- res=JLServer.inputsAndOutputs(code,false)
840
874
  return "" unless res
841
875
  res.map{|input,output,output2,error,error2|
842
876
  ## Dyndoc.warn "output2",output2
843
- output2
877
+ output
844
878
  }.join("\n")
845
- else
846
- JLServer.eval(code)
847
879
  end
848
880
  end
849
881
 
850
882
  def JLServer.echo(code,prompt="julia> ",tab=2)
851
883
  out=""
852
884
  res=JLServer.inputsAndOutputs(code)
853
- ## Dyndoc.warn "JLServer",res
885
+ ##
886
+ Dyndoc.warn "JLServer",res
887
+ return "Error when executing: "+code unless res
854
888
  res.each do |cmd|
855
889
  ## Dyndoc.warn "input",cmd
856
890
  out << prompt+ cmd[:input].split("\n").each_with_index.map{|e,i| i==0 ? e : " "*(prompt.length)+e}.join("\n").gsub(/\t/," "*tab)
857
- out << "\n"
891
+ out << "\n" unless cmd[:input].strip[-1]==";"
858
892
  ## Dyndoc.warn "output1",out
859
- out << cmd[:output2]
860
- out << (cmd[:output]=="nothing" ? "" : cmd[:output])
861
- ## Dyndoc.warn "output2",out
862
- out << cmd[:error]!="" ? cmd[:error] : ""
863
- out << (cmd[:output]=="nothing" ? "" : "\n\n")
893
+ if cmd[:error]==""
894
+ out << ((cmd[:output]=="nothing" or (cmd[:input].strip)[-1]==";") ? "" : cmd[:output])
895
+ out << ((cmd[:output2]=="nothing" or (cmd[:input].strip)[-1]==";") ? "" : cmd[:output2]) #cmd[:output2]
896
+ else
897
+ out << cmd[:error]
898
+ end
899
+ out << (cmd[:output]=="nothing" ? "" : "\n")
864
900
  ## Dyndoc.warn "output3",out
865
901
  end
866
902
  out
@@ -219,7 +219,7 @@ module Dyndoc
219
219
  #IMPORTANT: process has to have as the second argument e[:type] corresponding to the inside_type and as the third argument res[:type] corresponding to the out_type
220
220
  ##Dyndoc.warn "scan",txt2,e[:type],res[:type],(filter ? filter.process(txt2,e[:type],res[:type]) : txt2)
221
221
  txt2=((filter and !(txt2=~/\[HTML\]/)) ? filter.process(txt2,e[:type],res[:type]) : txt2)
222
- ##p txt2
222
+ ##p [:txt2,txt2]
223
223
  txt << txt2
224
224
  end
225
225
  #puts "txt";p txt
@@ -232,7 +232,7 @@ module Dyndoc
232
232
  class CallScanner < Scanner
233
233
 
234
234
  @@type[:call]={
235
- :start=>/\\?(?:\#|\#\#|@|#F|#R|#r|\:R|\:r|#Rb|#rb|\:|\:Rb|\:rb|\:jl|#jl)?\{/,
235
+ :start=>/\\?(?:\#|\%|\#\#|@|#F|#R|#r|\:R|\:r|#Rb|#rb|\:|\:Rb|\:rb|\:jl|#jl)?\{/,
236
236
  :stop=> /\\?\}/,
237
237
  :mode=>{:start=>-1,:stop=>0,:length=>1},
238
238
  :escape_start=>['\{'], #doivent être parsable dans start
@@ -257,11 +257,11 @@ module Dyndoc
257
257
  }
258
258
  =end
259
259
  @@type[:dtag] = {
260
- :start=>'\{[\#\@]([\w\:\|-]*[<>]?[=?!><]?(\.\w*)?)\]',
261
- :stop=> '\[[\#\@]([\w\:\|-]*[<>]?[=?!><]?)\}',
262
- :atom=>{:match=>/(\{[\#\@][\w\:\|]*)([\#\@]\})/,:replace=>{2=>"][#}"}},
260
+ :start=>'\{[\#\@\%]([\w\:\|-]*[<>]?[=?!><]?(\.\w*)?)\]',
261
+ :stop=> '\[[\#\@\%]([\w\:\|-]*[<>]?[=?!><]?)\}',
262
+ :atom=>{:match=>/(\{[\#\@\%][\w\:\|]*)([\#\@\%]\})/,:replace=>{2=>"][#}"}},
263
263
  :block=> '\]', #no longer |
264
- :keyword=>['\[[\#\@]','\]'],
264
+ :keyword=>['\[[\#\%\@]','\]'],
265
265
  :mode=>{:start=>0,:stop=>-1,:length=>1}
266
266
  }
267
267
 
@@ -275,7 +275,7 @@ module Dyndoc
275
275
  init_tag(@tag_type) if [:dtag].include? @tag_type
276
276
  end
277
277
 
278
- @@tagblck_set=[:<<,:<,:do,:>>,:>,:">!",:out,:nl,:"\\n",:"r<",:"R<",:"rb<",:"m<",:"M<",:"jl<",:"r>>",:"R>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:rout,:"r>",:"R>",:"rb>",:"m>",:"M>",:"jl>",:"_<",:"_>",:"__>",:"html>",:"tex>",:"txtl>",:"ttm>",:"md>",:"adoc>",:tag,:"??",:"?",:yield,:"=",:"-",:+,:"%",:"tex=",:"tex+",:"md=",:"md+",:"adoc=",:"adoc+",:"html=",:"html+",:"rb=",:"rb+",:"R=",:"R+",:"jl=",:"jl+",:"txtl=",:"txtl+"]
278
+ @@tagblck_set=[:<<,:<,:do,:>>,:>,:">!",:out,:nl,:"\\n",:"r<",:"R<",:"rb<",:"m<",:"M<",:"jl<",:"sh<",:"r>>",:"R>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:rout,:"r>",:"R>",:"rb>",:"m>",:"M>",:"jl>",:"_<",:"_>",:"__>",:"html>",:"tex>",:"txtl>",:"ttm>",:"md>",:"adoc>",:tag,:"??",:"?",:yield,:"=",:"-",:+,:"%",:"tex=",:"tex+",:"md=",:"md+",:"adoc=",:"adoc+",:"html=",:"html+",:"rb=",:"rb+",:"R=",:"R+",:"jl=",:"jl+",:"txtl=",:"txtl+"]
279
279
  #Rmk: when a symbol is included in another one, you have to place it before! Ex: :>> before :> and also :<< before :<
280
280
 
281
281
  @@tagblck_dyndoc_set = [:main,:content,:before,:after,:require,:helpers,:preamble,:postamble,:style,:title,:path,:first,:last,:default,:cfg]
@@ -302,6 +302,7 @@ module Dyndoc
302
302
  :"rb<" => [:blck, :"rb<"],
303
303
  :"R<" => [:blck, :"R<"],
304
304
  :"jl<" => [:blck, :"jl<"],
305
+ :"sh<" => [:blck, :"sh<"],
305
306
  :"r>>" => [:blck, :"r>>"],
306
307
  :"R>>" => [:blck, :"r>>"],
307
308
  :"*<" => [:blck, :"*<"],
@@ -366,7 +367,7 @@ module Dyndoc
366
367
  },
367
368
  :mode_arg=>:next_block,
368
369
  :tag_code=>[:code,:<,:>,:<<,:txt], #used for arg mode!
369
- :arg=>[:if,:unless,:elsif,:for,:case,:def,:func,:meth,:new,:super,:call,:input,:when,:break,:set,:style,:keys,:"?",:"rb<",:"r<",:"R<",:"m<",:"M<",:"jl<"],
370
+ :arg=>[:if,:unless,:elsif,:for,:case,:def,:func,:meth,:new,:super,:call,:input,:when,:break,:set,:style,:keys,:"?",:"rb<",:"r<",:"R<",:"m<",:"M<",:"jl<",:"sh<"],
370
371
  :blck=>{
371
372
  :instr=>[:document,:if,:unless,:case,:loop,:set,:tag,:keys,:rverb,:rbverb,:jlverb,:for],
372
373
  :keyword=>{
@@ -620,11 +621,12 @@ module Dyndoc
620
621
  end
621
622
  ##Dyndoc.warn "to scan", @scan.string[@scan.pos..-1]
622
623
  ##Dyndoc.warn "tag_reg",[blocktag_reg,tag_reg]
624
+ ##p ["tag_reg",[blocktag_reg,tag_reg]]
623
625
  end
624
626
  if (tag_keyword and (@scan.check_until(blocktag_reg))) #or (!@named_tags.empty? and check_until_for_named_tags)
625
627
  check_until_for_named_tags unless @named_tags.empty?
626
628
  key=@scan[2]
627
- ##Dyndoc.warn "keyword",[key,@scan[0],@scan[1],@scan[2]]
629
+ ##Dyndoc.warn p ["keyword",[key.scan(tag_reg),key.scan(tag_reg)[-1],key,@scan[0],@scan[1],@scan[2]]]
628
630
  ##Dyndoc.warn "pre_math,tag_selected",[@scan.pre_match,@tag_selected] if key=="[#tag]"
629
631
  res << find_text(from,key,inside)
630
632
  @is_arg=false if @is_arg
@@ -634,7 +636,7 @@ module Dyndoc
634
636
  res << (key=@tag_selected)
635
637
  else
636
638
  #key=tag_reg.match(key)[0]
637
- key= key.scan(tag_reg)[0]
639
+ key= key.scan(tag_reg)[-1]
638
640
  ##Dyndoc.warn "key(AP)",key if key=="tag"
639
641
  res << (key=key.to_sym) if key and !key.empty?
640
642
  end
@@ -201,13 +201,15 @@ module Dyndoc
201
201
  #p input
202
202
  =end
203
203
  # REPLACEMENT of ABOVE!
204
- unless @libs.keys.include? tmpl
205
- input=Dyndoc.read_content_file(tmpl)
206
- @libs[tmpl]=input
207
- filter.envir["_FILENAME_"]=tmpl.dup #register name of template!!!
208
- filter.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!!
209
- filter.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!!
210
- txt=parse(@libs[tmpl],filter,tags)
204
+ unless @libs.keys.include? tmpl
205
+ if tmpl and File.exists? tmpl
206
+ input=Dyndoc.read_content_file(tmpl)
207
+ @libs[tmpl]=input
208
+ filter.envir["_FILENAME_"]=tmpl.dup #register name of template!!!
209
+ filter.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!!
210
+ filter.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!!
211
+ txt=parse(@libs[tmpl],filter,tags)
212
+ end
211
213
  end
212
214
  }
213
215
  end
@@ -89,16 +89,17 @@ module Dyndoc
89
89
  # init rb4jl stuff
90
90
  # since inside ruby, no need Ruby.start and Ruby.stop like in rb4R.
91
91
  # sort of equivalent of JLServer.init_filter (but not yet defined)!
92
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+"\")"
92
+ #Julia << "Base.include(@__MODULE__,\"ruby.jl\")"
93
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+ "\")"
93
94
  Dyndoc.logger.info "initJulia: ruby.jl"
94
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+"\")"
95
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+ "\")"
95
96
  Dyndoc.logger.info "initJulia: dynArray.jl"
96
97
  #-| To debug ruby.jl and dynArray.jl => uncomment below and commnt above
97
98
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/ruby.jl")+"\")"
98
99
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/dynArray.jl")+"\")"
99
- Julia << "using Dyndoc"
100
+ Julia << "using Main.Dyndoc"
100
101
  Dyndoc.logger.info "initJulia: using Dyndoc"
101
- Julia << "Ruby.alive(true)"
102
+ Julia << "Dyndoc.Ruby.alive(true)"
102
103
  #Julia << "global const _dynArray=DynArray()"
103
104
  Dyndoc.logger.info "Julia initialized inside dyndoc!"
104
105
 
@@ -120,8 +121,10 @@ module Dyndoc
120
121
  @cfg[:part_tag][0]=@cfg[:part_tag][0][1..-1] if !(@cfg[:part_tag].empty?) and (@partTag_add= (@cfg[:part_tag][0][0,1]=="+"))
121
122
  =end
122
123
  ## default system root appended
123
- TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R
124
- TemplateManager.initJulia if Dyndoc.cfg_dyn[:langs].include? :jl
124
+ unless Dyndoc.cfg_dyn[:ruby_only]
125
+ TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R
126
+ TemplateManager.initJulia if Dyndoc.cfg_dyn[:langs].include? :jl
127
+ end
125
128
  rbenvir_init(binding)
126
129
  @rEnvir=["Global"]
127
130
  @envirs={}
@@ -1,5 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'securerandom'
4
+
3
5
  ## TODO: .force_encoding("utf-8") needs to be added (see server.rb)
4
6
  module Dyndoc
5
7
 
@@ -26,10 +28,11 @@ module Dyndoc
26
28
  class TemplateManager
27
29
 
28
30
  @@depth=0
31
+ @@outError=""
29
32
 
30
33
  @@cmd=["newBlck","input","require","def","func","meth","new","super","blck","do","if","for","case", "loop","r","renv","rverb","rbverb","jlverb","rout","rb","var","set","hide","format","txt","code","<","<<",">","eval","ifndef","tags","keys","opt","document","yield","get","part","style"]
31
34
  ## Alias
32
- @@cmdAlias={"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","<"=>"txt","<<"=>"txt",">"=>"txt","code"=>"txt","dyn"=>"eval","r>>"=>"rverb","R>>"=>"rverb","rout"=>"rverb","rb>>" => "rbverb","jl>>" => "jlverb","saved"=>"blck","blckAnyTag"=>"blck"}
35
+ @@cmdAlias={"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"}
33
36
  @@cmd += @@cmdAlias.keys
34
37
 
35
38
  def add_dtag(dtag,cmdAlias=nil)
@@ -87,7 +90,7 @@ module Dyndoc
87
90
  @vars,varsOld=filterLoc.envir,@vars
88
91
  Dyndoc.vars=@vars
89
92
  @filter=filterLoc unless @filter ##root filter
90
- out=""
93
+ out,$outError ="",""
91
94
  #p texblock
92
95
  texblock.map{|b|
93
96
  #p b
@@ -96,33 +99,49 @@ module Dyndoc
96
99
  cmd=@@cmdAlias[cmd] if @@cmdAlias.keys.include? cmd
97
100
  #Dyndoc.warn "parse:cmd,b",[cmd,b]
98
101
  @@depth+=1
99
- ###TO temporarily AVOID RESCUE MODE:
100
- ###
101
- if true; method("do_"+cmd).call(out,b,filterLoc); else
102
- begin
103
- ## Dyndoc.warn "cmd",[cmd,b]
104
- method("do_"+cmd).call(out,b,filterLoc)
105
- ## Dyndoc.warn [:out,out] if cmd=="eval"
106
- rescue
107
- puts "=> Leaving block depth #{@@depth}: "
108
- codeText=b.inspect
109
- ##Dyndoc.warn "codeText",codeText
110
- nbChar=(Dyndoc.cfg_dyn[:nbChar_error]) ? Dyndoc.cfg_dyn[:nbChar_error] : 80
111
- if codeText.length > nbChar
112
- codeText=codeText[0..((nbChar*2/3).to_int)]+" ...... "+codeText[(-(nbChar/3).to_int)..-1]
113
- end
114
- puts codeText
115
- if @@depth==1
116
- puts "=> Exiting abnormally!\n"
117
- raise SystemExit
118
- else
119
- raise RuntimeError, "Dyn Runtime Error"
102
+ ## To deactivate, put it inside ~/.dyndoc.yml
103
+ if Dyndoc.cfg_dyn[:parse_rescue]
104
+ begin
105
+ ## Dyndoc.warn "cmd",[cmd,b]
106
+ method("do_"+cmd).call(out,b,filterLoc)
107
+ ## Dyndoc.warn [:out,out] if cmd=="eval"
108
+ rescue
109
+ $outError << "=> Leaving block depth #{@@depth}: " << "\n"
110
+ codeText = b.inspect
111
+ ##Dyndoc.warn "codeText",codeText
112
+ nbChar=(Dyndoc.cfg_dyn[:nbChar_error]) ? Dyndoc.cfg_dyn[:nbChar_error] : 80
113
+ if codeText.length > nbChar
114
+ codeText=codeText[0..((nbChar*2/3).to_int)]+" ...... "+codeText[(-(nbChar/3).to_int)..-1]
115
+ end
116
+ $outError << codeText << "\n"
117
+ if $outRbError && !$outRbError.empty?
118
+ $outError << $outRbError << "\n"
119
+ $outRbError = ""
120
+ end
121
+ if @@depth==1
122
+ $outError << "=> Exiting abnormally!</code>" << "\n"
123
+ @@outError << "<pre style='background-color: #EBECE4;'><code>"+$outError+"</code></pre>" << "\n"
124
+ puts "@@outError: \n"+@@outError
125
+ #raise SystemExit
126
+ out << @@outError
127
+ @@outError=""
128
+ else
129
+ @@outError << "<pre style='background-color: #EBECE4;'><code>Dyn Runtime Error\n"+$outError+"</code></pre>"
130
+ $outError=""
131
+ if Dyndoc.cfg_dyn[:parse_rescue_mode]==:simple
132
+ out << @@outError
133
+ @@outError=""
134
+ else
135
+ raise RuntimeError, "Dyn Runtime Error"
136
+ end
137
+ end
138
+ Dyndoc.warn "out #{@@depth} :",$outError
139
+
140
+ ensure
141
+ @@depth -= 1
120
142
  end
121
- ensure
122
- @@depth -= 1
123
- end
124
- ###TO temporarily AVOID RESCUE MODE:
125
- ###
143
+ else
144
+ method("do_"+cmd).call(out,b,filterLoc)
126
145
  end
127
146
  }
128
147
  ##restore old partTag and vars
@@ -404,7 +423,7 @@ p [vars,b2]
404
423
  if @@newBlcks.keys.include? @blckDepth[-1]
405
424
  @blckName ||= []
406
425
  tmp=blck[1][1].strip
407
- @blckName << (tmp.empty? ? `uuidgen`.strip : tmp)
426
+ @blckName << (tmp.empty? ? SecureRandom.uuid.strip : tmp)
408
427
  #puts "blckNAME";p @blckName
409
428
  end
410
429
 
@@ -482,7 +501,7 @@ p [vars,b2]
482
501
  when :do,:<
483
502
  i,*b2=next_block(blck,i)
484
503
  parse(b2,filter) if cond_tag and cond
485
- when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<"
504
+ when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<",:"sh<"
486
505
  # if current_block_tag==:"jl<"
487
506
  # ##p "iciiiii"
488
507
  # end
@@ -498,7 +517,7 @@ p [vars,b2]
498
517
  b2=[code.unshift(newblck)]
499
518
  ##puts "r<;rb<";p b2
500
519
  filter.outType=":"+(blck[i].to_s)[0...-1]
501
- #p filter.outType
520
+ #Dyndoc.warn "rb,jl,R block",filter.outType
502
521
  parse(b2,filter)
503
522
  filter.outType=nil
504
523
  end
@@ -1056,7 +1075,7 @@ p [vars,b2]
1056
1075
  when :binding
1057
1076
  i,*b2=next_block(blck,i)
1058
1077
  rbEnvir=b2[0][1].strip
1059
- when :do,:<,:out,:>,:"r<",:"rb<",:"r>",:"R>",:"R<",:"r>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:"rb>",:"?",:tag,:"??",:yield,:>>,:"=",:"+",:<<,:"txtl>",:"md>",:"adoc>",:"ttm>",:"html>",:"tex>",:"_>"
1078
+ 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>",:"_>"
1060
1079
  code = blck[i..-1].unshift(:blck)
1061
1080
  when :","
1062
1081
  i,*b2=next_block(blck,i)
@@ -2138,6 +2157,7 @@ p call
2138
2157
  def do_jl(tex,blck,filter)
2139
2158
  return unless Dyndoc.cfg_dyn[:langs].include? :jl
2140
2159
  ## jlBlock stuff
2160
+ ## Dyndoc.warn "do_jl",blck
2141
2161
  as_default_tmpl_mngr! if
2142
2162
  dynBlock=dynBlock_in_doLangBlock?(blck)
2143
2163
  if dynBlock
@@ -2161,7 +2181,7 @@ p call
2161
2181
  as_default_tmpl_mngr!
2162
2182
  tex << JLServer.outputs(code,:block => true)
2163
2183
  else
2164
- JLServer.eval(code)
2184
+ JLServer.outputs(code)
2165
2185
  end
2166
2186
  ## revert all the stuff
2167
2187
  if dynBlock
@@ -2171,6 +2191,15 @@ p call
2171
2191
  filter.outType=nil
2172
2192
  end
2173
2193
 
2194
+ def do_sh(tex,blck,filter)
2195
+ #Dyndoc.warn "do_sh: blck ";p blck[1..-1]
2196
+ filter.outType="none"
2197
+ code=parse(blck[1..-1],filter)
2198
+ %x[ #{code} ]
2199
+ #Dyndoc.warn "do_sh: code ";p code
2200
+ filter.outType=nil
2201
+ end
2202
+
2174
2203
  def do_m(tex,blck,filter)
2175
2204
  newblck=blck[0]
2176
2205
  # Dyndoc.warn "do_m";p blck