dyndoc-ruby-core 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/dyndoc/.DS_Store +0 -0
- data/dyndoc/Dyn/.postload +1 -0
- data/dyndoc/Dyn/.preload +1 -0
- data/dyndoc/Dyn/After.dyn +3 -0
- data/dyndoc/Dyn/Base.dyn +18 -0
- data/dyndoc/Dyn/Minimum.dyn +20 -0
- data/dyndoc/Model/Html/DefaultPost_html.dyn +5 -0
- data/dyndoc/Model/Html/DefaultPre_html.dyn +15 -0
- data/dyndoc/Model/Odt/DefaultPost_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPost_tmpl_content.xml +3 -0
- data/dyndoc/Model/Odt/DefaultPre_content.xml +8 -0
- data/dyndoc/Model/Odt/DefaultPre_tmpl_content.xml +8 -0
- data/dyndoc/Model/Tex/ContentPost_tmpl.tex +1 -0
- data/dyndoc/Model/Tex/ContentPre_tmpl.tex +6 -0
- data/dyndoc/Model/Tex/DefaultPost_tmpl.tex +73 -0
- data/dyndoc/Model/Tex/DefaultPre_tmpl.tex +16 -0
- data/dyndoc/Model/Ttm/DefaultPost_tmpl.ttm +3 -0
- data/dyndoc/Model/Ttm/DefaultPre_tmpl.ttm +16 -0
- data/dyndoc/Std/Array.dyn +96 -0
- data/dyndoc/Std/Composer.dyn +38 -0
- data/dyndoc/Std/DevTag.dyn +101 -0
- data/dyndoc/Std/DynVar.dyn +23 -0
- data/dyndoc/Std/File.dyn +55 -0
- data/dyndoc/Std/Git.dyn +34 -0
- data/dyndoc/Std/List.dyn +46 -0
- data/dyndoc/Std/OOP.dyn +32 -0
- data/dyndoc/Std/Signal.dyn +18 -0
- data/dyndoc/Std/String.dyn +22 -0
- data/dyndoc/Std/Styles.dyn +1 -0
- data/dyndoc/Std/Test.dyn +282 -0
- data/dyndoc/Std/Utils.dyn +42 -0
- data/dyndoc/Std/Verb.dyn +5 -0
- data/dyndoc/Style/Notation/Math.dyn +7 -0
- data/dyndoc/Style/Notation/Stat/Classic.dyn +8 -0
- data/dyndoc/Style/Notation/Stat/Cqls.dyn +44 -0
- data/dyndoc/Style/Text/Std.dyn +5 -0
- data/dyndoc/Style/Text/StdAlias.dyn +3 -0
- data/dyndoc/Style/Text/StdTex.dyn +17 -0
- data/dyndoc/Style/Text/Txt.dyn +1 -0
- data/dyndoc/Tex/.postload +1 -0
- data/dyndoc/Tex/.preload +1 -0
- data/dyndoc/Tex/10pt_tmpl.tex +1 -0
- data/dyndoc/Tex/11pt_tmpl.tex +1 -0
- data/dyndoc/Tex/12pt_tmpl.tex +1 -0
- data/dyndoc/Tex/Article_tmpl.tex +1 -0
- data/dyndoc/Tex/Beamer.dyn_tex +35 -0
- data/dyndoc/Tex/BeamerHandout_tmpl.tex +2 -0
- data/dyndoc/Tex/Book_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultFirst_tmpl.tex +1 -0
- data/dyndoc/Tex/DefaultLast_tmpl.tex +8 -0
- data/dyndoc/Tex/Default_tmpl.tex +9 -0
- data/dyndoc/Tex/First_tmpl.tex +8 -0
- data/dyndoc/Tex/Fr_tmpl.tex +17 -0
- data/dyndoc/Tex/Header_tmpl.tex +3 -0
- data/dyndoc/Tex/InclGraph_tmpl.tex +19 -0
- data/dyndoc/Tex/InclSpatProc_tmpl.tex +70 -0
- data/dyndoc/Tex/InclSumMI_tmpl.tex +4 -0
- data/dyndoc/Tex/LargeA4_tmpl.tex +5 -0
- data/dyndoc/Tex/Last_tmpl.tex +1 -0
- data/dyndoc/Tex/Option_tmpl.tex +8 -0
- data/dyndoc/Tex/Png_tmpl.tex +1 -0
- data/dyndoc/Tex/RefCite2_tmpl.tex +16 -0
- data/dyndoc/Tex/RefCite_tmpl.tex +16 -0
- data/dyndoc/Tex/Report_tmpl.tex +1 -0
- data/dyndoc/Tex/Theorem_tmpl.tex +14 -0
- data/dyndoc/Tools/.DS_Store +0 -0
- data/dyndoc/Tools/Atom.dyn/index.dyn +42 -0
- data/dyndoc/Tools/AtomDyndocker.dyn/index.dyn +43 -0
- data/dyndoc/Tools/R/Fig.dyn +144 -0
- data/dyndoc/Tools/R/Tools.dyn +344 -0
- data/dyndoc/Tools/Tex/Beamer.dyn +204 -0
- data/dyndoc/Tools/Tex/BeamerSlide.dyn_tex +199 -0
- data/dyndoc/Tools/Tex/Pgf.dyn +115 -0
- data/dyndoc/Tools/Tex/Table.dyn +278 -0
- data/dyndoc/Tools/Tex/Tools.dyn +37 -0
- data/dyndoc/Tools/Tex/Verb.dyn +77 -0
- data/dyndoc/Tools/Web/.DS_Store +0 -0
- data/dyndoc/Tools/Web/Ace.dyn +54 -0
- data/dyndoc/Tools/Web/Code.dyn +129 -0
- data/dyndoc/Tools/Web/DHtmlX.dyn +39 -0
- data/dyndoc/Tools/Web/DataTable.dyn_html +354 -0
- data/dyndoc/Tools/Web/Html.dyn +286 -0
- data/dyndoc/Tools/Web/Html/JQuery.dyn +123 -0
- data/dyndoc/Tools/Web/Html/Styles.dyn +4 -0
- data/dyndoc/Tools/Web/JQueryTools.dyn +87 -0
- data/dyndoc/Tools/Web/Layout.dyn +86 -0
- data/dyndoc/Tools/Web/Layout/CQLS.dyn +6 -0
- data/dyndoc/Tools/Web/Layout/LJK.dyn +41 -0
- data/dyndoc/Tools/Web/TabBar.dyn +37 -0
- data/dyndoc/Tools/Web/Ttm.dyn +20 -0
- data/dyndoc/Tools/Web/Txtl.dyn +14 -0
- data/lib/dyndoc-core.rb +59 -0
- data/lib/dyndoc/base/envir.rb +541 -0
- data/lib/dyndoc/base/filter/call.rb +127 -0
- data/lib/dyndoc/base/filter/filter_mngr.rb +637 -0
- data/lib/dyndoc/base/filter/server.rb +882 -0
- data/lib/dyndoc/base/filters.rb +3 -0
- data/lib/dyndoc/base/helpers.rb +9 -0
- data/lib/dyndoc/base/helpers/core.rb +32 -0
- data/lib/dyndoc/base/helpers/parser.rb +188 -0
- data/lib/dyndoc/base/scanner.rb +886 -0
- data/lib/dyndoc/base/tags.rb +4 -0
- data/lib/dyndoc/base/tags/keys_mngr.rb +401 -0
- data/lib/dyndoc/base/tags/part_tag.rb +194 -0
- data/lib/dyndoc/base/tags/tag_mngr.rb +125 -0
- data/lib/dyndoc/base/tags/user_tag.rb +216 -0
- data/lib/dyndoc/base/tmpl.rb +6 -0
- data/lib/dyndoc/base/tmpl/eval.rb +581 -0
- data/lib/dyndoc/base/tmpl/extension.rb +337 -0
- data/lib/dyndoc/base/tmpl/manager.rb +450 -0
- data/lib/dyndoc/base/tmpl/oop.rb +57 -0
- data/lib/dyndoc/base/tmpl/parse_do.rb +2446 -0
- data/lib/dyndoc/base/tmpl/rbenvir.rb +54 -0
- data/lib/dyndoc/base/utils.rb +367 -0
- data/lib/dyndoc/common/dynArray.rb +234 -0
- data/lib/dyndoc/common/file.rb +52 -0
- data/lib/dyndoc/common/init.rb +2 -0
- data/lib/dyndoc/common/tilt.rb +149 -0
- data/lib/dyndoc/common/utils.rb +61 -0
- data/lib/dyndoc/common/uv.rb +163 -0
- data/lib/dyndoc/init/config.rb +296 -0
- data/lib/dyndoc/init/home.rb +9 -0
- data/lib/dyndoc/plugins/tex.rb +4 -0
- data/lib/dyndoc/plugins/tex/beamer.rb +208 -0
- data/lib/dyndoc/plugins/tex/tex_eval.rb +69 -0
- data/lib/dyndoc/plugins/tex/tex_parse_do.rb +25 -0
- data/lib/dyndoc/plugins/tex/tex_user_tag.rb +32 -0
- data/share/R/dyndocMsys2.R +5 -0
- data/share/R/dyndocTools.R +9 -0
- data/share/R/test.R +14 -0
- data/share/R/tools/dynArray.R +34 -0
- data/share/R/tools/dynCapture.R +84 -0
- data/share/R/tools/dynMsys2.R +54 -0
- data/share/julia/dynArray.jl +93 -0
- data/share/julia/dyndoc.jl +110 -0
- data/share/julia/ruby.jl +37 -0
- metadata +202 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
module Dyndoc
|
2
|
+
module Ruby
|
3
|
+
|
4
|
+
class TemplateManager
|
5
|
+
|
6
|
+
def rbenvir_init(envir)
|
7
|
+
@rbEnvir=[envir]
|
8
|
+
end
|
9
|
+
|
10
|
+
def rbenvir_new
|
11
|
+
#l'objectif est que comme c'est une méthode toutes les
|
12
|
+
#fonctions de parsing de l'objet sont connues!
|
13
|
+
binding
|
14
|
+
end
|
15
|
+
|
16
|
+
def rbenvir_go_to(inRb,envir=nil)
|
17
|
+
if inRb
|
18
|
+
#puts "rbenvir_go_to #{inRb.inspect}"
|
19
|
+
inRb=":new" if ["new","none",":none","nil"].include? inRb
|
20
|
+
@rbEnvirs={} unless @rbEnvirs
|
21
|
+
#p inRb
|
22
|
+
@rbEnvirs[inRb]=rbenvir_new if inRb==":new" or !@rbEnvirs[inRb]
|
23
|
+
@rbEnvirs[inRb]=envir if envir and inRb!=":new"
|
24
|
+
#puts "rbenvir_go_to";p envir
|
25
|
+
@rbEnvir.unshift(@rbEnvirs[inRb])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def rbenvir_back_from(inRb)
|
30
|
+
@rbEnvir.shift if inRb
|
31
|
+
end
|
32
|
+
|
33
|
+
def rbenvir_ls(rbEnvir=nil)
|
34
|
+
rbEnvir=@rbEnvir[0] unless rbEnvir
|
35
|
+
rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol
|
36
|
+
rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer
|
37
|
+
eval("local_variables",rbEnvir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def rbenvir_get(rbEnvir=nil)
|
41
|
+
rbEnvir=@rbEnvir[0] unless rbEnvir #the current if nil
|
42
|
+
rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol
|
43
|
+
rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer
|
44
|
+
rbEnvir
|
45
|
+
end
|
46
|
+
|
47
|
+
def rbenvir_current
|
48
|
+
@rbEnvirs.keys.select{|b| @rbEnvirs[b]==@rbEnvir[0]}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,367 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Dyndoc
|
4
|
+
|
5
|
+
CHARS_SET_FIRST=[["_{_","__OPEN__"],["_}_","__CLOSE__"]]
|
6
|
+
CHARS_SET_LAST=[["__OPEN__","{"],["__CLOSE__","}"]]
|
7
|
+
PROTECT_FORMAT_BLOCKTEXT="<protect-format-blocktext>"
|
8
|
+
|
9
|
+
module Utils
|
10
|
+
## variable sep!
|
11
|
+
def Utils.split_code_by_sep(code,sep="|")
|
12
|
+
return code.split("\n").map{|e| e.split(sep)}.flatten
|
13
|
+
end
|
14
|
+
|
15
|
+
def Utils.preserve_pattern(line,pattern,chars)
|
16
|
+
line.gsub(pattern){|s| Utils.escape(s,chars)}
|
17
|
+
end
|
18
|
+
|
19
|
+
## used in [\#var] and [\#set]
|
20
|
+
## protect "|" inside @{toto(...)}
|
21
|
+
def Utils.split_code(code,pattern=/@\{.*\}/,chars=["|","@@@"])
|
22
|
+
inst=Utils.preserve_pattern(code,pattern,chars)
|
23
|
+
inst,*b=inst.split(/\n\-{3,}\n/)
|
24
|
+
b=inst.strip.split("\n").map{|e| e.split(chars[0])}.flatten+b if inst
|
25
|
+
b.map!{|l| Utils.preserve_pattern(l,pattern,chars.reverse)}
|
26
|
+
return b
|
27
|
+
end
|
28
|
+
|
29
|
+
def Utils.silence_warnings(val=nil)
|
30
|
+
old_verbose, $VERBOSE = $VERBOSE, val
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
$VERBOSE = old_verbose
|
34
|
+
end
|
35
|
+
|
36
|
+
def Utils.make_doc(txt)
|
37
|
+
out=txt.split("\n")
|
38
|
+
## Ajout surement du à kile qui rajoutte des "\r" => générant un bug dans R
|
39
|
+
out.map!{|e| (e[-1,1]=="\r" ? e[0...-1] : e )}
|
40
|
+
return out
|
41
|
+
end
|
42
|
+
|
43
|
+
# TOOLS ###################################
|
44
|
+
def Utils.clean_comment(b)
|
45
|
+
b.map!{|l| ( l.scan(/([^%]*)(%%.*)/)[0] ? $1.strip : l)}.reject!{|e| e.empty?}
|
46
|
+
end
|
47
|
+
|
48
|
+
def Utils.clean_indent(b)
|
49
|
+
start,key=b[0].scan(/(\s*)([^\s]*)/)[0]
|
50
|
+
if start.length>0
|
51
|
+
b.map!{|l|
|
52
|
+
( (l.index start)==0 ? l[start.length,l.length-start.length] : l )
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def Utils.escape(str,chars)
|
58
|
+
str.gsub(/#{Regexp.escape(chars[0])}/,chars[1])
|
59
|
+
end
|
60
|
+
|
61
|
+
def Utils.escape!(str,chars_set)
|
62
|
+
chars_set.each{|chars| str.gsub!(/#{Regexp.escape(chars[0])}/,chars[1]) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def Utils.escape_delim!(str,mode=:last)
|
66
|
+
chars_set=(mode==:first ? CHARS_SET_FIRST : CHARS_SET_LAST )
|
67
|
+
chars_set.each{|chars| str.gsub!(/#{Regexp.escape(chars[0])}/,chars[1]) }
|
68
|
+
return str
|
69
|
+
end
|
70
|
+
|
71
|
+
def Utils.end_line(key,code)
|
72
|
+
while key[-1,1]=="\\"
|
73
|
+
key=(key[0...-1]+(code.shift)).strip
|
74
|
+
end
|
75
|
+
return [key,code]
|
76
|
+
end
|
77
|
+
|
78
|
+
def Utils.clean_eol(str)
|
79
|
+
str.gsub!("\r\n","\n")
|
80
|
+
end
|
81
|
+
|
82
|
+
def Utils.clean_bom_utf8!(str)
|
83
|
+
str.gsub!("\xEF\xBB\xBF", '')
|
84
|
+
end
|
85
|
+
|
86
|
+
# To consider first and last whitespaces put before and after an escaped sequence! Before the string is formatted for indentation convenience!
|
87
|
+
def Utils.protect_blocktext(str,seq="__STR__")
|
88
|
+
#str=code+str if str[0,1]==" "
|
89
|
+
#str=str+code if str[-1,1]==" "
|
90
|
+
#puts "protect_blocktext";p str
|
91
|
+
#puts "format_blocktext";p Utils.format_blocktext(str)
|
92
|
+
seq+Utils.format_blocktext(str)+seq
|
93
|
+
end
|
94
|
+
|
95
|
+
# When considered, remove the escaped sequence!
|
96
|
+
def Utils.unprotect_blocktext(str,seq="__STR__")
|
97
|
+
#puts "unprotect blocktext";p str
|
98
|
+
str.gsub(seq,"")
|
99
|
+
end
|
100
|
+
|
101
|
+
def Utils.format_blocktext(str)
|
102
|
+
str.gsub(/\n[ \t\r\f]*\|/,"\n").gsub(/\|\n/,"").gsub("<\\n>","\n").gsub("<\\t>","\t")
|
103
|
+
end
|
104
|
+
|
105
|
+
#called in #txt to protect the corresponding blocktext
|
106
|
+
def Utils.protect_format_blocktext(str)
|
107
|
+
str.gsub(/\n[ \t\r\f]*\|/) {|e| e.gsub(/\|/,"__BLOCKBAR__")}.gsub(/\|\n/,"__BLOCKBAR__\n").gsub("<\\n>","__BLOCKSPACE__").gsub("<\\t>","__BLOCKTAB__")
|
108
|
+
end
|
109
|
+
|
110
|
+
def Utils.unprotect_format_blocktext(str)
|
111
|
+
str.gsub("__BLOCKBAR__","|").gsub("__BLOCKSPACE__","<\\n>").gsub("__BLOCKTAB__","<\\t>").gsub("__RAW__","")
|
112
|
+
end
|
113
|
+
|
114
|
+
def Utils.protect_txt_block(str)
|
115
|
+
str2=Utils.protect_format_blocktext(str)
|
116
|
+
Utils.escape!(str2,[["{","_{_"],["}","_}_"]])
|
117
|
+
Utils.escape_delim!(str2,:first)
|
118
|
+
str2
|
119
|
+
end
|
120
|
+
|
121
|
+
def Utils.protect_extraction(str)
|
122
|
+
str.gsub(/(?:\#|\#\#|@|#F|#R|#r|\:R|\:r|#Rb|#rb|\:|\:Rb|\:rb)+\{/) {|e| "\\"+e}
|
123
|
+
end
|
124
|
+
|
125
|
+
## the scanner converts automatically {#toto#} in {#toto][#} and {@toto@} in {@toto][#}
|
126
|
+
## this function does the convert when needed for verbatim or code.
|
127
|
+
def Utils.format_call_without_param(code)
|
128
|
+
code.gsub(/\{(\#|\@)(\w*)\]\[\#\}/,'{\1\2\1}')
|
129
|
+
end
|
130
|
+
|
131
|
+
def Utils.format_call_without_param!(code)
|
132
|
+
code.gsub!(/\{(\#|\@)(\w*)\]\[\#\}/,'{\1\2\1}')
|
133
|
+
end
|
134
|
+
|
135
|
+
def Utils.uuidgen
|
136
|
+
`uuidgen`.strip
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
@@raw_text,@@raw_key,@@raw_var_ls=[],[],[]
|
141
|
+
|
142
|
+
## multilines is for @verbatim which behaves differently depending on the number of lines in the content
|
143
|
+
## when the key replaces the content this solves the problem!
|
144
|
+
def Utils.dyndoc_raw_text_key(key=nil,multilines=nil)
|
145
|
+
"__"+(key=( key ? key : "" ))+"|"+Utils.uuidgen+"__"+(multilines ? "\n__"+key+"__" : "")
|
146
|
+
end
|
147
|
+
|
148
|
+
## add a raw text
|
149
|
+
def Utils.dyndoc_raw_text_add(raw_text,key=nil,gen_key=true)
|
150
|
+
@@raw_key << (key=(gen_key ? Utils.dyndoc_raw_text_key(key,raw_text=~/\r?\n/) : key ))
|
151
|
+
@@raw_text << [raw_text] #like a pointer!
|
152
|
+
#puts "dyndoc_raw_text:key";p key
|
153
|
+
key
|
154
|
+
end
|
155
|
+
|
156
|
+
## find a raw text
|
157
|
+
def Utils.dyndoc_raw_text(key=nil)
|
158
|
+
if key
|
159
|
+
ind=@@raw_key.index{|e| e==key or e=~/^\_\_#{key}/}
|
160
|
+
#p (ind ? @@raw_text[ind][0] : nil)
|
161
|
+
(ind ? @@raw_text[ind][0] : nil)
|
162
|
+
else
|
163
|
+
[@@raw_key,@@raw_text]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
## apply replacement in out
|
168
|
+
def Utils.dyndoc_raw_text!(out,opt={:clean=>nil,:once=>nil})
|
169
|
+
@@raw_key.each_index do |i|
|
170
|
+
#p [@@raw_key[i],@@raw_text[i]]
|
171
|
+
#begin puts @@raw_key[i];p @@raw_text[i];puts @@raw_text[i]; end #if i==1
|
172
|
+
@@raw_text[i][0].gsub!('\\\\','\\\\\\\\\\')
|
173
|
+
out.gsub!(@@raw_key[i],@@raw_text[i][0]) #if the result is placed into a dyn variable, it can be repeated!
|
174
|
+
@@raw_text[i][0]="" if opt[:once] #used only once!!! Ex: used by raw.
|
175
|
+
end
|
176
|
+
@@raw_text,@@raw_key=[],[] if opt[:clean]
|
177
|
+
##puts "dyndoc_raw:out";puts out
|
178
|
+
return out
|
179
|
+
end
|
180
|
+
|
181
|
+
RAW_TAGS={"{#code]"=>"[#code}","{#raw]"=>"[#raw}"}
|
182
|
+
RAW_LANG={"r"=>"R","rb"=>"ruby"}
|
183
|
+
|
184
|
+
|
185
|
+
## Just used inside do_rb in parse_do.rb file to save rbcode before process_rb!
|
186
|
+
@@raw_code_to_process=true
|
187
|
+
def Utils.raw_code_to_process=(state=nil)
|
188
|
+
@@raw_code_to_process=state
|
189
|
+
end
|
190
|
+
|
191
|
+
def Utils.raw_code_to_process
|
192
|
+
return @@raw_code_to_process
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
def Utils.parse_raw_text!(txt,tmplMngr=nil)
|
198
|
+
#puts "parse_raw_text:";p txt
|
199
|
+
filter=/(?:(\{\#code\]|\{\#raw\])(\s*[\w\.\-_:]+\s*)(\[\#(?:dyn|R|r|ruby|rb)(?:\>|\<)?\]\n?)|(\[\#code\}|\[\#raw\}))/m
|
200
|
+
txt2=txt.split(filter,-1)
|
201
|
+
return if txt2.length==1
|
202
|
+
#Dyndoc.warn "parse:txt2",txt2
|
203
|
+
code=""
|
204
|
+
while txt2.length>1
|
205
|
+
if RAW_TAGS.keys.include? txt2[0] and txt2[1..-1].include? RAW_TAGS[txt2[0]]
|
206
|
+
tag,name,lang=txt2.shift(3)
|
207
|
+
name=~/\s*([\w\.\-_:]+)\s*/
|
208
|
+
name=$1
|
209
|
+
lang=~/\[\#(dyn|R|r|ruby|rb)(\>|\<)?\]/
|
210
|
+
lang,type=$1,$2
|
211
|
+
lang="dyn" unless lang
|
212
|
+
lang=RAW_LANG[lang] if RAW_LANG[lang]
|
213
|
+
type="<" unless type
|
214
|
+
code2=""
|
215
|
+
code2 << txt2.shift until txt2[0]==RAW_TAGS[tag]
|
216
|
+
#puts "parse_raw_text:name,type,mode,code";p [name,type,lang,code2]
|
217
|
+
key=Utils.dyndoc_raw_text_add(code2,name+"-"+lang)
|
218
|
+
#puts "parse_raw_text:key added";p key
|
219
|
+
code << key if type==">"
|
220
|
+
if tmplMngr
|
221
|
+
## puts inside global envir!
|
222
|
+
envir=tmplMngr.filterGlobal.envir
|
223
|
+
envir[lang+"."+name+".name"]=key
|
224
|
+
envir[lang+"."+name+".code"]=@@raw_text[-1]
|
225
|
+
## "content" would be the name of the result after evaluation and saved in <dyn_basename_file>.dyn_out/raw_code.dyn
|
226
|
+
end
|
227
|
+
@@raw_var_ls << lang+"."+name #
|
228
|
+
txt2.shift #last close tag!
|
229
|
+
else
|
230
|
+
code << txt2.shift
|
231
|
+
end
|
232
|
+
end
|
233
|
+
code << txt2.join("") #the remaining code
|
234
|
+
|
235
|
+
##OLD: @@raw_key_index=@@raw_key.map{|key| key=~/\_\_(.*)\|(.*)/ ? $1 : nil}.compact
|
236
|
+
##puts "code";p code
|
237
|
+
txt.replace(code)
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
def Utils.dyndoc_raw_var_ls
|
242
|
+
@@raw_var_ls
|
243
|
+
end
|
244
|
+
|
245
|
+
def Utils.dyndoc_raw_var_eval(var,tmplMngr=nil) #var differs from key since it is saved in filter!
|
246
|
+
return "" unless tmplMngr
|
247
|
+
#p var
|
248
|
+
return ((@@raw_var_ls.include? var) ? tmplMngr.parse(tmplMngr.filterGlobal.envir[var+".code"]) : "" )
|
249
|
+
end
|
250
|
+
|
251
|
+
def Utils.dyndoc_raw_var_save(var,tmplMngr=nil)
|
252
|
+
return unless tmplMngr
|
253
|
+
#puts "raw_var_save_content";p var+".content"
|
254
|
+
envir=tmplMngr.filterGlobal.envir
|
255
|
+
content=Utils.dyndoc_raw_var_eval(var,tmplMngr)
|
256
|
+
#p content
|
257
|
+
envir[var+".eval"]=content
|
258
|
+
#for next compilation
|
259
|
+
Utils.saved_content_add_as_variable(var+".eval",content,tmplMngr.filename)
|
260
|
+
end
|
261
|
+
|
262
|
+
def Utils.dyndoc_raw_var_content(var,tmplMngr=nil)
|
263
|
+
return "" unless tmplMngr
|
264
|
+
#puts "var_content";p var+".content"
|
265
|
+
#p tmplMngr.filter.envir.global["dyn"]
|
266
|
+
#p tmplMngr.filterGlobal.envir
|
267
|
+
Utils.dyndoc_raw_var_save(var,tmplMngr) if !tmplMngr.filterGlobal.envir[var+".eval"] or Utils.saved_content_to_be_recreated(tmplMngr).include? var
|
268
|
+
tmplMngr.filterGlobal.envir[var+".eval"]
|
269
|
+
end
|
270
|
+
|
271
|
+
SAVED_CONTENTS_FILE="saved_contents.dyn"
|
272
|
+
|
273
|
+
def Utils.saved_content_fetch_variables_from_file(filename,tmplMngr=nil)
|
274
|
+
return unless tmplMngr
|
275
|
+
#p filename
|
276
|
+
return unless out_rsrc=Dyndoc::Utils.out_rsrc_exists?(filename)
|
277
|
+
return unless File.exists?(saved_contents_file=File.join(out_rsrc,SAVED_CONTENTS_FILE)) ##normally, autogenerated!
|
278
|
+
#p out_rsrc
|
279
|
+
## fetch the contents by reading and parsing unsing the global filter!
|
280
|
+
#puts "saved_contents_file";p saved_contents_file
|
281
|
+
code="{#document][#main]"+File.read(saved_contents_file)+"[#}"
|
282
|
+
tmplMngr.parse(code,tmplMngr.filterGlobal)
|
283
|
+
#puts "fetch var:dyn";p tmplMngr.filter.envir.global["dyn"]
|
284
|
+
end
|
285
|
+
|
286
|
+
@@saved_content_ls=[]
|
287
|
+
@@saved_content_to_be_recreated=nil
|
288
|
+
|
289
|
+
def Utils.saved_content_to_be_recreated(tmplMngr)
|
290
|
+
unless @@saved_content_to_be_recreated
|
291
|
+
user_input=tmplMngr.filterGlobal.envir["_.EVAL"]
|
292
|
+
@@saved_content_to_be_recreated=(user_input ? user_input.strip.split(",") : [])
|
293
|
+
end
|
294
|
+
@@saved_content_to_be_recreated
|
295
|
+
end
|
296
|
+
|
297
|
+
def Utils.saved_content_add_as_variable(var,result,filename) #var is dyndoc variable
|
298
|
+
##p filename
|
299
|
+
out_rsrc=Dyndoc::Utils.mkdir_out_rsrc(filename)
|
300
|
+
unless File.exists? File.join(out_rsrc,SAVED_CONTENTS_FILE)
|
301
|
+
File.open(File.join(out_rsrc,SAVED_CONTENTS_FILE),"a") do |f|
|
302
|
+
f << "[#%] File automatically generated! Remove it for regenerating it!\n"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
## if it alread exist, delete it first!
|
306
|
+
Utils.saved_content_delete_as_variable(var,filename)
|
307
|
+
File.open(File.join(out_rsrc,SAVED_CONTENTS_FILE),"a") do |f|
|
308
|
+
f << "[#=]"+var+"["+result+"]\n"
|
309
|
+
end
|
310
|
+
@@saved_content_ls << var
|
311
|
+
end
|
312
|
+
|
313
|
+
def Utils.saved_content_delete_as_variable(var,filename)
|
314
|
+
return unless out_rsrc=Dyndoc::Utils.out_rsrc_exists?(filename)
|
315
|
+
return unless File.exists?(saved_contents_file=File.join(out_rsrc,SAVED_CONTENTS_FILE))
|
316
|
+
saved_contents=File.read(saved_contents_file)
|
317
|
+
## Normally, no problem since no [#=] inside result!
|
318
|
+
saved_contents_new=saved_contents.gsub(/\[\#\=\]\s*#{var}\s*\[.*\]\s*\[\#\=\]/m,"[#=]")
|
319
|
+
unless saved_contents==saved_contents_new
|
320
|
+
File.open(File.join(out_rsrc,SAVED_CONTENTS_FILE),"w") do |f|
|
321
|
+
f << saved_contents_new
|
322
|
+
end
|
323
|
+
@@saved_content_ls.delete(var)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def Utils.saved_content_ls
|
328
|
+
return @@saved_content_ls
|
329
|
+
end
|
330
|
+
|
331
|
+
def Utils.saved_content_get(var,tmplMngr=nil,force=nil)
|
332
|
+
return unless tmplMngr
|
333
|
+
if force
|
334
|
+
return (Utils.saved_content_to_be_recreated(tmplMngr).include? var) ? nil : tmplMngr.filterGlobal.envir[var]
|
335
|
+
else
|
336
|
+
return tmplMngr.filterGlobal.envir[var]
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
## Added for atom
|
341
|
+
def Utils.protect_dyn_block_for_atom(txt)
|
342
|
+
txt.gsub("#","__DIESE_ATOM__") # => since dyndoc command uses "#" this is very easy way to protect evaluation
|
343
|
+
end
|
344
|
+
|
345
|
+
def Utils.parse_dyn_block_for_interactive!(txt)
|
346
|
+
#Dyndoc.warn "parse_dyn_block_for_atom",txt
|
347
|
+
filter=/(?:(\{\#dyn>\])|(\[\#dyn>\}))/m
|
348
|
+
txt2=txt.split(filter,-1)
|
349
|
+
return if txt2.length==1
|
350
|
+
#Dyndoc.warn "parse:txt2",txt2
|
351
|
+
code=""
|
352
|
+
while txt2.length>1
|
353
|
+
if txt2[0]=="{#dyn>]" and txt2[1..-1].include? "[#dyn>}"
|
354
|
+
start,tmp,stop=txt2.shift(3)
|
355
|
+
## protect the dyndoc code to delay the evaluation after unprotection (in javascript)
|
356
|
+
code << Utils.protect_dyn_block_for_atom(tmp.inspect)
|
357
|
+
else
|
358
|
+
code << txt2.shift
|
359
|
+
end
|
360
|
+
end
|
361
|
+
code << txt2.join("") #the remaining code
|
362
|
+
#Dyndoc.warn "atom",code
|
363
|
+
txt.replace(code)
|
364
|
+
end
|
365
|
+
|
366
|
+
end
|
367
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
#require 'jl4rb'
|
2
|
+
#require 'R4rb'
|
3
|
+
|
4
|
+
# Since more than one language is used for Array transfert
|
5
|
+
# This stuff is moved from R4rb package to here
|
6
|
+
# => Undone because R4rb is not self-content
|
7
|
+
# => methods :> and :< overloaded from R4rb
|
8
|
+
|
9
|
+
class Array
|
10
|
+
|
11
|
+
## Already in R4rb and still there to be self-contents
|
12
|
+
# def rb2R=(mode=nil)
|
13
|
+
# ##puts "rb2R mode #{object_id}";p mode
|
14
|
+
# mode=R4rb unless mode
|
15
|
+
# return if @rb2R_mode and @rb2R_mode==mode
|
16
|
+
# @rb2R_mode=mode unless @rb2R_mode
|
17
|
+
# @rb2R=(@rb2R_mode==Rserve ? Rserve::RVector.new("") : R2rb::RVector.new("") )
|
18
|
+
# ##puts "rb2R=";p @rb2R
|
19
|
+
# end
|
20
|
+
|
21
|
+
def rb2jl! #only one mode
|
22
|
+
@rb2jl= Julia::Vector.new("")
|
23
|
+
##puts "rb2jl=";p @rb2jl
|
24
|
+
end
|
25
|
+
# out is a String representing a R or Julia expression
|
26
|
+
|
27
|
+
def >(out)
|
28
|
+
out.strip!
|
29
|
+
mode=:r
|
30
|
+
#out represents here an R or Julia object
|
31
|
+
if out =~ /^jl\:/
|
32
|
+
mode,out=:jl,out[3..-1]
|
33
|
+
elsif out =~ /^(r|R)\:/
|
34
|
+
out=out[2..-1]
|
35
|
+
end
|
36
|
+
case mode
|
37
|
+
when :r
|
38
|
+
self.rb2R=nil unless @rb2R
|
39
|
+
@rb2R << out
|
40
|
+
@rb2R < self
|
41
|
+
when :jl
|
42
|
+
self.rb2jl=nil unless @rb2jl
|
43
|
+
@rb2jl << out
|
44
|
+
@rb2jl < self
|
45
|
+
end
|
46
|
+
return self
|
47
|
+
end
|
48
|
+
|
49
|
+
def <(out) #out represents here an R or Julia expression to execute and put inside the Array
|
50
|
+
out.strip!
|
51
|
+
mode=:r
|
52
|
+
#out represents here an R or Julia object
|
53
|
+
if out =~ /^jl\:/
|
54
|
+
mode,out=:jl,out[3..-1]
|
55
|
+
elsif out =~ /^(r|R)\:/
|
56
|
+
out=out[2..-1]
|
57
|
+
end
|
58
|
+
case mode
|
59
|
+
when :r
|
60
|
+
self.rb2R=nil unless @rb2R
|
61
|
+
@rb2R << out
|
62
|
+
@rb2R > self
|
63
|
+
when :jl
|
64
|
+
self.rb2jl! unless @rb2jl
|
65
|
+
@rb2jl << out
|
66
|
+
@rb2jl > self
|
67
|
+
end
|
68
|
+
|
69
|
+
return self
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
## Dyndoc Array : ruby Array synchronized to Julia or R Vector
|
76
|
+
# when change occurs from any language
|
77
|
+
module Dyndoc
|
78
|
+
|
79
|
+
# Just a fancy funcion to access Dyndoc::Vector in the way as Julia and R
|
80
|
+
def Dyndoc.Vec
|
81
|
+
Dyndoc::Vector
|
82
|
+
end
|
83
|
+
|
84
|
+
class Vector
|
85
|
+
|
86
|
+
## global stuff
|
87
|
+
@@all={}
|
88
|
+
|
89
|
+
def Vector.get
|
90
|
+
@@all
|
91
|
+
end
|
92
|
+
|
93
|
+
def Vector.[](key)
|
94
|
+
@@all[key.to_s]
|
95
|
+
end
|
96
|
+
|
97
|
+
def Vector.[]=(key,value)
|
98
|
+
@@all[key.to_s].replace(value) if value.is_a? Array
|
99
|
+
@@all[key.to_s]
|
100
|
+
end
|
101
|
+
|
102
|
+
## object stuff
|
103
|
+
attr_accessor :vectors, :ary, :id
|
104
|
+
|
105
|
+
# ary is a String when lang is not :rb
|
106
|
+
def initialize(langs=[:r],first=[],lang=:rb,vname=nil)
|
107
|
+
@ary=(first.is_a? String) ? [] : first
|
108
|
+
@vectors={}
|
109
|
+
#@to_update={}
|
110
|
+
@vname,@id=vname,vname #+"@"+self.object_id.abs.to_s
|
111
|
+
if langs.include? :r
|
112
|
+
Array.initR
|
113
|
+
@vectors[:r]=R4rb::RVector.new ""
|
114
|
+
@vectors[:r] << ids(:r)
|
115
|
+
@vectors[:r] < @ary unless @ary.empty?
|
116
|
+
##@to_update[:r]=nil
|
117
|
+
end
|
118
|
+
if langs.include? :jl
|
119
|
+
Julia.init
|
120
|
+
@vectors[:jl]=Julia::Vector.new ""
|
121
|
+
@vectors[:jl] << ids(:jl)
|
122
|
+
Julia << wrapper(:jl)+"=Any[]"
|
123
|
+
@vectors[:jl] < @ary unless @ary.empty?
|
124
|
+
#@to_update[:jl]=nil
|
125
|
+
end
|
126
|
+
# global register => callable for update
|
127
|
+
@@all[ids(:rb)]=self
|
128
|
+
# first init
|
129
|
+
@unlock=true
|
130
|
+
case lang
|
131
|
+
when :jl
|
132
|
+
Julia << ids(:jl)+"="+first
|
133
|
+
sync(:jl)
|
134
|
+
## Julia << "println("+wrapper(:jl)+")"
|
135
|
+
when :r,:R
|
136
|
+
R4rb << ids(:r)+"<-"+first
|
137
|
+
sync(:r)
|
138
|
+
## R4rb << "print("+wrapper(:r)+")"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def inspect
|
143
|
+
@ary.inspect
|
144
|
+
end
|
145
|
+
|
146
|
+
def ids(lang)
|
147
|
+
case lang
|
148
|
+
when :rb
|
149
|
+
@id
|
150
|
+
when :jl
|
151
|
+
"Dyndoc.Vec[\""+@id+"\"].ary"
|
152
|
+
when :r
|
153
|
+
"Dyndoc.Vec[\""+@id+"\"]"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def wrapper(lang)
|
158
|
+
case lang
|
159
|
+
when :rb
|
160
|
+
"Dyndoc.Vec[:"+@id+"]"
|
161
|
+
when :jl
|
162
|
+
"Dyndoc.Vec[\""+@id+"\"]"
|
163
|
+
when :r
|
164
|
+
"Dyndoc.Vec[\""+@id+"\"]"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# from is :rb, :jl or :r
|
169
|
+
def sync(from=:rb)
|
170
|
+
if @unlock
|
171
|
+
@unlock=nil #to avoid the same update several times
|
172
|
+
## Dyndoc.warn "rb sync (from #{from}):",ids(:rb)
|
173
|
+
@vectors[from] > @ary unless from==:rb
|
174
|
+
## Dyndoc.warn "new ary",[@vectors[from].name,@vectors[from].value,@ary]
|
175
|
+
([:jl,:r]-[from]).each do |to|
|
176
|
+
## Dyndoc.warn "rb sync (to #{to})"
|
177
|
+
@vectors[to] < @ary
|
178
|
+
## Dyndoc.warn "@vectors[#{to}].value", @vectors[to].value
|
179
|
+
end
|
180
|
+
@unlock=true
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
## Replacement of sync splitted into 2 parts!
|
185
|
+
## Does not work for sync_to(:jl) => so OBSOLETE from now!
|
186
|
+
# from is :rb, :jl or :r
|
187
|
+
# def sync_from(from=:rb)
|
188
|
+
# if @unlock
|
189
|
+
# @unlock=nil #to avoid the same update several times
|
190
|
+
# ## Dyndoc.warn "rb sync (from #{from}):",ids(:rb)
|
191
|
+
# @vectors[from] > @ary unless from==:rb
|
192
|
+
# ## Dyndoc.warn "sync from #{from}",[@vectors[from].name,@vectors[from].value,@ary]
|
193
|
+
# ## delay the update when demanded!
|
194
|
+
# @to_update[:r]=true unless from==:r
|
195
|
+
# @to_update[:jl]=true unless from==:jl
|
196
|
+
# @unlock=true
|
197
|
+
# end
|
198
|
+
# end
|
199
|
+
|
200
|
+
# # to is :jl or :r (:rb is always up to date)
|
201
|
+
# def sync_to(to=:r)
|
202
|
+
# if @unlock and @to_update[to]
|
203
|
+
# @unlock=nil #to avoid the same update several times
|
204
|
+
# ## Dyndoc.warn "sync to #{to}",[@ary,@vectors[to].name]
|
205
|
+
# @vectors[to] < @ary
|
206
|
+
# ## Dyndoc.warn "done", [@vectors[to].name,@vectors[to].value]
|
207
|
+
# @to_update[to]=nil
|
208
|
+
# @unlock=true
|
209
|
+
# end
|
210
|
+
# end
|
211
|
+
|
212
|
+
|
213
|
+
def [](key)
|
214
|
+
@ary[key]
|
215
|
+
end
|
216
|
+
|
217
|
+
# when modified from ruby, other languages are updated
|
218
|
+
def []=(key,val)
|
219
|
+
@ary[key]=val #super
|
220
|
+
sync
|
221
|
+
self
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
def replace(ary)
|
226
|
+
@ary.replace ary #super ary
|
227
|
+
sync
|
228
|
+
self
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|