dyndoc-ruby-core 1.2.3 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 96cc8056fc32b8e3e88f8f689d8cc5c923fc563c
4
- data.tar.gz: 3ecb5ff17a16a5bf8f528f2bbd6b09a031e61ec3
2
+ SHA256:
3
+ metadata.gz: 43743c1ff1beb4c4f53a80874dda62d41be396be2358a723805a6137895a8519
4
+ data.tar.gz: a9b1266ed703968a8ffad14deff056e9ed8de134355b73b47aa21fa3718e52a1
5
5
  SHA512:
6
- metadata.gz: cdd8fd694820fd0591568af526139adb363a25d633f1d4eee7eea06e84bdb4ce198e3f87d3700d0dc68e58bf3925842748b2095cfa35aeebb7fb1e12b8fc7a7b
7
- data.tar.gz: 7321db26f0dc1f66954e34e982ed852a7230afc031c54cf37789461dd21ace084ff5ef95c0c9547f9350248d6ab1e658115ed30290123a64f6675cc3a719dd4f
6
+ metadata.gz: 557f72a70d51e5d0d533f2ccc5f9047f5e07659ecb744e642a95c7cc518c6f9db674f8be84746230437fc32829cfc910f398b1b0b18072f8174b847e0bd6010e
7
+ data.tar.gz: 601fe0897cdeb6a832c0eb1f5d19d70e7e361cd3917917ebdeb31501f229266168203119b2dbaed705cc9201f2055d99d6dbb800de55e0474e5c8b7b984313b2
@@ -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,7 @@ 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.ruby_only', :type => :boolean, :default => false
33
34
 
34
35
  Settings.define 'cfg_dyn.dyndoc_session', :type => Symbol, :default => :normal #or :interactive
35
36
 
@@ -44,6 +45,7 @@ Settings.define 'cfg_dyn.devel_mode', :type=> Symbol, :default=> :none
44
45
  Settings.define 'cfg_dyn.ruby_debug', :type=> Symbol, :default=> :none
45
46
 
46
47
  Settings.define 'cfg_dyn.model_doc', :default => "default"
48
+ Settings.define 'cfg_dyn.exec_mode', :default => "no"
47
49
  Settings.define 'cfg_dyn.format_doc', :default => :tex
48
50
  Settings.define 'cfg_dyn.pandoc_filter', :default => ""
49
51
 
@@ -60,5 +62,8 @@ Settings.resolve!
60
62
  require 'dyndoc/init/config'
61
63
  Dyndoc.init_dyndoc_library_path
62
64
  Dyndoc.init_rootDoc
65
+ Dyndoc.add_logger
66
+ ## Dyndoc.logger.info("dyndoc-core loaded!")
67
+ ## Dyndoc.logger.info(".dyndoc.yml: "+File.join(ENV["HOME"],".dyndoc.yml"))
63
68
 
64
69
  CqlsDoc=Dyndoc #for compatibity
@@ -104,10 +104,30 @@ module Dyndoc
104
104
  out
105
105
  end
106
106
 
107
+ def RbServer.redirect
108
+ if block_given?
109
+ require 'stringio'
110
+ begin
111
+ # redirect output to StringIO objects
112
+ oldstdout,oldstderr=$stdout, $stderr
113
+ stdout, stderr = StringIO.new, StringIO.new
114
+ $stdout, $stderr = stdout, stderr
115
+ yield
116
+ ensure
117
+ # restore normal output
118
+ $stdout, $stderr = oldstdout,oldstderr
119
+ end
120
+ return {stdout: stdout.string, stderr: stderr.string}
121
+ else
122
+ return {stdout: "", stderr: ""}
123
+ end
124
+
125
+ end
126
+
107
127
  def RbServer.capture(code,rbEnvir=nil)
108
128
 
109
129
  require 'stringio'
110
- require 'ostruct'
130
+ require 'ostruct'
111
131
 
112
132
  begin
113
133
  # redirect output to StringIO objects
@@ -273,10 +293,10 @@ module Dyndoc
273
293
  short[0]=short[0].to_i
274
294
  short[2]=short[2].to_i
275
295
  ## Dyndoc.warn "short",[short,txt]
276
- (0...short[0]).each{|i| txtout << txt[i].force_encoding("utf-8") << "\n"}
296
+ (0...short[0]).each{|i| txtout << (txt[i] ? txt[i].force_encoding("utf-8") : "") << "\n"}
277
297
  txtout << short[1] << "\n"
278
298
  le = txt.length
279
- ((le-short[2])...le).each{|i| txtout << txt[i].force_encoding("utf-8") << "\n"}
299
+ ((le-short[2])...le).each{|i| txtout << (txt[i] ? txt[i].force_encoding("utf-8") : "") << "\n"}
280
300
  else
281
301
  txt=txt.map{|e| e.force_encoding("utf-8")}
282
302
  txtout << txt.join("\n")
@@ -808,59 +828,73 @@ module Dyndoc
808
828
  @@initVerb=nil
809
829
 
810
830
  def JLServer.initVerb
811
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
812
- @@initVerb=true
831
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dyndoc.jl")+"\")"
832
+ Julia << "push!(Libdl.DL_LOAD_PATH,\"/usr/lib\");push!(Libdl.DL_LOAD_PATH,\"/usr/local/lib\")"
833
+ @@initVerb=true
813
834
  end
814
835
 
815
836
  def JLServer.inputsAndOutputs(code,hash=true)
816
837
  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|
838
+ Dyndoc.logger.info("JLServer.inputsAndOutputs: "+code.strip)
839
+ res=(Julia << 'capture_output_julia('+code.strip.inspect.gsub("$","\\$")+')')
840
+ Dyndoc.logger.info("JLServer.inputsAndOutputs:"+res.inspect)
841
+ res.map!{|input,output,output2,error,error2|
820
842
  {:input=>input,:output=>output,:output2=>output2,:error=>error,:error2=>error2}
821
- } if hash
843
+ } if res and hash
822
844
  res
823
845
  end
824
846
 
825
847
  def JLServer.eval(code)
826
- Julia.eval(code)
848
+ Julia.eval("capture_output_julia("+code.strip.inspect.gsub("$","\\$")+")")
827
849
  end
828
850
 
829
851
  def JLServer.output(code,opts={})
830
- opts={:print=>true}.merge(opts)
852
+ #opts={:print=>true}.merge(opts)
831
853
  ## Dyndoc.warn "jlserv",code+"|"+Julia.eval(code,:print=>opts[:print]).to_s
832
- Julia.eval(code,:print=>opts[:print]).to_s
854
+ #Julia.eval(code,:print=>opts[:print]).to_s
855
+
856
+ res=JLServer.inputsAndOutputs(code,false)
857
+ Dyndoc.warn "jlserv.output",[code,res]
858
+ return "" unless res
859
+ res=res.map{|input,output,output2,error,error2|
860
+ #Dyndoc.warn "output",output
861
+ output
862
+ }
863
+ res.length==0 ? "" : res[-1]
833
864
  end
834
865
 
835
866
  def JLServer.outputs(code,opts={}) #may have more than one lines in code
836
867
  ## Dyndoc.warn "JLServer.outputs opts",opts
837
- ## Dyndoc.warn "JLServer code",code
868
+ ##
869
+ Dyndoc.warn "JLServer code",code
870
+ res=JLServer.inputsAndOutputs(code,false)
838
871
  if opts[:block]
839
- res=JLServer.inputsAndOutputs(code,false)
840
872
  return "" unless res
841
873
  res.map{|input,output,output2,error,error2|
842
874
  ## Dyndoc.warn "output2",output2
843
- output2
875
+ output
844
876
  }.join("\n")
845
- else
846
- JLServer.eval(code)
847
877
  end
848
878
  end
849
879
 
850
880
  def JLServer.echo(code,prompt="julia> ",tab=2)
851
881
  out=""
852
882
  res=JLServer.inputsAndOutputs(code)
853
- ## Dyndoc.warn "JLServer",res
883
+ ##
884
+ Dyndoc.warn "JLServer",res
885
+ return "Error when executing: "+code unless res
854
886
  res.each do |cmd|
855
887
  ## Dyndoc.warn "input",cmd
856
888
  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"
889
+ out << "\n" unless cmd[:input].strip[-1]==";"
858
890
  ## 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")
891
+ if cmd[:error]==""
892
+ out << ((cmd[:output]=="nothing" or (cmd[:input].strip)[-1]==";") ? "" : cmd[:output])
893
+ out << ((cmd[:output2]=="nothing" or (cmd[:input].strip)[-1]==";") ? "" : cmd[:output2]) #cmd[:output2]
894
+ else
895
+ out << cmd[:error]
896
+ end
897
+ out << (cmd[:output]=="nothing" ? "" : "\n")
864
898
  ## Dyndoc.warn "output3",out
865
899
  end
866
900
  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
@@ -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,:"=",:"-",:+,:"%"]
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=>{
@@ -512,7 +513,7 @@ module Dyndoc
512
513
  else
513
514
  @dtag[:named_tag][key][:tag].sub("_TAG_",Regexp.escape( key.to_s ))
514
515
  end
515
- else
516
+ else
516
517
  return Regexp.escape(key.to_s)
517
518
  end
518
519
  end
@@ -77,23 +77,31 @@ module Dyndoc
77
77
  if RUBY_PLATFORM =~ /mingw/
78
78
  require File.join(ENV["DYNDOC_HOME"],"bin","msys2","file_tools.rb") if ENV["DYNDOC_HOME"]
79
79
  end
80
+ Dyndoc.logger.info "R initialized inside dyndoc!"
80
81
  end
81
82
 
82
83
  def TemplateManager.initJulia
84
+ Dyndoc.logger.info "initJulia: first"
83
85
  first=require "jl4rb" #save if it the first initialization!
86
+ Dyndoc.logger.info "initJulia: require"
84
87
  Julia.init
88
+ Dyndoc.logger.info "initJulia: init"
85
89
  # init rb4jl stuff
86
90
  # since inside ruby, no need Ruby.start and Ruby.stop like in rb4R.
87
91
  # sort of equivalent of JLServer.init_filter (but not yet defined)!
88
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+"\")"
89
- Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+"\")"
92
+ #Julia << "Base.include(@__MODULE__,\"ruby.jl\")"
93
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+ "\")"
94
+ Dyndoc.logger.info "initJulia: ruby.jl"
95
+ Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+ "\")"
96
+ Dyndoc.logger.info "initJulia: dynArray.jl"
90
97
  #-| To debug ruby.jl and dynArray.jl => uncomment below and commnt above
91
98
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/ruby.jl")+"\")"
92
99
  # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/dynArray.jl")+"\")"
93
- Julia << "using Dyndoc"
94
- Julia << "Ruby.alive(true)"
100
+ Julia << "using Main.Dyndoc"
101
+ Dyndoc.logger.info "initJulia: using Dyndoc"
102
+ Julia << "Dyndoc.Ruby.alive(true)"
95
103
  #Julia << "global const _dynArray=DynArray()"
96
- Dyndoc.warn "Julia initialized inside dyndoc!"
104
+ Dyndoc.logger.info "Julia initialized inside dyndoc!"
97
105
 
98
106
  end
99
107
 
@@ -113,8 +121,10 @@ module Dyndoc
113
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]=="+"))
114
122
  =end
115
123
  ## default system root appended
116
- TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R
117
- 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
118
128
  rbenvir_init(binding)
119
129
  @rEnvir=["Global"]
120
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
 
@@ -29,7 +31,7 @@ module Dyndoc
29
31
 
30
32
  @@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
33
  ## 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"}
34
+ @@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
35
  @@cmd += @@cmdAlias.keys
34
36
 
35
37
  def add_dtag(dtag,cmdAlias=nil)
@@ -65,9 +67,9 @@ module Dyndoc
65
67
  Utils.escape!(texblock,CHARS_SET_FIRST)
66
68
  Utils.clean_bom_utf8!(texblock)
67
69
  Utils.silence_warnings do
68
- texblock=@scan.process("{#document][#content]" + texblock + "[#}")
70
+ texblock=@scan.process("{#document][#content]" + texblock + "[#document}")
69
71
  end
70
- ## Dyndoc.warn "parsed",texblock
72
+ ##Dyndoc.warn "parsed",texblock
71
73
  end
72
74
  #p "texblock";p texblock
73
75
  unless filterLoc
@@ -404,7 +406,7 @@ p [vars,b2]
404
406
  if @@newBlcks.keys.include? @blckDepth[-1]
405
407
  @blckName ||= []
406
408
  tmp=blck[1][1].strip
407
- @blckName << (tmp.empty? ? `uuidgen`.strip : tmp)
409
+ @blckName << (tmp.empty? ? SecureRandom.uuid.strip : tmp)
408
410
  #puts "blckNAME";p @blckName
409
411
  end
410
412
 
@@ -482,7 +484,7 @@ p [vars,b2]
482
484
  when :do,:<
483
485
  i,*b2=next_block(blck,i)
484
486
  parse(b2,filter) if cond_tag and cond
485
- when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<"
487
+ when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<",:"sh<"
486
488
  # if current_block_tag==:"jl<"
487
489
  # ##p "iciiiii"
488
490
  # end
@@ -498,11 +500,12 @@ p [vars,b2]
498
500
  b2=[code.unshift(newblck)]
499
501
  ##puts "r<;rb<";p b2
500
502
  filter.outType=":"+(blck[i].to_s)[0...-1]
501
- #p filter.outType
503
+ #Dyndoc.warn "rb,jl,R block",filter.outType
502
504
  parse(b2,filter)
503
505
  filter.outType=nil
504
506
  end
505
- when :"=" #equivalent of :var but DO NOT USE :var
507
+ #equivalent of :var but DO NOT USE :var
508
+ when :"=",:"tex=",:"md=",:"adoc=",:"txtl=",:"html=",:"rb=",:"R=",:"jl="
506
509
  i,*b2=next_block(blck,i)
507
510
  if cond_tag and cond
508
511
  #puts "=:b2";p b2
@@ -516,7 +519,7 @@ p [vars,b2]
516
519
  #puts "-:b2"
517
520
  parse(b2,filter).strip.split(",").each{|key| @vars.remove(key)}
518
521
  end
519
- when :+
522
+ when :+,:"tex+",:"md+",:"adoc+",:"txtl+",:"html+",:"rb+",:"R+",:"jl+"
520
523
  ##Dyndoc.warn "+:-1:block",[i,blck]
521
524
  i,*b2=next_block(blck,i)
522
525
  ##Dyndoc.warn "+:0:i,b2",[i,b2]
@@ -569,7 +572,7 @@ p [vars,b2]
569
572
  #puts "varNew:#{var}";p @vars.extract_raw(var)
570
573
  end
571
574
  end
572
- when :out,:>,:">!" # :>! is in some sense equivalent of :set
575
+ when :out,:>,:">!" # :>! is in some sense equivalent of :set
573
576
  i,*b2=next_block(blck,i)
574
577
  #puts "block >, cond_tag, cond";p cond_tag ;p cond
575
578
  if cond_tag and cond and !b2.empty?
@@ -1055,7 +1058,7 @@ p [vars,b2]
1055
1058
  when :binding
1056
1059
  i,*b2=next_block(blck,i)
1057
1060
  rbEnvir=b2[0][1].strip
1058
- when :do,:<,:out,:>,:"r<",:"rb<",:"r>",:"R>",:"R<",:"r>>",:rverb,:"rb>>",:rbverb,:"jl>>",:jlverb,:"rb>",:"?",:tag,:"??",:yield,:>>,:"=",:"+",:<<,:"txtl>",:"md>",:"adoc>",:"ttm>",:"html>",:"tex>",:"_>"
1061
+ 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>",:"_>"
1059
1062
  code = blck[i..-1].unshift(:blck)
1060
1063
  when :","
1061
1064
  i,*b2=next_block(blck,i)
@@ -1231,6 +1234,8 @@ p call
1231
1234
  #p var
1232
1235
  end
1233
1236
  end while i<blck.length-1
1237
+ ## IMPORTANT: special treatment for default empty block to avoid infinit loop
1238
+ code["default"] << :out << [:main,""] if code["default"].length==1
1234
1239
  code.each_key{|k| code.delete(k) if code[k].length==1 }
1235
1240
  return [var,code]
1236
1241
  end
@@ -2135,6 +2140,7 @@ p call
2135
2140
  def do_jl(tex,blck,filter)
2136
2141
  return unless Dyndoc.cfg_dyn[:langs].include? :jl
2137
2142
  ## jlBlock stuff
2143
+ ## Dyndoc.warn "do_jl",blck
2138
2144
  as_default_tmpl_mngr! if
2139
2145
  dynBlock=dynBlock_in_doLangBlock?(blck)
2140
2146
  if dynBlock
@@ -2158,7 +2164,7 @@ p call
2158
2164
  as_default_tmpl_mngr!
2159
2165
  tex << JLServer.outputs(code,:block => true)
2160
2166
  else
2161
- JLServer.eval(code)
2167
+ JLServer.outputs(code)
2162
2168
  end
2163
2169
  ## revert all the stuff
2164
2170
  if dynBlock
@@ -2168,6 +2174,15 @@ p call
2168
2174
  filter.outType=nil
2169
2175
  end
2170
2176
 
2177
+ def do_sh(tex,blck,filter)
2178
+ #Dyndoc.warn "do_sh: blck ";p blck[1..-1]
2179
+ filter.outType="none"
2180
+ code=parse(blck[1..-1],filter)
2181
+ %x[ #{code} ]
2182
+ #Dyndoc.warn "do_sh: code ";p code
2183
+ filter.outType=nil
2184
+ end
2185
+
2171
2186
  def do_m(tex,blck,filter)
2172
2187
  newblck=blck[0]
2173
2188
  # Dyndoc.warn "do_m";p blck
@@ -19,7 +19,7 @@ module Dyndoc
19
19
  }
20
20
 
21
21
  require 'logger'
22
- @@dyn_logger = Logger.new @@cfg_dir[:log_file], 7, 1048576
22
+ @@dyn_logger = nil
23
23
 
24
24
  def Dyndoc.cfg_dir
25
25
  @@cfg_dir
@@ -29,10 +29,18 @@ module Dyndoc
29
29
  Settings[:cfg_dyn]
30
30
  end
31
31
 
32
+ def Dyndoc.add_logger
33
+ @@dyn_logger = Logger.new(@@cfg_dir[:log_file], 7, 1048576)
34
+ end
35
+
32
36
  def Dyndoc.logger
33
37
  @@dyn_logger
34
38
  end
35
39
 
40
+ def Dyndoc.logger_info(txt)
41
+ @@dyn_logger.info(txt)
42
+ end
43
+
36
44
  @@dyn_block={}
37
45
 
38
46
  def Dyndoc.dyn_block
@@ -1,21 +1,24 @@
1
- # include("ruby.jl")
1
+
2
2
 
3
3
  module Dyndoc
4
4
 
5
- import Base.setindex!,Base.getindex,Base.IO,Base.show,Base.showarray
6
- importall Ruby
5
+
6
+ using Main.Ruby
7
+
8
+ import Base.setindex!,Base.getindex,Base.IO,Base.show #,Base.showarray
9
+ import Main.Ruby.start,Main.Ruby.stop,Main.Ruby.run,Main.Ruby.alive
7
10
 
8
11
  export DynVector,DynArray,getindex,setindex!,show,Vector,sync,getkey
9
12
 
10
13
  # this is just a wrapper of Vector type with update of all connected vectors
11
- # when change on the vector occurs
14
+ # when change on the vector occurs
12
15
 
13
16
 
14
- type DynVector
17
+ mutable struct DynVector
15
18
  ary::Vector
16
- key::ASCIIString
19
+ key::String
17
20
 
18
- DynVector(a::Vector,k::ASCIIString)=(x=new();x.ary=a;x.key=k;x)
21
+ #DynVector(a::Vector,k::String)=(x=new();x.ary=a;x.key=k;x)
19
22
  end
20
23
 
21
24
  function getindex(dynvect::DynVector,i::Integer)
@@ -26,35 +29,34 @@ end
26
29
  function setindex!(dynvect::DynVector,value,i::Integer)
27
30
  dynvect.ary[i]=value
28
31
  ## println("inisde vect:",Ruby.alive())
29
- if Ruby.alive()
30
- Ruby.run("Dyndoc::Vector[\""*dynvect.key*"\"].sync(:jl)")
32
+ if Ruby.alive()
33
+ Ruby.run("Dyndoc::Vector[\""*dynvect.key*"\"].sync(:jl)")
31
34
  end
32
35
  end
33
36
 
34
- show(io::IO,dynvect::DynVector)=showarray(io,dynvect.ary)
37
+ show(io::IO,dynvect::DynVector)=show(io,dynvect.ary)
35
38
 
36
39
  # gather all the julia vectors connected to dyndoc.
37
40
 
38
- type DynArray
41
+ mutable struct DynArray
39
42
  vars::Dict
40
-
41
43
  DynArray()=(x=new();x.vars=Dict();x)
42
44
  end
43
45
 
44
46
  global const Vec=DynArray()
45
47
 
46
- function getindex(dynary::DynArray,key::ASCIIString)
48
+ function getindex(dynary::DynArray,key::String)
47
49
  #println("getindex(" * key * ")->todo")
48
50
  #if Ruby.alive()
49
51
  #println("getindex(" * key * ")->to sync")
50
- #Ruby.run("Dyndoc::Vector[\""*key*"\"].sync_to(:jl)")
52
+ #Ruby.run("Dyndoc::Vector[\""*key*"\"].sync_to(:jl)")
51
53
  #end
52
54
  #println("getindex(" * key * ")->done")
53
55
  dynary.vars[key]
54
56
  end
55
57
  getindex(dynary::DynArray,key::Symbol)=getindex(dynary,string(key))
56
58
 
57
- function setindex!(dynary::DynArray,value,key::ASCIIString)
59
+ function setindex!(dynary::DynArray,value,key::String)
58
60
  #println("key:" * key)
59
61
  #println(keys(dynary.vars))
60
62
  if(haskey(dynary.vars,key))
@@ -65,7 +67,7 @@ function setindex!(dynary::DynArray,value,key::ASCIIString)
65
67
  end
66
68
 
67
69
  ## println("inside array:",Ruby.alive())
68
-
70
+
69
71
  if Ruby.alive()
70
72
  Ruby.run("Dyndoc::Vector[\""*key*"\"].sync(:jl)")
71
73
  end
@@ -73,13 +75,13 @@ end
73
75
  setindex!(dynary::DynArray,value,key::Symbol)=setindex!(dynary,value,string(key))
74
76
 
75
77
 
76
- sync(dynary::DynArray,key::ASCIIString)= if Ruby.alive() Ruby.run("Dyndoc::Vector[\""*key*"\"].sync(:jl)") end
78
+ sync(dynary::DynArray,key::String)= if Ruby.alive() Ruby.run("Dyndoc::Vector[\""*key*"\"].sync(:jl)") end
77
79
 
78
80
  show(io::IO,dynary::DynArray)=show(io,dynary.vars)
79
81
 
80
82
  # NO MORE KEY WITH THE FORM "<name>@<ruby id object>"
81
83
  # function getkey(dynary::DynArray,k::Symbol)
82
- # for k2 in keys(dynary.vars)
84
+ # for k2 in keys(dynary.vars)
83
85
  # if split(k2,"@")[1] == string(k)
84
86
  # return k2
85
87
  # end
@@ -90,4 +92,3 @@ show(io::IO,dynary::DynArray)=show(io,dynary.vars)
90
92
  # setindex!(dynary::DynArray,value,key::Symbol)=setindex!(dynary,value,getkey(dynary,key))
91
93
 
92
94
  end
93
-
@@ -1,87 +1,55 @@
1
- #cmd="a=1\n(a)\nfor i in 1:3\nprintln(i)\nend"
2
-
3
- # # Unused! See capture_julia
4
- # function capture_cmd(cmd::AbstractString)
5
- # add,cmd0=true,AbstractString[]
6
- # res=Any[] #Dict{AbstractString,Any}()
7
- # for l=split(cmd,"\n")
8
- # #println("l => ",l)
9
- # push!(cmd0,l)
10
- # pcmd0=Base.parse_input_line(join(cmd0,"\n"))
11
- # #print(join(cmd0,"\n")*":");println(pcmd0)
12
- # add = typeof(pcmd0)==Expr && pcmd0.head == :continue
13
- # if !add
14
- # #print("ici:")
15
- # #println(Base.eval(pcmd0))
16
- # push!(res,(join(cmd0,"\n"),eval(pcmd0)))
17
- # cmd0=AbstractString[]
18
- # end
19
- # #println(res)
20
- # end
21
- # res
22
- # end
23
-
24
- module DyndocSandbox
25
- importall Ruby
26
- importall Dyndoc
1
+ module Dyndoc2Sandbox
2
+ import Main.Ruby.run,Main.Ruby.alive
3
+ import Main.Dyndoc.DynVector,Main.Dyndoc.DynArray,Main.Dyndoc.getindex,Main.Dyndoc.setindex!,Main.Dyndoc.show,Main.Dyndoc.Vector,Main.Dyndoc.sync,Main.Dyndoc.getkey
4
+ using InteractiveUtils
5
+ end
27
6
 
28
- # Replace OUTPUT_STREAM references so we can capture output.
29
- OUTPUT_STREAM = IOBuffer()
30
- print(x) = Base.print(OUTPUT_STREAM, x)
31
- println(x) = Base.println(OUTPUT_STREAM, x)
32
7
 
33
- # Output
34
- MIME_OUTPUT = Array(Tuple, 0)
35
- emit(mime, data) = push!(MIME_OUTPUT, (mime, data))
8
+ function replace_dyndoc2sandbox(txt)
9
+ replace(replace(txt,"Main.Dyndoc2Sandbox." => ""),"Main.Dyndoc2Sandbox" => "Main")
36
10
  end
37
11
 
38
- function get_stdout_iobuffer()
39
- #seek(DyndocSandbox.OUTPUT_STREAM, 0)
40
- #jl4rb_out =
41
- takebuf_string(DyndocSandbox.OUTPUT_STREAM)
42
- #truncate(DyndocSandbox.OUTPUT_STREAM, 0)
43
- #jl4rb_out
12
+ function echo_repl_julia(res)
13
+ # buf = IOBuffer();
14
+ # td = TextDisplay(buf);
15
+ # display(td, res);
16
+ # takebuf_string(buf)
17
+ #println(typeof(res))
18
+ replace_dyndoc2sandbox(repr("text/plain",res))
44
19
  end
45
20
 
46
- function get_stderr_iobuffer()
47
- #jl4rb_out = takebuf_string(STDERR.buffer)
48
- #jl4rb_out
49
- ## THIS FAILS WHEN DYNDOC DAEMONIZED SO AUTOMATIC EMPTY RESULT for now
50
- ## MAYBE TO DELETE SOON!
51
- ""
21
+ ## Rmk: The process is based on what is done in weave.jl (src/run.jl)
22
+ getstdout() = stdout #Base.STDOUT
23
+ function capture_output_expr(expr)
24
+ #oldSTDOUT = STDOUT
25
+ oldSTDOUT = getstdout()
26
+ out = nothing
27
+ obj = nothing
28
+ rw, wr = redirect_stdout()
29
+ reader = @async read(rw, String) # @async readstring(rw)
30
+ try
31
+ obj = Core.eval(Dyndoc2Sandbox, expr)
32
+ obj != nothing && display(obj)
33
+ #catch E
34
+ # throw_errors && throw(E)
35
+ # display(E)
36
+ # @warn("ERROR: $(typeof(E)) occurred, including output in Weaved document")
37
+
38
+ finally
39
+ redirect_stdout(oldSTDOUT)
40
+ close(wr)
41
+ out = fetch(reader) #wait(reader)
42
+ close(rw)
43
+ end
44
+ return (obj, out)
52
45
  end
53
46
 
54
- # export weave
55
- # module DyndocSandbox
56
- # # Copied from Gadfly.jl/src/weave.jl
57
- # # Replace OUTPUT_STREAM references so we can capture output.
58
- # OUTPUT_STREAM = IOString()
59
- # print(x) = Base.print(OUTPUT_STREAM, x)
60
- # println(x) = Base.println(OUTPUT_STREAM, x)
61
-
62
- # function eval(expr)
63
- # result = try
64
- # Base.eval(DyndocSandbox, expr)
65
- # seek(DyndocSandbox.OUTPUT_STREAM, 0)
66
- # output = takebuf_string(DyndocSandbox.OUTPUT_STREAM)
67
- # truncate(DyndocSandbox.OUTPUT_STREAM, 0)
68
- # output
69
- # catch e
70
- # io = IOBuffer()
71
- # print(io, "ERROR: ")
72
- # Base.error_show(io, e)
73
- # tmp = bytestring(io)
74
- # close(io)
75
- # tmp
76
- # end
77
- # result
78
- # end
79
- # end
80
-
81
- function capture_julia(cmd::AbstractString)
47
+ function capture_output_julia(cmd::AbstractString)
82
48
  add,cmd0=true,AbstractString[]
83
49
  res=Any[] #Dict{AbstractString,Any}()
84
50
  #println(cmd)
51
+ #cmd=replace(cmd,r"\$","\$")
52
+
85
53
  for l=split(cmd,"\n")
86
54
  #println("l => ",l)
87
55
  push!(cmd0,l)
@@ -91,17 +59,18 @@ function capture_julia(cmd::AbstractString)
91
59
  if !add
92
60
  #print("ici:")
93
61
  #println(Base.eval(pcmd0))
94
- result,error = "",""
62
+ result,error,out = "","",""
95
63
  try
96
- result=eval(DyndocSandbox, pcmd0)
64
+ result,out=capture_output_expr(pcmd0)
97
65
  catch e
98
- #io = IOBuffer()
99
- #print(io, "ERROR: ")
100
- #Base.error_show(io, e)
101
- error = "Error: $(string(e))"
102
- #close(io)
103
- end
104
- push!(res,(join(cmd0,"\n"),string(result),get_stdout_iobuffer(),error,get_stderr_iobuffer()))
66
+ #io = IOBuffer()
67
+ #print(io, "ERROR: ")
68
+ #Base.error_show(io, e)
69
+ error = "ERROR: $(sprint(showerror,e))"
70
+ #close(io)
71
+ end
72
+ println(l)
73
+ push!(res,(join(cmd0,"\n"), echo_repl_julia(result),replace_dyndoc2sandbox(out),replace_dyndoc2sandbox(error),""))
105
74
  cmd0=AbstractString[]
106
75
  end
107
76
  #println(res)
@@ -0,0 +1,192 @@
1
+ #cmd="a=1\n(a)\nfor i in 1:3\nprintln(i)\nend"
2
+
3
+ # # Unused! See capture_julia
4
+ # function capture_cmd(cmd::AbstractString)
5
+ # add,cmd0=true,AbstractString[]
6
+ # res=Any[] #Dict{AbstractString,Any}()
7
+ # for l=split(cmd,"\n")
8
+ # #println("l => ",l)
9
+ # push!(cmd0,l)
10
+ # pcmd0=Base.parse_input_line(join(cmd0,"\n"))
11
+ # #print(join(cmd0,"\n")*":");println(pcmd0)
12
+ # add = typeof(pcmd0)==Expr && pcmd0.head == :continue
13
+ # if !add
14
+ # #print("ici:")
15
+ # #println(Base.eval(pcmd0))
16
+ # push!(res,(join(cmd0,"\n"),eval(pcmd0)))
17
+ # cmd0=AbstractString[]
18
+ # end
19
+ # #println(res)
20
+ # end
21
+ # res
22
+ # end
23
+
24
+ module DyndocSandbox
25
+ import Main.Ruby.start,Main.Ruby.stop,Main.Ruby.run,Main.Ruby.alive
26
+ import Main.Dyndoc.DynVector,Main.Dyndoc.DynArray,Main.Dyndoc.getindex,Main.Dyndoc.setindex!,Main.Dyndoc.show,Main.Dyndoc.Vector,Main.Dyndoc.sync,Main.Dyndoc.getkey
27
+
28
+ # Replace OUTPUT_STREAM references so we can capture output.
29
+ OUTPUT_STREAM = IOBuffer()
30
+ print(x) = Base.print(OUTPUT_STREAM, x)
31
+ println(x) = Base.println(OUTPUT_STREAM, x)
32
+
33
+ # Output
34
+ MIME_OUTPUT = Array(Tuple, 0)
35
+ emit(mime, data) = push!(MIME_OUTPUT, (mime, data))
36
+ end
37
+
38
+ function get_stdout_iobuffer()
39
+ #seek(DyndocSandbox.OUTPUT_STREAM, 0)
40
+ #jl4rb_out =
41
+ takebuf_string(DyndocSandbox.OUTPUT_STREAM)
42
+ #truncate(DyndocSandbox.OUTPUT_STREAM, 0)
43
+ #jl4rb_out
44
+ end
45
+
46
+ function get_stderr_iobuffer()
47
+ #jl4rb_out = takebuf_string(STDERR.buffer)
48
+ #jl4rb_out
49
+ ## THIS FAILS WHEN DYNDOC DAEMONIZED SO AUTOMATIC EMPTY RESULT for now
50
+ ## MAYBE TO DELETE SOON!
51
+ ""
52
+ end
53
+
54
+ # export weave
55
+ # module DyndocSandbox
56
+ # # Copied from Gadfly.jl/src/weave.jl
57
+ # # Replace OUTPUT_STREAM references so we can capture output.
58
+ # OUTPUT_STREAM = IOString()
59
+ # print(x) = Base.print(OUTPUT_STREAM, x)
60
+ # println(x) = Base.println(OUTPUT_STREAM, x)
61
+
62
+ # function eval(expr)
63
+ # result = try
64
+ # Base.eval(DyndocSandbox, expr)
65
+ # seek(DyndocSandbox.OUTPUT_STREAM, 0)
66
+ # output = takebuf_string(DyndocSandbox.OUTPUT_STREAM)
67
+ # truncate(DyndocSandbox.OUTPUT_STREAM, 0)
68
+ # output
69
+ # catch e
70
+ # io = IOBuffer()
71
+ # print(io, "ERROR: ")
72
+ # Base.error_show(io, e)
73
+ # tmp = bytestring(io)
74
+ # close(io)
75
+ # tmp
76
+ # end
77
+ # result
78
+ # end
79
+ # end
80
+
81
+
82
+ function capture_julia(cmd::AbstractString)
83
+ add,cmd0=true,AbstractString[]
84
+ res=Any[] #Dict{AbstractString,Any}()
85
+ #println(cmd)
86
+ #cmd=replace(cmd,r"\$","\$")
87
+ # for standard redirection
88
+ ##OUT: (outRead, outWrite) = redirect_stdout()
89
+ for l=split(cmd,"\n")
90
+ #println("l => ",l)
91
+ push!(cmd0,l)
92
+ pcmd0=Base.parse_input_line(join(cmd0,"\n"))
93
+ #print(join(cmd0,"\n")*":");println(pcmd0)
94
+ add = typeof(pcmd0)==Expr && pcmd0.head == :incomplete
95
+ if !add
96
+ #print("ici:")
97
+ #println(Base.eval(pcmd0))
98
+ result,error = "",""
99
+ try
100
+ result=eval(DyndocSandbox, pcmd0)
101
+ catch e
102
+ #io = IOBuffer()
103
+ #print(io, "ERROR: ")
104
+ #Base.error_show(io, e)
105
+ error = "Error: $(string(e))"
106
+ #close(io)
107
+ end
108
+
109
+ ##OUT: data_out = readavailable(outRead)
110
+
111
+ ##OUT: push!(res,(join(cmd0,"\n"),echo_repl_julia(result),get_stdout_iobuffer(),data_out,error,get_stderr_iobuffer()))
112
+ push!(res,(join(cmd0,"\n"),echo_repl_julia(result),get_stdout_iobuffer(),error,get_stderr_iobuffer()))
113
+ cmd0=AbstractString[]
114
+ end
115
+ #println(res)
116
+ end
117
+ ##OUT: close(outWrite);close(outRead)
118
+ res
119
+ end
120
+
121
+
122
+ module Dyndoc2Sandbox
123
+ import Main.Ruby.run,Main.Ruby.alive
124
+ import Main.Dyndoc.DynVector,Main.Dyndoc.DynArray,Main.Dyndoc.getindex,Main.Dyndoc.setindex!,Main.Dyndoc.show,Main.Dyndoc.Vector,Main.Dyndoc.sync,Main.Dyndoc.getkey
125
+ end
126
+
127
+ function echo_repl_julia(res)
128
+ buf = IOBuffer();
129
+ td = TextDisplay(buf);
130
+ display(td, res);
131
+ takebuf_string(buf)
132
+ end
133
+
134
+ ## Rmk: The process is based on what is done in weave.jl (src/run.jl)
135
+ getstdout() = stdout #Base.STDOUT
136
+ function capture_output_expr(expr)
137
+ #oldSTDOUT = STDOUT
138
+ oldSTDOUT = getstdout()
139
+ out = nothing
140
+ obj = nothing
141
+ rw, wr = redirect_stdout()
142
+ reader = @async read(rw, String) # @async readstring(rw)
143
+ try
144
+ obj = eval(Dyndoc2Sandbox, expr)
145
+ obj != nothing && display(obj)
146
+ catch E
147
+ throw_errors && throw(E)
148
+ display(E)
149
+ @warn("ERROR: $(typeof(E)) occurred, including output in Weaved document")
150
+
151
+ finally
152
+ redirect_stdout(oldSTDOUT)
153
+ close(wr)
154
+ out = wait(reader)
155
+ close(rw)
156
+ end
157
+ return (obj, out)
158
+ end
159
+
160
+ function capture_output_julia(cmd::AbstractString)
161
+ add,cmd0=true,AbstractString[]
162
+ res=Any[] #Dict{AbstractString,Any}()
163
+ #println(cmd)
164
+ #cmd=replace(cmd,r"\$","\$")
165
+
166
+ for l=split(cmd,"\n")
167
+ #println("l => ",l)
168
+ push!(cmd0,l)
169
+ pcmd0=Base.parse_input_line(join(cmd0,"\n"))
170
+ #print(join(cmd0,"\n")*":");println(pcmd0)
171
+ add = typeof(pcmd0)==Expr && pcmd0.head == :incomplete
172
+ if !add
173
+ #print("ici:")
174
+ #println(Base.eval(pcmd0))
175
+ result,error,out = "","",""
176
+ try
177
+ result,out=capture_output_expr(pcmd0)
178
+ catch e
179
+ #io = IOBuffer()
180
+ #print(io, "ERROR: ")
181
+ #Base.error_show(io, e)
182
+ error = "Error: $(string(e))"
183
+ #close(io)
184
+ end
185
+
186
+ push!(res,(join(cmd0,"\n"),echo_repl_julia(result),out,error,""))
187
+ cmd0=AbstractString[]
188
+ end
189
+ #println(res)
190
+ end
191
+ res
192
+ end
@@ -0,0 +1,127 @@
1
+
2
+ ## Inspired from the excellent weave.jl
3
+
4
+ using Compat
5
+
6
+ #Contains report global properties
7
+ mutable struct DyndocReport <: AbstractDisplay
8
+ #cwd::AbstractString
9
+ #basename::AbstractString
10
+ #formatdict::Dict{Symbol,Any}
11
+ #pending_code::AbstractString
12
+ #cur_result::AbstractString
13
+ #rich_output::AbstractString
14
+ fignum::Int
15
+ figures::Array{AbstractString}
16
+ #term_state::Symbol
17
+ #cur_chunk
18
+ mimetypes::Array{AbstractString}
19
+ # first_plot::Bool
20
+ #header_script::String
21
+ #throw_errors::Bool
22
+ end
23
+
24
+ #function Report(cwd, basename, formatdict, mimetypes, throw_errors)
25
+ # Report(cwd, basename, formatdict, "", "", "", 1, AbstractString[], :text, nothing,
26
+ # mimetypes, true, "", throw_errors)
27
+ #end
28
+
29
+
30
+ #Default mimetypes in order, can be overridden for some inside `run method` formats
31
+ const default_mime_types = ["image/svg+xml", "image/png", "text/html", "text/plain"]
32
+ #const default_mime_types = ["image/png", "image/svg+xml", "text/html", "text/plain"]
33
+ #From IJulia as a reminder
34
+ #const supported_mime_types = [ "text/html", "text/latex", "image/svg+xml", "image/png", "image/jpeg", "text/plain", "text/markdown" ]
35
+
36
+ function Base.display(report::DyndocReport, data)
37
+ #Set preferred mimetypes for report based on format
38
+ for m in report.mimetypes
39
+ if showable(m, data)
40
+ try
41
+ if !istextmime(m)
42
+ Compat.invokelatest(display, report, m, data)
43
+ elseif report.cur_chunk.options[:term]
44
+ Compat.invokelatest(display, report, "text/plain", data)
45
+ else
46
+ Compat.invokelatest(display, report, m, data)
47
+ end
48
+ catch e
49
+ throw(e)
50
+ @warn("Failed to display data in \"$m\" format")
51
+ continue
52
+ end
53
+ break
54
+ end
55
+ end
56
+ end
57
+
58
+ function Base.display(report::DyndocReport, m::MIME"image/png", data)
59
+ figname = add_figure(report, data, m, ".png")
60
+ end
61
+
62
+ function Base.display(report::DyndocReport, m::MIME"image/svg+xml", data)
63
+ figname = add_figure(report, data, m, ".svg")
64
+ end
65
+
66
+ function Base.display(report::DyndocReport, m::MIME"application/pdf", data)
67
+ figname = add_figure(report, data, m, ".pdf")
68
+ end
69
+
70
+ #Text is written to stdout, called from "term" mode chunks
71
+ function Base.display(report::DyndocReport, m::MIME"text/plain", data)
72
+ io = PipeBuffer()
73
+ show(IOContext(io, :limit => true), m, data)
74
+ flush(io)
75
+ s = read(io, String)
76
+ close(io)
77
+ println(s)
78
+ end
79
+
80
+ function Base.display(report::DyndocReport, m::MIME"text/plain", data::Exception)
81
+ println("Error: " * sprint(showerror, data))
82
+ end
83
+
84
+ function Base.display(report::DyndocReport, m::MIME"text/html", data::Exception)
85
+ report.rich_output = sprint(show, m, data)
86
+ end
87
+
88
+ function Base.show(io, m::MIME"text/html", data::Exception)
89
+ println(io ,"<pre class=\"julia-error\">")
90
+ println(io, Markdown.htmlesc("ERROR: " * sprint(showerror, data)))
91
+ println(io ,"</pre>")
92
+ end
93
+
94
+ #Catch "rich_output"
95
+ function Base.display(report::DyndocReport, m::MIME"text/html", data)
96
+ s = repr(m, data)
97
+ report.rich_output *= "\n" * s
98
+ end
99
+
100
+ #Catch "rich_output"
101
+ function Base.display(report::DyndocReport, m::MIME"text/markdown", data)
102
+ s = repr(m, data)
103
+ report.rich_output *= "\n" * s
104
+ end
105
+
106
+ function Base.display(report::DyndocReport, m::MIME"text/latex", data)
107
+ s = repr(m, data)
108
+ report.rich_output *= "\n" * s
109
+ end
110
+
111
+ """Add saved figure name to results and return the name"""
112
+ function add_figure(report::DyndocReport, data, m, ext)
113
+ chunk = report.cur_chunk
114
+ full_name, rel_name = get_figname(report, chunk, ext = ext)
115
+
116
+ open(full_name, "w") do io
117
+ if ext == ".pdf"
118
+ write(io, repr(m, data))
119
+ else
120
+ show(io, m, data)
121
+ end
122
+ end
123
+
124
+ push!(report.figures, rel_name)
125
+ report.fignum += 1
126
+ return full_name
127
+ end
@@ -1,28 +1,28 @@
1
1
 
2
2
 
3
3
  module Ruby
4
-
5
- librb=Libdl.dlopen(("JULIA_RUBYLIB_PATH" in keys(ENV)) ? ENV["JULIA_RUBYLIB_PATH"] : "libruby")
4
+ using Libdl
5
+ librb=Libdl.dlopen(("JULIA_RUBYLIB_PATH" in keys(ENV)) ? ENV["JULIA_RUBYLIB_PATH"] : "/usr/lib/libruby")
6
6
 
7
7
  export start,stop,run,alive
8
8
 
9
9
  global ruby_alive=false
10
10
 
11
11
  function start()
12
- ccall(Libdl.dlsym(librb,:ruby_init),Void,())
13
- ccall(Libdl.dlsym(librb,:ruby_init_loadpath),Void,())
12
+ ccall(Libdl.dlsym(librb,:ruby_init),Cvoid,())
13
+ ccall(Libdl.dlsym(librb,:ruby_init_loadpath),Cvoid,())
14
14
  ruby_alive=true
15
15
  end
16
16
 
17
17
  function stop()
18
- ccall(Libdl.dlsym(librb,:ruby_finalize),Void,())
18
+ ccall(Libdl.dlsym(librb,:ruby_finalize),Cvoid,())
19
19
  ruby_alive=false
20
20
  end
21
21
 
22
22
  function run(code::AbstractString)
23
23
  state=1 #not modified then
24
24
  ##println(code)
25
- res=ccall(Libdl.dlsym(librb,:rb_eval_string_protect),Ptr{UInt64},(Ptr{UInt8},Ptr{UInt32}),bytestring(code),&state)
25
+ res=ccall(Libdl.dlsym(librb,:rb_eval_string_protect),Ptr{UInt64},(Ptr{UInt8},Ref{UInt32}),string(code),state)
26
26
  return nothing
27
27
  end
28
28
 
metadata CHANGED
@@ -1,98 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dyndoc-ruby-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CQLS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2020-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: configliere
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.4'
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.4.18
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0.4'
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.4.18
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: ultraviolet
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- version: '1.0'
40
- - - '>='
37
+ - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: 1.0.0
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
48
- - !ruby/object:Gem::Version
49
- version: '1.0'
50
- - - '>='
47
+ - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: 1.0.0
53
- description: |2
54
- Provide templating in text document.
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ description: " Provide templating in text document.\n"
55
54
  email: rdrouilh@gmail.com
56
55
  executables: []
57
56
  extensions: []
58
57
  extra_rdoc_files: []
59
58
  files:
60
- - lib/dyndoc-core.rb
61
- - lib/dyndoc/base/envir.rb
62
- - lib/dyndoc/base/filter/call.rb
63
- - lib/dyndoc/base/filter/filter_mngr.rb
64
- - lib/dyndoc/base/filter/server.rb
65
- - lib/dyndoc/base/filters.rb
66
- - lib/dyndoc/base/helpers.rb
67
- - lib/dyndoc/base/helpers/core.rb
68
- - lib/dyndoc/base/helpers/parser.rb
69
- - lib/dyndoc/base/scanner.rb
70
- - lib/dyndoc/base/tags.rb
71
- - lib/dyndoc/base/tags/keys_mngr.rb
72
- - lib/dyndoc/base/tags/part_tag.rb
73
- - lib/dyndoc/base/tags/tag_mngr.rb
74
- - lib/dyndoc/base/tags/user_tag.rb
75
- - lib/dyndoc/base/tmpl.rb
76
- - lib/dyndoc/base/tmpl/eval.rb
77
- - lib/dyndoc/base/tmpl/extension.rb
78
- - lib/dyndoc/base/tmpl/manager.rb
79
- - lib/dyndoc/base/tmpl/oop.rb
80
- - lib/dyndoc/base/tmpl/parse_do.rb
81
- - lib/dyndoc/base/tmpl/rbenvir.rb
82
- - lib/dyndoc/base/utils.rb
83
- - lib/dyndoc/common/dynArray.rb
84
- - lib/dyndoc/common/file.rb
85
- - lib/dyndoc/common/init.rb
86
- - lib/dyndoc/common/tilt.rb
87
- - lib/dyndoc/common/utils.rb
88
- - lib/dyndoc/common/uv.rb
89
- - lib/dyndoc/init/config.rb
90
- - lib/dyndoc/init/home.rb
91
- - lib/dyndoc/plugins/tex.rb
92
- - lib/dyndoc/plugins/tex/beamer.rb
93
- - lib/dyndoc/plugins/tex/tex_eval.rb
94
- - lib/dyndoc/plugins/tex/tex_parse_do.rb
95
- - lib/dyndoc/plugins/tex/tex_user_tag.rb
59
+ - dyndoc/Dyn/.postload
60
+ - dyndoc/Dyn/.preload
96
61
  - dyndoc/Dyn/After.dyn
97
62
  - dyndoc/Dyn/Base.dyn
98
63
  - dyndoc/Dyn/Minimum.dyn
@@ -130,6 +95,8 @@ files:
130
95
  - dyndoc/Style/Text/StdAlias.dyn
131
96
  - dyndoc/Style/Text/StdTex.dyn
132
97
  - dyndoc/Style/Text/Txt.dyn
98
+ - dyndoc/Tex/.postload
99
+ - dyndoc/Tex/.preload
133
100
  - dyndoc/Tex/10pt_tmpl.tex
134
101
  - dyndoc/Tex/11pt_tmpl.tex
135
102
  - dyndoc/Tex/12pt_tmpl.tex
@@ -178,26 +145,58 @@ files:
178
145
  - dyndoc/Tools/Web/TabBar.dyn
179
146
  - dyndoc/Tools/Web/Ttm.dyn
180
147
  - dyndoc/Tools/Web/Txtl.dyn
181
- - share/julia/dynArray.jl
182
- - share/julia/dyndoc.jl
183
- - share/julia/ruby.jl
148
+ - dyndoc/Tools/julia/Fig.dyn
149
+ - lib/dyndoc-core.rb
150
+ - lib/dyndoc/base/envir.rb
151
+ - lib/dyndoc/base/filter/call.rb
152
+ - lib/dyndoc/base/filter/filter_mngr.rb
153
+ - lib/dyndoc/base/filter/server.rb
154
+ - lib/dyndoc/base/filters.rb
155
+ - lib/dyndoc/base/helpers.rb
156
+ - lib/dyndoc/base/helpers/core.rb
157
+ - lib/dyndoc/base/helpers/parser.rb
158
+ - lib/dyndoc/base/scanner.rb
159
+ - lib/dyndoc/base/tags.rb
160
+ - lib/dyndoc/base/tags/keys_mngr.rb
161
+ - lib/dyndoc/base/tags/part_tag.rb
162
+ - lib/dyndoc/base/tags/tag_mngr.rb
163
+ - lib/dyndoc/base/tags/user_tag.rb
164
+ - lib/dyndoc/base/tmpl.rb
165
+ - lib/dyndoc/base/tmpl/eval.rb
166
+ - lib/dyndoc/base/tmpl/extension.rb
167
+ - lib/dyndoc/base/tmpl/manager.rb
168
+ - lib/dyndoc/base/tmpl/oop.rb
169
+ - lib/dyndoc/base/tmpl/parse_do.rb
170
+ - lib/dyndoc/base/tmpl/rbenvir.rb
171
+ - lib/dyndoc/base/utils.rb
172
+ - lib/dyndoc/common/dynArray.rb
173
+ - lib/dyndoc/common/file.rb
174
+ - lib/dyndoc/common/init.rb
175
+ - lib/dyndoc/common/tilt.rb
176
+ - lib/dyndoc/common/utils.rb
177
+ - lib/dyndoc/common/uv.rb
178
+ - lib/dyndoc/init/config.rb
179
+ - lib/dyndoc/init/home.rb
180
+ - lib/dyndoc/plugins/tex.rb
181
+ - lib/dyndoc/plugins/tex/beamer.rb
182
+ - lib/dyndoc/plugins/tex/tex_eval.rb
183
+ - lib/dyndoc/plugins/tex/tex_parse_do.rb
184
+ - lib/dyndoc/plugins/tex/tex_user_tag.rb
184
185
  - share/R/dyndocMsys2.R
185
186
  - share/R/dyndocTools.R
186
187
  - share/R/test.R
187
188
  - share/R/tools/dynArray.R
188
189
  - share/R/tools/dynCapture.R
189
190
  - share/R/tools/dynMsys2.R
190
- - dyndoc/.DS_Store
191
- - dyndoc/Dyn/.postload
192
- - dyndoc/Dyn/.preload
193
- - dyndoc/Tex/.postload
194
- - dyndoc/Tex/.preload
195
- - dyndoc/Tools/.DS_Store
196
- - dyndoc/Tools/Web/.DS_Store
191
+ - share/julia/dynArray.jl
192
+ - share/julia/dyndoc.jl
193
+ - share/julia/dyndocOLD.jl
194
+ - share/julia/dynreport.jl
195
+ - share/julia/ruby.jl
197
196
  homepage: http://cqls.upmf-grenoble.fr
198
197
  licenses:
199
198
  - MIT
200
- - GPL-2
199
+ - GPL-2.0
201
200
  metadata: {}
202
201
  post_install_message:
203
202
  rdoc_options: []
@@ -205,18 +204,17 @@ require_paths:
205
204
  - lib
206
205
  required_ruby_version: !ruby/object:Gem::Requirement
207
206
  requirements:
208
- - - '>='
207
+ - - ">="
209
208
  - !ruby/object:Gem::Version
210
209
  version: '0'
211
210
  required_rubygems_version: !ruby/object:Gem::Requirement
212
211
  requirements:
213
- - - '>='
212
+ - - ">="
214
213
  - !ruby/object:Gem::Version
215
214
  version: '0'
216
215
  requirements:
217
216
  - none
218
- rubyforge_project:
219
- rubygems_version: 2.0.14.1
217
+ rubygems_version: 3.0.6
220
218
  signing_key:
221
219
  specification_version: 4
222
220
  summary: R and Ruby in text document
Binary file
Binary file
Binary file