dyndoc-ruby-core 1.0.3 → 1.0.4
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 +4 -4
- data/lib/dyndoc/base/filter/server.rb +51 -51
- data/lib/dyndoc/base/tmpl/manager.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36bb654f81d5dc724967d4e5a50599551d827a05
|
4
|
+
data.tar.gz: e33f05528d9e392745c669b7b1be587fd85ff39d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59992801cbfcb258e6fca73c03c162b6def069237ff08f28265f56c575255279dadda7a6dd68e586ec9b2e70bbfd91422ce3d8f1729484734d0170db6ceec453
|
7
|
+
data.tar.gz: a26e6739b605b91138c1346f40f075c02f808e736f12af1dd654411c18fcd06c649d89c2a96e9327272567c3f0c27032c4f4c34468aca2485b654f21210094ee
|
@@ -30,7 +30,7 @@ module Dyndoc
|
|
30
30
|
@@start,@@stop="\\{","\\}"
|
31
31
|
|
32
32
|
def RbServer.filter(str,rbEnvir=nil)
|
33
|
-
res=str.gsub(/\\?(?i:\#Rb|\#rb|\:Rb|\:rb|\:)#{@@start}[^#{@@stop}]+#{@@stop}/) {|w|
|
33
|
+
res=str.gsub(/\\?(?i:\#Rb|\#rb|\:Rb|\:rb|\:)#{@@start}[^#{@@stop}]+#{@@stop}/) {|w|
|
34
34
|
if w[0,1]=="\\"
|
35
35
|
w[1..-1]
|
36
36
|
else
|
@@ -66,8 +66,8 @@ module Dyndoc
|
|
66
66
|
out=rbEnvir.module_eval(code)
|
67
67
|
end
|
68
68
|
rescue
|
69
|
-
if RUBY_VERSION >= "1.9.3" and rbEnvir.is_a? Binding and rbEnvir.eval("local_variables").include? :childBinding
|
70
|
-
begin
|
69
|
+
if RUBY_VERSION >= "1.9.3" and rbEnvir.is_a? Binding and rbEnvir.eval("local_variables").include? :childBinding
|
70
|
+
begin
|
71
71
|
rbEnvir2=rbEnvir.eval("childBinding")
|
72
72
|
out=rbEnvir2.eval(code)
|
73
73
|
return out
|
@@ -81,9 +81,9 @@ module Dyndoc
|
|
81
81
|
# or more informative for debugging!
|
82
82
|
|
83
83
|
out="\\:{"+code+"}"
|
84
|
-
|
84
|
+
|
85
85
|
if Dyndoc.cfg_dyn[:ruby_debug] ==:expression
|
86
|
-
Dyndoc.warn "WARNING: >>>>>>>>>>>>>>>>>>+\n"+opts[:error]+" in #{rbEnvir}:\n"+code+"\n<<<<<<<<<<<<<<<<<<"
|
86
|
+
Dyndoc.warn "WARNING: >>>>>>>>>>>>>>>>>>+\n"+opts[:error]+" in #{rbEnvir}:\n"+code+"\n<<<<<<<<<<<<<<<<<<"
|
87
87
|
end
|
88
88
|
|
89
89
|
|
@@ -91,7 +91,7 @@ module Dyndoc
|
|
91
91
|
##p ["error ruby",code]
|
92
92
|
$dyn_logger.write("\nERROR Ruby:\n"+code+"\n")
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
rescue SyntaxError
|
96
96
|
puts "RbServer syntax error in: "+code
|
97
97
|
raise SystemError if Dyndoc.cfg_dyn[:dyndoc_mode]==:normal and Dyndoc.cfg_dyn[:ruby_debug]!=:none
|
@@ -190,7 +190,7 @@ module Dyndoc
|
|
190
190
|
end
|
191
191
|
|
192
192
|
if $dyndoc_rserv
|
193
|
-
##puts "$dyndoc_rserv";p $dyndoc_rserv
|
193
|
+
##puts "$dyndoc_rserv";p $dyndoc_rserv
|
194
194
|
RServer.R4rb :Rserve,$dyndoc_rserv
|
195
195
|
R4rb_status? if $dyndoc_server_hostname
|
196
196
|
end
|
@@ -213,7 +213,7 @@ module Dyndoc
|
|
213
213
|
hide=0
|
214
214
|
passe=0
|
215
215
|
opt = nil
|
216
|
-
code=""
|
216
|
+
code=""
|
217
217
|
##Dyndoc.warn "block",block
|
218
218
|
block.each_line{|l|
|
219
219
|
l2=l.chomp
|
@@ -255,19 +255,19 @@ module Dyndoc
|
|
255
255
|
## redirect R output
|
256
256
|
code << l << "\n" ##ajout de "\n" grace à Pierre (le 15/12/05) pour bug: "1:10 #toto" -> pas de sortie car parse erreur n2!!!
|
257
257
|
case @@mode
|
258
|
-
when :capture_normal
|
258
|
+
when :capture_normal
|
259
259
|
evalOk=(R4rb << ".output<<-capture.output({"+RServer.code_envir(code,env)+"})")
|
260
260
|
when :capture_cqls
|
261
261
|
evalOk=(R4rb << ".output<<-capture.output.cqls({"+RServer.code_envir(code,env)+"})")
|
262
262
|
end
|
263
263
|
|
264
264
|
##Dyndoc.warn "evalOk",code,evalOk
|
265
|
-
if evalOk
|
265
|
+
if evalOk
|
266
266
|
txt=(@@out < '.output' ) ##.join("\n").split(/\n/)
|
267
|
-
code=""
|
267
|
+
code=""
|
268
268
|
else
|
269
269
|
txt=@@out=[]
|
270
|
-
end
|
270
|
+
end
|
271
271
|
if optout and optout.keys.include? "short"
|
272
272
|
short=optout["short"].split(",")
|
273
273
|
short[0]=short[0].to_i
|
@@ -284,7 +284,7 @@ module Dyndoc
|
|
284
284
|
##txt.each{|l| txtout << l <<"\n"}
|
285
285
|
end
|
286
286
|
end
|
287
|
-
optout=nil
|
287
|
+
optout=nil
|
288
288
|
hide -= 1 if hide>0
|
289
289
|
passe -=1 if passe>0
|
290
290
|
end
|
@@ -300,7 +300,7 @@ module Dyndoc
|
|
300
300
|
hide=0
|
301
301
|
passe=0
|
302
302
|
opt = nil
|
303
|
-
code=""
|
303
|
+
code=""
|
304
304
|
block.each_line{|l|
|
305
305
|
l2=l.chomp
|
306
306
|
inst=l2.delete(" ").split("|")[0]
|
@@ -341,12 +341,12 @@ module Dyndoc
|
|
341
341
|
## redirect R output
|
342
342
|
code << l << "\n" ##ajout de "\n" grace à Pierre (le 15/12/05) pour bug: "1:10 #toto" -> pas de sortie car parse erreur n2!!!
|
343
343
|
evalOk=(R4rb << ".output<<-capture.output({"+RServer.code_envir(code,env)+"})")
|
344
|
-
if evalOk
|
344
|
+
if evalOk
|
345
345
|
txt=(@@out < '.output' ) ##.join("\n").split(/\n/)
|
346
|
-
code=""
|
346
|
+
code=""
|
347
347
|
else
|
348
348
|
txt=@@out=[]
|
349
|
-
end
|
349
|
+
end
|
350
350
|
if optout and optout.keys.include? "short"
|
351
351
|
short=optout["short"].split(",")
|
352
352
|
short[0]=short[0].to_i
|
@@ -363,7 +363,7 @@ module Dyndoc
|
|
363
363
|
outputs << output.gsub(/^[\n]*/,"")
|
364
364
|
input,output="",""
|
365
365
|
end
|
366
|
-
optout=nil
|
366
|
+
optout=nil
|
367
367
|
hide -= 1 if hide>0
|
368
368
|
passe -=1 if passe>0
|
369
369
|
end
|
@@ -373,17 +373,17 @@ module Dyndoc
|
|
373
373
|
|
374
374
|
|
375
375
|
@@mode=:capture_cqls #or :capture_protected or capture_normal or capture_local
|
376
|
-
|
376
|
+
|
377
377
|
def RServer.mode=(val)
|
378
378
|
@@mode= val
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
def RServer.mode
|
382
382
|
@@mode
|
383
383
|
end
|
384
384
|
|
385
385
|
@@device_cmd,@@device="png","png"
|
386
|
-
|
386
|
+
|
387
387
|
def RServer.device(dev="pdf")
|
388
388
|
case dev
|
389
389
|
when "pdf"
|
@@ -392,11 +392,11 @@ module Dyndoc
|
|
392
392
|
@@device_cmd,@@device="png","png"
|
393
393
|
end
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
#def RServer.input_semi_colon(block)
|
397
397
|
# block.map{|e| e.chomp!;((e.include? ";") ? (ee=e.split(";");["##!eval",e,"##hide:#{ee.length}"]+ee) : e )}.compact.join("\n")
|
398
398
|
#end
|
399
|
-
|
399
|
+
|
400
400
|
def RServer.inputsAndOutputs(block,id="",optRDevice="",prompt={:normal=>'',:continue=>''},env="Global")
|
401
401
|
Utils.clean_eol(block)
|
402
402
|
envLoc=env
|
@@ -411,7 +411,7 @@ module Dyndoc
|
|
411
411
|
code=""
|
412
412
|
# add R device
|
413
413
|
imgdir=($dyn_rsrc ? File.join($dyn_rsrc,"img") : "/tmp/Rserver-img"+rand(1000000).to_s)
|
414
|
-
|
414
|
+
|
415
415
|
imgfile=File.join(imgdir,"tmpImgFile"+id.to_s+"-")
|
416
416
|
cptImg=0
|
417
417
|
imgCopy=[]
|
@@ -420,7 +420,7 @@ module Dyndoc
|
|
420
420
|
Dir[imgfile+"*"].each{|f| FileUtils.rm_f(f)}
|
421
421
|
#p Dir[imgfile+"*"]
|
422
422
|
|
423
|
-
|
423
|
+
|
424
424
|
#Dyndoc.warn "fig command:", "#{@@device_cmd}(\"#{imgfile}%d.#{@@device}\",#{optRDevice})"
|
425
425
|
R4rb << "#{@@device_cmd}(\"#{imgfile}%d.#{@@device}\",#{optRDevice})"
|
426
426
|
#block=RServer.input_semi_colon(block)
|
@@ -461,10 +461,10 @@ module Dyndoc
|
|
461
461
|
|
462
462
|
if echo>0
|
463
463
|
echo -= 1
|
464
|
-
echoLines << l2
|
464
|
+
echoLines << l2
|
465
465
|
next
|
466
466
|
end
|
467
|
-
|
467
|
+
|
468
468
|
if echo==0 and !echoLines.empty? and !results.empty?
|
469
469
|
results[-1][:output] << "\n" unless results[-1][:output].empty?
|
470
470
|
results[-1][:output] << echoLines.join("\n")
|
@@ -489,7 +489,7 @@ module Dyndoc
|
|
489
489
|
imgName=File.basename(opt["img"].strip,".*")
|
490
490
|
imgName+=".#{@@device}" #unless imgName=~/\.#{@@device}$/
|
491
491
|
imgName=File.join(imgdir,imgName)
|
492
|
-
|
492
|
+
|
493
493
|
imgCopy << {:in => imgfile+cptImg.to_s+".#{@@device}",:out=>imgName}
|
494
494
|
opt.delete("img")
|
495
495
|
else
|
@@ -497,7 +497,7 @@ module Dyndoc
|
|
497
497
|
end
|
498
498
|
puts "DYN ERROR!!! no fig allowed after empty R output!!!" unless results[-1]
|
499
499
|
results[-1][:img]={:name=>imgName}
|
500
|
-
results[-1][:img][:opt]=opt if opt and !opt.empty?
|
500
|
+
results[-1][:img][:opt]=opt if opt and !opt.empty?
|
501
501
|
#could not copy file now!!!!
|
502
502
|
when "##add"
|
503
503
|
results[-1][:add]=opt
|
@@ -510,15 +510,15 @@ module Dyndoc
|
|
510
510
|
l2,envLoc=RServer.find_envir(l2,envLoc)
|
511
511
|
#Dyndoc.warn "after",l,envLoc
|
512
512
|
input << l2 << "\n"
|
513
|
-
#Dyndoc.warn :input3, input
|
513
|
+
#Dyndoc.warn :input3, input
|
514
514
|
end
|
515
515
|
if passe==0 and l2[0,1]!="#"
|
516
516
|
## redirect R output
|
517
517
|
code << l2 << "\n" ##ajout de "\n" grace à Pierre (le 15/12/05) pour bug: "1:10 #toto" -> pas de sortie car parse erreur n2!!!
|
518
518
|
case @@mode
|
519
519
|
when :capture_cqls
|
520
|
-
##TODO: instead of only splitting check that there is no
|
521
|
-
## or ask the user to use another character instead of ";" printed as is in the input!
|
520
|
+
##TODO: instead of only splitting check that there is no
|
521
|
+
## or ask the user to use another character instead of ";" printed as is in the input!
|
522
522
|
codes=code.split(";")
|
523
523
|
#Dyndoc.warn :codes, codes
|
524
524
|
evalOk=(R4rb << ".output <<- ''")
|
@@ -527,8 +527,8 @@ module Dyndoc
|
|
527
527
|
#Dyndoc.warn "tmp",tmp
|
528
528
|
}
|
529
529
|
when :capture_protected
|
530
|
-
##TODO: instead of only splitting check that there is no
|
531
|
-
## or ask the user to use another character instead of ";" printed as is in the input!
|
530
|
+
##TODO: instead of only splitting check that there is no
|
531
|
+
## or ask the user to use another character instead of ";" printed as is in the input!
|
532
532
|
codes=code.split(";")
|
533
533
|
evalOk=(R4rb << ".output <<- ''")
|
534
534
|
codes.each{|cod|
|
@@ -567,10 +567,10 @@ module Dyndoc
|
|
567
567
|
#p evalOk;p code;R4rb << "print(geterrmessage())";R4rb << "if(exists(\".output\") ) print(.output)"
|
568
568
|
if evalOk
|
569
569
|
txt=(@@out < '.output' ) ##.join("\n").split(/\n/)
|
570
|
-
code=""
|
570
|
+
code=""
|
571
571
|
else
|
572
572
|
txt=@@out=[]
|
573
|
-
end
|
573
|
+
end
|
574
574
|
if optout and optout.keys.include? "short"
|
575
575
|
short=optout["short"].split(",")
|
576
576
|
short[0]=short[0].to_i
|
@@ -598,7 +598,7 @@ module Dyndoc
|
|
598
598
|
results << result unless (result[:input]+result[:output]).empty?
|
599
599
|
#end
|
600
600
|
input,output="",""
|
601
|
-
|
601
|
+
|
602
602
|
end
|
603
603
|
if passe==0 and l2[0,1]=="#"
|
604
604
|
result={}
|
@@ -617,7 +617,7 @@ module Dyndoc
|
|
617
617
|
results << result
|
618
618
|
input,output="",""
|
619
619
|
end
|
620
|
-
optout=nil
|
620
|
+
optout=nil
|
621
621
|
hide -= 1 if hide>0
|
622
622
|
passe -=1 if passe>0
|
623
623
|
#Dyndoc.warn :hide2,hide
|
@@ -626,7 +626,7 @@ module Dyndoc
|
|
626
626
|
R4rb << "dev.off()"
|
627
627
|
imgCopy.each{|e|
|
628
628
|
FileUtils.mkdir_p File.dirname(e[:out]) unless File.exist? File.dirname(e[:out])
|
629
|
-
if File.exists? e[:in]
|
629
|
+
if File.exists? e[:in]
|
630
630
|
FileUtils.mv(e[:in],e[:out])
|
631
631
|
else
|
632
632
|
Dyndoc.warn "WARNING! #{e[:in]} does not exists for #{e[:out]}"
|
@@ -638,7 +638,7 @@ module Dyndoc
|
|
638
638
|
#Dyndoc.warn :results, results
|
639
639
|
return results
|
640
640
|
end
|
641
|
-
|
641
|
+
|
642
642
|
@@out=[]
|
643
643
|
|
644
644
|
@@start,@@stop="\\{","\\}"
|
@@ -647,7 +647,7 @@ module Dyndoc
|
|
647
647
|
#out2=out.gsub(/\\n/,'\textbackslash{n}')
|
648
648
|
out.gsub("{",'\{').gsub("}",'\}').gsub("~",'\boldmath\ensuremath{\mathtt{\sim}}')
|
649
649
|
end
|
650
|
-
|
650
|
+
|
651
651
|
def RServer.formatInput(out)
|
652
652
|
out2=out.gsub(/\\n/,'\textbackslash{n}')
|
653
653
|
## {\texttildelow}
|
@@ -665,7 +665,7 @@ module Dyndoc
|
|
665
665
|
#Dyndoc.warn :formatInput4, [out,out2,out3]
|
666
666
|
return out2.gsub("~",'\boldmath\ensuremath{\mathtt{\sim}}')
|
667
667
|
end
|
668
|
-
|
668
|
+
|
669
669
|
|
670
670
|
def RServer.filter(str)
|
671
671
|
## modified (28/5/04) (old : /\#R\{.+\}/ => {\#R{ok}} does not work since "ok}" was selected !!
|
@@ -696,7 +696,7 @@ module Dyndoc
|
|
696
696
|
#puts "New env #{env} in #{parent}"
|
697
697
|
".GlobalEnv$.env4dyn$#{env}<-new.env(parent=.GlobalEnv$.env4dyn$#{parent})".to_R
|
698
698
|
end
|
699
|
-
|
699
|
+
|
700
700
|
def RServer.local_code_envir(code,env="Global")
|
701
701
|
"local({"+code+"},.GlobalEnv$.env4dyn$#{env})"
|
702
702
|
end
|
@@ -737,7 +737,7 @@ module Dyndoc
|
|
737
737
|
#Dyndoc.warn "without",code,(@@out < "evalq("+code+",.env4dyn$"+env+")"),"done"
|
738
738
|
code="prettyNum("+code+")" if pretty
|
739
739
|
#Dyndoc.warn "with",code,(@@out < "evalq("+code+",.env4dyn$"+env+")"),"done"
|
740
|
-
|
740
|
+
|
741
741
|
## code="evalq("+code+",envir=.GlobalEnv$.env4dyn$"+env+")" ##-> replaced by
|
742
742
|
code=RServer.code_envir(code,env)
|
743
743
|
#Dyndoc.warn "RServer.output->",code,(@@out < code)
|
@@ -753,13 +753,13 @@ module Dyndoc
|
|
753
753
|
#Dyndoc.warn "without",code,(@@out < "evalq("+code+",.env4dyn$"+env+")"),"done"
|
754
754
|
code="prettyNum("+code+")" if opts[:pretty]
|
755
755
|
#Dyndoc.warn "with",code,(@@out < "evalq("+code+",.env4dyn$"+env+")"),"done"
|
756
|
-
|
756
|
+
|
757
757
|
## code="evalq("+code+",envir=.GlobalEnv$.env4dyn$"+env+")" ##-> replaced by
|
758
758
|
code=RServer.code_envir(code,env)
|
759
759
|
#Dyndoc.warn "RServer.output->",code,(@@out < code)
|
760
760
|
#Dyndoc.warn "RServer.safe_output: capture",capture,code
|
761
761
|
if opts[:capture] or opts[:blockR]
|
762
|
-
## IMPORTANT; this is here to ensure that a double output is avoided at the end if the last instruction is a print
|
762
|
+
## IMPORTANT; this is here to ensure that a double output is avoided at the end if the last instruction is a print
|
763
763
|
code = "invisible("+code+")" if invisible
|
764
764
|
code+=";invisible()" if opts[:blockR]
|
765
765
|
#Dyndoc.warn "safe_output",code
|
@@ -769,11 +769,11 @@ module Dyndoc
|
|
769
769
|
else
|
770
770
|
res=(@@out < "{.result_try_code<-try({"+code+"},silent=TRUE);if(inherits(.result_try_code,'try-error')) 'try-error' else .result_try_code}") #.join(', ')
|
771
771
|
end
|
772
|
-
res
|
772
|
+
res
|
773
773
|
end
|
774
774
|
|
775
775
|
#more useful than echo_tex!!!
|
776
|
-
def RServer.rout(code,env="Global")
|
776
|
+
def RServer.rout(code,env="Global")
|
777
777
|
out="> "+code
|
778
778
|
code="capture.output({"+code+"})"
|
779
779
|
## code="evalq("+code+",.GlobalEnv$.env4dyn$"+env+")" ##-> replaced by
|
@@ -793,15 +793,15 @@ module Dyndoc
|
|
793
793
|
R4rb << "print(.libPaths())"
|
794
794
|
end
|
795
795
|
R4rb << "if(!(Sys.getenv('R_LIBS_USER') %in% .libPaths())) .libPaths(Sys.getenv('R_LIBS_USER'))"
|
796
|
-
|
797
|
-
|
796
|
+
## R4rb << "require(dyndoc)" => put in TemplateManager.initR dyndocTools.R
|
797
|
+
R4rb << "require(rb4R)"
|
798
798
|
end
|
799
799
|
|
800
800
|
end
|
801
801
|
|
802
802
|
class JLServer
|
803
803
|
|
804
|
-
# def JLServer.init(mode=:default) #mode=maybe zmq (to investigate)
|
804
|
+
# def JLServer.init(mode=:default) #mode=maybe zmq (to investigate)
|
805
805
|
# require 'jl4rb'
|
806
806
|
# Julia.init
|
807
807
|
# end
|
@@ -43,6 +43,11 @@ module Dyndoc
|
|
43
43
|
|
44
44
|
# Maybe better located inside server.rb
|
45
45
|
def TemplateManager.initR
|
46
|
+
# For windows! R now change HOME variable by appending "/Documents" at the end. Ruby does not do that!
|
47
|
+
unless File.exist? File.join(ENV["HOME"],"R","win-library")
|
48
|
+
ENV["HOME"] += "/Documents"
|
49
|
+
end
|
50
|
+
|
46
51
|
first=require "R4rb" #save if it the first initialization!
|
47
52
|
Dyndoc.warn "FIRST INIT OF R!!!! => #{first}"
|
48
53
|
Array.initR
|