dyndoc-ruby-core 1.0.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.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/dyndoc/.DS_Store +0 -0
  3. data/dyndoc/Dyn/.postload +1 -0
  4. data/dyndoc/Dyn/.preload +1 -0
  5. data/dyndoc/Dyn/After.dyn +3 -0
  6. data/dyndoc/Dyn/Base.dyn +18 -0
  7. data/dyndoc/Dyn/Minimum.dyn +20 -0
  8. data/dyndoc/Model/Html/DefaultPost_html.dyn +5 -0
  9. data/dyndoc/Model/Html/DefaultPre_html.dyn +15 -0
  10. data/dyndoc/Model/Odt/DefaultPost_content.xml +3 -0
  11. data/dyndoc/Model/Odt/DefaultPost_tmpl_content.xml +3 -0
  12. data/dyndoc/Model/Odt/DefaultPre_content.xml +8 -0
  13. data/dyndoc/Model/Odt/DefaultPre_tmpl_content.xml +8 -0
  14. data/dyndoc/Model/Tex/ContentPost_tmpl.tex +1 -0
  15. data/dyndoc/Model/Tex/ContentPre_tmpl.tex +6 -0
  16. data/dyndoc/Model/Tex/DefaultPost_tmpl.tex +73 -0
  17. data/dyndoc/Model/Tex/DefaultPre_tmpl.tex +16 -0
  18. data/dyndoc/Model/Ttm/DefaultPost_tmpl.ttm +3 -0
  19. data/dyndoc/Model/Ttm/DefaultPre_tmpl.ttm +16 -0
  20. data/dyndoc/Std/Array.dyn +96 -0
  21. data/dyndoc/Std/Composer.dyn +38 -0
  22. data/dyndoc/Std/DevTag.dyn +101 -0
  23. data/dyndoc/Std/DynVar.dyn +23 -0
  24. data/dyndoc/Std/File.dyn +55 -0
  25. data/dyndoc/Std/Git.dyn +34 -0
  26. data/dyndoc/Std/List.dyn +46 -0
  27. data/dyndoc/Std/OOP.dyn +32 -0
  28. data/dyndoc/Std/Signal.dyn +18 -0
  29. data/dyndoc/Std/String.dyn +22 -0
  30. data/dyndoc/Std/Styles.dyn +1 -0
  31. data/dyndoc/Std/Test.dyn +282 -0
  32. data/dyndoc/Std/Utils.dyn +42 -0
  33. data/dyndoc/Std/Verb.dyn +5 -0
  34. data/dyndoc/Style/Notation/Math.dyn +7 -0
  35. data/dyndoc/Style/Notation/Stat/Classic.dyn +8 -0
  36. data/dyndoc/Style/Notation/Stat/Cqls.dyn +44 -0
  37. data/dyndoc/Style/Text/Std.dyn +5 -0
  38. data/dyndoc/Style/Text/StdAlias.dyn +3 -0
  39. data/dyndoc/Style/Text/StdTex.dyn +17 -0
  40. data/dyndoc/Style/Text/Txt.dyn +1 -0
  41. data/dyndoc/Tex/.postload +1 -0
  42. data/dyndoc/Tex/.preload +1 -0
  43. data/dyndoc/Tex/10pt_tmpl.tex +1 -0
  44. data/dyndoc/Tex/11pt_tmpl.tex +1 -0
  45. data/dyndoc/Tex/12pt_tmpl.tex +1 -0
  46. data/dyndoc/Tex/Article_tmpl.tex +1 -0
  47. data/dyndoc/Tex/Beamer.dyn_tex +35 -0
  48. data/dyndoc/Tex/BeamerHandout_tmpl.tex +2 -0
  49. data/dyndoc/Tex/Book_tmpl.tex +1 -0
  50. data/dyndoc/Tex/DefaultFirst_tmpl.tex +1 -0
  51. data/dyndoc/Tex/DefaultLast_tmpl.tex +8 -0
  52. data/dyndoc/Tex/Default_tmpl.tex +9 -0
  53. data/dyndoc/Tex/First_tmpl.tex +8 -0
  54. data/dyndoc/Tex/Fr_tmpl.tex +17 -0
  55. data/dyndoc/Tex/Header_tmpl.tex +3 -0
  56. data/dyndoc/Tex/InclGraph_tmpl.tex +19 -0
  57. data/dyndoc/Tex/InclSpatProc_tmpl.tex +70 -0
  58. data/dyndoc/Tex/InclSumMI_tmpl.tex +4 -0
  59. data/dyndoc/Tex/LargeA4_tmpl.tex +5 -0
  60. data/dyndoc/Tex/Last_tmpl.tex +1 -0
  61. data/dyndoc/Tex/Option_tmpl.tex +8 -0
  62. data/dyndoc/Tex/Png_tmpl.tex +1 -0
  63. data/dyndoc/Tex/RefCite2_tmpl.tex +16 -0
  64. data/dyndoc/Tex/RefCite_tmpl.tex +16 -0
  65. data/dyndoc/Tex/Report_tmpl.tex +1 -0
  66. data/dyndoc/Tex/Theorem_tmpl.tex +14 -0
  67. data/dyndoc/Tools/.DS_Store +0 -0
  68. data/dyndoc/Tools/Atom.dyn/index.dyn +42 -0
  69. data/dyndoc/Tools/AtomDyndocker.dyn/index.dyn +43 -0
  70. data/dyndoc/Tools/R/Fig.dyn +144 -0
  71. data/dyndoc/Tools/R/Tools.dyn +344 -0
  72. data/dyndoc/Tools/Tex/Beamer.dyn +204 -0
  73. data/dyndoc/Tools/Tex/BeamerSlide.dyn_tex +199 -0
  74. data/dyndoc/Tools/Tex/Pgf.dyn +115 -0
  75. data/dyndoc/Tools/Tex/Table.dyn +278 -0
  76. data/dyndoc/Tools/Tex/Tools.dyn +37 -0
  77. data/dyndoc/Tools/Tex/Verb.dyn +77 -0
  78. data/dyndoc/Tools/Web/.DS_Store +0 -0
  79. data/dyndoc/Tools/Web/Ace.dyn +54 -0
  80. data/dyndoc/Tools/Web/Code.dyn +129 -0
  81. data/dyndoc/Tools/Web/DHtmlX.dyn +39 -0
  82. data/dyndoc/Tools/Web/DataTable.dyn_html +354 -0
  83. data/dyndoc/Tools/Web/Html.dyn +286 -0
  84. data/dyndoc/Tools/Web/Html/JQuery.dyn +123 -0
  85. data/dyndoc/Tools/Web/Html/Styles.dyn +4 -0
  86. data/dyndoc/Tools/Web/JQueryTools.dyn +87 -0
  87. data/dyndoc/Tools/Web/Layout.dyn +86 -0
  88. data/dyndoc/Tools/Web/Layout/CQLS.dyn +6 -0
  89. data/dyndoc/Tools/Web/Layout/LJK.dyn +41 -0
  90. data/dyndoc/Tools/Web/TabBar.dyn +37 -0
  91. data/dyndoc/Tools/Web/Ttm.dyn +20 -0
  92. data/dyndoc/Tools/Web/Txtl.dyn +14 -0
  93. data/lib/dyndoc-core.rb +59 -0
  94. data/lib/dyndoc/base/envir.rb +541 -0
  95. data/lib/dyndoc/base/filter/call.rb +127 -0
  96. data/lib/dyndoc/base/filter/filter_mngr.rb +637 -0
  97. data/lib/dyndoc/base/filter/server.rb +882 -0
  98. data/lib/dyndoc/base/filters.rb +3 -0
  99. data/lib/dyndoc/base/helpers.rb +9 -0
  100. data/lib/dyndoc/base/helpers/core.rb +32 -0
  101. data/lib/dyndoc/base/helpers/parser.rb +188 -0
  102. data/lib/dyndoc/base/scanner.rb +886 -0
  103. data/lib/dyndoc/base/tags.rb +4 -0
  104. data/lib/dyndoc/base/tags/keys_mngr.rb +401 -0
  105. data/lib/dyndoc/base/tags/part_tag.rb +194 -0
  106. data/lib/dyndoc/base/tags/tag_mngr.rb +125 -0
  107. data/lib/dyndoc/base/tags/user_tag.rb +216 -0
  108. data/lib/dyndoc/base/tmpl.rb +6 -0
  109. data/lib/dyndoc/base/tmpl/eval.rb +581 -0
  110. data/lib/dyndoc/base/tmpl/extension.rb +337 -0
  111. data/lib/dyndoc/base/tmpl/manager.rb +450 -0
  112. data/lib/dyndoc/base/tmpl/oop.rb +57 -0
  113. data/lib/dyndoc/base/tmpl/parse_do.rb +2446 -0
  114. data/lib/dyndoc/base/tmpl/rbenvir.rb +54 -0
  115. data/lib/dyndoc/base/utils.rb +367 -0
  116. data/lib/dyndoc/common/dynArray.rb +234 -0
  117. data/lib/dyndoc/common/file.rb +52 -0
  118. data/lib/dyndoc/common/init.rb +2 -0
  119. data/lib/dyndoc/common/tilt.rb +149 -0
  120. data/lib/dyndoc/common/utils.rb +61 -0
  121. data/lib/dyndoc/common/uv.rb +163 -0
  122. data/lib/dyndoc/init/config.rb +296 -0
  123. data/lib/dyndoc/init/home.rb +9 -0
  124. data/lib/dyndoc/plugins/tex.rb +4 -0
  125. data/lib/dyndoc/plugins/tex/beamer.rb +208 -0
  126. data/lib/dyndoc/plugins/tex/tex_eval.rb +69 -0
  127. data/lib/dyndoc/plugins/tex/tex_parse_do.rb +25 -0
  128. data/lib/dyndoc/plugins/tex/tex_user_tag.rb +32 -0
  129. data/share/R/dyndocMsys2.R +5 -0
  130. data/share/R/dyndocTools.R +9 -0
  131. data/share/R/test.R +14 -0
  132. data/share/R/tools/dynArray.R +34 -0
  133. data/share/R/tools/dynCapture.R +84 -0
  134. data/share/R/tools/dynMsys2.R +54 -0
  135. data/share/julia/dynArray.jl +93 -0
  136. data/share/julia/dyndoc.jl +110 -0
  137. data/share/julia/ruby.jl +37 -0
  138. metadata +202 -0
@@ -0,0 +1,337 @@
1
+ module Dyndoc
2
+
3
+
4
+ module Ruby
5
+
6
+
7
+ #this is an attempt to offer an interface for running on a block tree.
8
+ #usefull for user adding dtag.
9
+ class BlckMngr
10
+
11
+ attr_reader :children, :blck, :tmplMngr, :filter
12
+
13
+ def initialize(tmplMngr,blck,tex,filter)
14
+ @tmplMngr,@blck,@pos=tmplMngr,blck,0
15
+ @tex,@filter=tex,filter
16
+ @children=[] #the blocks
17
+ end
18
+
19
+ def parse_child(filter=@filter)
20
+ @tmplMngr.parse(child,filter)
21
+ end
22
+
23
+ def parse(blck=@blck,filter=@filter)
24
+ ##Dyndoc.warn "parse!!!",blck
25
+ res=@tmplMngr.parse(blck,filter)
26
+ ##Dyndoc.warn "result parse",res
27
+ res
28
+ end
29
+
30
+ def parse!(blck=@blck,filter=@filter)
31
+ self << parse(blck,filter)
32
+ end
33
+
34
+ def <<(content)
35
+ @tex << content
36
+ return self
37
+ end
38
+
39
+ def pos=(i)
40
+ @pos=i
41
+ end
42
+
43
+ def pos
44
+ @pos
45
+ end
46
+
47
+ def length
48
+ @blck.length
49
+ end
50
+
51
+ def at_end?
52
+ @pos == @blck.length-1
53
+ end
54
+
55
+ def next_at_end?
56
+ @pos == @blck.length-2
57
+ end
58
+
59
+ def [](i)
60
+ @blck[i]
61
+ end
62
+
63
+ def tag
64
+ @blck[@pos]
65
+ end
66
+
67
+ def next_tag
68
+ @blck[@pos+1]
69
+ end
70
+
71
+ def next_tag!
72
+ @blck[@pos+=1]
73
+ end
74
+
75
+ def child(i=-1)
76
+ @children[i]
77
+ end
78
+
79
+ def next_child_at(pos)
80
+ b,i=[],pos
81
+ while (i+1<@blck.length and @blck[i+1].is_a? Array)
82
+ i+=1
83
+ b << @blck[i]
84
+ end
85
+ return b
86
+ end
87
+
88
+ def next_child
89
+ b=next_child_at(@pos)
90
+ @gone=nil
91
+ return b
92
+ end
93
+
94
+ def goto_next_child!
95
+ unless @gone
96
+ @pos+=@children[-1].length
97
+ @gone=true #only once!
98
+ end
99
+ end
100
+
101
+ def next_child!
102
+ @children << next_child
103
+ goto_next_child!
104
+ return child
105
+ end
106
+
107
+ def next_child_until(tagset)
108
+ b,i=[],@pos
109
+ #p @blck
110
+ while (i+1<@blck.length and !(tagset.include? @blck[i+1]))
111
+ i += 1
112
+ b << @blck[i]
113
+ end
114
+ @gone=nil
115
+ return b
116
+ end
117
+
118
+ def next_child_until!(tagset)
119
+ @children << next_child_until(tagset)
120
+ goto_next_child!
121
+ return child
122
+ end
123
+
124
+ def next_child_while(tagset)
125
+ b,i=[],@pos
126
+ while (i+1<@blck.length and (tagset.include? @blck[i+1]))
127
+ i+=1
128
+ b << @blck[i]
129
+ end
130
+ @gone=nil
131
+ return b
132
+ end
133
+
134
+ def next_child_while!(tagset)
135
+ @children << next_child_while(tagset)
136
+ goto_next_child!
137
+ return child
138
+ end
139
+
140
+ def child_as_var
141
+ b=@tmplMngr.make_var_block(child.unshift(:var),@filter)
142
+ @tmplMngr.eval_VARS(b,@filter)
143
+ end
144
+
145
+ end
146
+
147
+ class TemplateManager
148
+
149
+ @@newBlcks={}
150
+
151
+ def do_newBlck(tex,b,filter)
152
+ blckMngr=BlckMngr.new(self,b,tex,filter)
153
+ blckname=b[1][1].strip
154
+ ##p blckname
155
+ if ["saved"].include? blckname
156
+ Dyndoc.warn "Warning: Impossible to redefine an existing instruction!"
157
+ end
158
+ #puts "new_blck:b";p b
159
+ blckMngr.pos=1
160
+ items=[]
161
+ return unless [:blck,:aggregate].include? blckMngr.next_tag
162
+ @@newBlcks[blckname]={}
163
+ if blckMngr.next_tag==:aggregate
164
+ blckMngr.next_tag!
165
+ @@newBlcks[blckname][:aggregate]= blckMngr.next_tag![1].strip.split(",")
166
+ end
167
+ while blckMngr.next_tag! == :blck and !blckMngr.at_end?
168
+ items << (item=blckMngr.next_tag![1].strip)
169
+ blcks=[]
170
+ while (blckMngr.next_tag != :blck) and !blckMngr.at_end?
171
+ blcks << blckMngr.next_tag!
172
+ end
173
+ if [":pre",":post"].include? item
174
+ @@newBlcks[blckname][item]=blcks
175
+ else
176
+ i,subBlcks=-1,{}
177
+ while ([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1)
178
+
179
+ subname=blcks[i+=1]
180
+ subBlcks[subname]=[]
181
+ while !([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1)
182
+ subBlcks[subname] << blcks[i+=1]
183
+ end
184
+ end
185
+ @@newBlcks[blckname][item]=subBlcks
186
+ end
187
+
188
+ end
189
+
190
+ ## declare the new block!
191
+ add_dtag({
192
+ :instr=>[blckname],
193
+ :keyword_reg=>{
194
+ blckname.to_sym=> '[%.\w,><?=+:-]+'
195
+ },
196
+ :with_tagblck=>[blckname.to_sym],
197
+ },"blck") #alias of blck!
198
+ #=begin
199
+ (items-[":pre",":post"]).each do |item|
200
+ #p @@newBlcks[blckname][item]
201
+
202
+ if @@newBlcks[blckname][item][:do_code]
203
+ blckRbCode=
204
+ %Q[def do_blck_#{blckname}_#{item}(tex,blck,filter)
205
+ ##Dyndoc.warn :newBlck, blck
206
+ blckMngr=BlckMngr.new(self,blck,tex,filter)
207
+ ## the next code is automatically generated!
208
+ #{@@newBlcks[blckname][item][:do_code][0][1]}
209
+ end]
210
+ #Dyndoc.warn :blckRbCode, blckRbCode
211
+ Dyndoc::Ruby::TemplateManager.module_eval(blckRbCode)
212
+ #Dyndoc.warn :methods, methods.sort
213
+ end
214
+ end
215
+ #=end
216
+ #p methods.sort
217
+ #Dyndoc.warn "newBlck[\"#{blckname}\"]",@@newBlcks[blckname]
218
+ end
219
+
220
+ def blckMode_normal?
221
+ (@@newBlcks.keys & @blckDepth).empty?
222
+ end
223
+
224
+ def aggregate_newBlck(blck,aggrItems,allAggrItems,from)
225
+ res,newBlck=blck[0...from],nil
226
+ ##puts "debut aggr";p res;p aggrItems;p allAggrItems
227
+ resAggr=[] #to save the different elements in the right order
228
+ (from..(blck.length-1)).each do |i|
229
+ if newBlck
230
+ if allAggrItems.include? blck[i]
231
+ if aggrItems.include? blck[i]
232
+ resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]})
233
+ else
234
+ newBlck = nil
235
+ resAggr << blck[i]
236
+ end
237
+ else
238
+ newBlck[:blck] << blck[i]
239
+ end
240
+ else
241
+ if aggrItems.include? blck[i]
242
+ resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]})
243
+ else
244
+ resAggr << blck[i]
245
+ end
246
+ end
247
+ end
248
+
249
+ ## if defaultFmtCotainer defined use it as block starter!
250
+ start=@defaultFmtContainer ? @defaultFmtContainer : :>
251
+ ##puts "start";p start
252
+ #puts "resAggr";p resAggr
253
+ resAggr.each {|e|
254
+ if e.is_a? Hash
255
+ res << e[:tag] << ((e[:blck][1].is_a? Symbol) ? e[:blck] : [:blck,start]+e[:blck][1..-1])
256
+ else
257
+ res << e
258
+ end
259
+ }
260
+ ##puts "result";p res
261
+ res
262
+
263
+ end
264
+
265
+ def completed_newBlck(cmd,blckname,blck,filter)
266
+ ### IMPORTANT: blckname==nil means inside sub-blck :blckAnyTag and then no init performed as :pre and :post preprocess!
267
+ ## As in [#rb>] for (i in 1..3) {#>][#bar]....[#} !!!! No blckname here!
268
+ if blckname
269
+ filter.envir["blckname"]=blckname
270
+ end
271
+ #Dyndoc.warn "completed_newBlck: blck init",[blckname,blck]
272
+ i=(blckname ? 2 : 1)
273
+ ## blckAnyTag behaves like the previous tag in @@newBlcks.keys (all the user-defined commands)
274
+ cmd=@blckDepth.reverse.find{|e| @@newBlcks.keys.include? e} if cmd=="blckAnyTag"
275
+ #Dyndoc.warn "extension",[i,cmd,@@newBlcks[cmd],@blckDepth]
276
+ items=(@@newBlcks[cmd].keys)-[":pre",":post",:aggregate]
277
+ #Dyndoc.warn "completed:items",items
278
+ if @@newBlcks[cmd][:aggregate] #and blckname
279
+ blck=aggregate_newBlck(blck,@@newBlcks[cmd][:aggregate].map{|e| e.to_sym},items.map{|e| e.to_sym},i)
280
+ ##Dyndoc.warn "aggregate",blck
281
+ end
282
+ ## first replace :"," by :"="
283
+ while blck[i]==:","
284
+ blck[i]= :"="
285
+ i+=2
286
+ end
287
+ ## prepend the pre code if it exists!
288
+ ##Dyndoc.warn "blck.length(BEFORE pre)",[blckname,cmd,blck.length,blck]
289
+ if @@newBlcks[cmd][":pre"] and blckname
290
+ blck.insert(i,*(@@newBlcks[cmd][":pre"]))
291
+ i+=@@newBlcks[cmd][":pre"].length
292
+ end
293
+ ##Dyndoc.warn "blck.length",[blck.length,blck]
294
+ while i < blck.length-1
295
+ item=blck[i].to_s
296
+ #Dyndoc.warn "item",[cmd,item]
297
+ if items.include? item
298
+ if @@newBlcks[cmd][item][:pre]
299
+ blck.insert(i,*(@@newBlcks[cmd][item][:pre]))
300
+ i+=@@newBlcks[cmd][item][:pre].length
301
+ end
302
+ if @@newBlcks[cmd][item][:do_code] and blck[i+1].respond_to? "[]" and blck[i+1][0]==:named
303
+ blck.insert(i,blck[i+1])
304
+ blck.insert(i,:"=")
305
+ i+=2
306
+ elsif !@@newBlcks[cmd][item][:do_code]
307
+ blck[i]=(blck[i+1][0]==:named ? :"=" : :">")
308
+ end
309
+ i+=2
310
+ if @@newBlcks[cmd][item][:post]
311
+ #puts "post";p blck[i-1];p blck[i];p blck[i+1];p *(@@newBlcks[cmd][item][:post])
312
+ blck.insert(i,*(@@newBlcks[cmd][item][:post]))
313
+ i+=@@newBlcks[cmd][item][:post].length
314
+ end
315
+ else
316
+ i+=1
317
+ end
318
+ #Dyndoc.warn "completed_newBlck: blck iter",blck
319
+ end
320
+ #Dyndoc.warn "completed_newBlck: blck before end",blck
321
+ ## prepend the pre code if it exists!
322
+ if @@newBlcks[cmd][":post"] and blckname
323
+ blck.insert(i+1,*(@@newBlcks[cmd][":post"]))
324
+ i+=@@newBlcks[cmd][":post"].length
325
+ end
326
+ #p blck
327
+ ## find tag
328
+ #p @@newBlcks[cmd]
329
+ #Dyndoc.warn "completed_newBlck: blck end",blck
330
+ return blck
331
+ end
332
+
333
+ end
334
+
335
+ end
336
+
337
+ end
@@ -0,0 +1,450 @@
1
+ # encoding: UTF-8
2
+
3
+ module Dyndoc
4
+
5
+ @@tmpl_mngr=nil
6
+
7
+ ##need to point to the current TemplateManager
8
+ def Dyndoc.tmpl_mngr
9
+ @@tmpl_mngr
10
+ end
11
+
12
+ def Dyndoc.tmpl_mngr=(tmpl_mngr)
13
+ @@tmpl_mngr = tmpl_mngr
14
+ end
15
+
16
+ ## Make more readable the creation of newBlck
17
+ def Dyndoc.cache(cache_={})
18
+ return Dyndoc.tmpl_mngr.vars[Dyndoc.tmpl_mngr.blckName[-1]] if cache_.empty?
19
+ Dyndoc.tmpl_mngr.vars[Dyndoc.tmpl_mngr.blckName[-1]]=cache_
20
+ end
21
+
22
+ def Dyndoc.extract_var(id)
23
+ Dyndoc.tmpl_mngr.vars.extract(id)
24
+ end
25
+
26
+ module Ruby
27
+
28
+ class TemplateManager
29
+
30
+ attr_accessor :global, :filterGlobal, :filter, :vars, :libs , :tmpl , :blocks, :calls, :args, :envirs, :fmt, :Fmt, :fmtContainer, :fmtOutput, :dyndocMode ,:echo, :filename, :tags, :strip
31
+ attr_accessor :tmpl_cfg, :cfg_tmpl, :cfg, :doc
32
+ attr_accessor :rbEnvir, :rbEnvirs, :rEnvir
33
+ attr_accessor :rbBlock
34
+ attr_reader :scan, :blckName
35
+ ### attr_accessor :mark
36
+
37
+ @@interactive=nil
38
+
39
+ def TemplateManager.interactive
40
+ @@interactive=Dyndoc.cfg_dyn[:dyndoc_session]==:interactive unless @@interactive
41
+ @@interactive
42
+ end
43
+
44
+ # Maybe better located inside server.rb
45
+ def TemplateManager.initR
46
+ first=require "R4rb" #save if it the first initialization!
47
+ Dyndoc.warn "FIRST INIT OF R!!!! => #{first}"
48
+ Array.initR
49
+ TemplateManager.interactive
50
+ #p "client";p Dyndoc.cfg_dyn;p interactive
51
+ R4rb << "rm(list=ls(all=TRUE))" if !first and !@@interactive #remove all initial variables if previous documents session
52
+ R4rb << ".dynStack<-new.env()" #used for R variables used by dyndoc
53
+ RServer.init_envir
54
+ RServer.init_filter
55
+ ## ruby and R init for dynArray stuff
56
+ require "dyndoc/common/dynArray"
57
+ dyndocToolsR = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocTools.R").gsub('\\','/')
58
+ ## WD is introduced by Msys and ConEmuDir by ConEmu
59
+ dyndocToolsRoot = RUBY_PLATFORM =~ /msys/ ? (ENV['WD'] || ENV['ConEmuDir']).split('\\')[0...-2].join(File::Separator) : ""
60
+ R4rb << "source('"+dyndocToolsRoot+dyndocToolsR+"',chdir=TRUE)"
61
+ if RUBY_PLATFORM =~ /msys/
62
+ dyndocMsys2R = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocMsys2.R").gsub('\\','/')
63
+ R4rb << "source('"+dyndocToolsRoot+dyndocMsys2R+"',chdir=TRUE)"
64
+ end
65
+ if RUBY_PLATFORM =~ /mingw/
66
+ require File.join(ENV["DYNDOC_HOME"],"bin","msys2","file_tools.rb")
67
+ end
68
+ end
69
+
70
+ def TemplateManager.initJulia
71
+ first=require "jl4rb" #save if it the first initialization!
72
+ Julia.init
73
+ # init rb4jl stuff
74
+ # since inside ruby, no need Ruby.start and Ruby.stop like in rb4R.
75
+ # sort of equivalent of JLServer.init_filter (but not yet defined)!
76
+ Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+"\")"
77
+ Julia << "include(\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+"\")"
78
+ #-| To debug ruby.jl and dynArray.jl => uncomment below and commnt above
79
+ # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/ruby.jl")+"\")"
80
+ # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/dynArray.jl")+"\")"
81
+ Julia << "using Dyndoc"
82
+ Julia << "Ruby.alive(true)"
83
+ #Julia << "global const _dynArray=DynArray()"
84
+ Dyndoc.warn "Julia initialized inside dyndoc!"
85
+
86
+ end
87
+
88
+ def TemplateManager.attr
89
+ attr={:cmd => @@cmd,:cmdAlias => @@cmdAlias, :argsSep => @@argsSep, :tags => @@tags,:prefix => @@prefix, :tagSearch => @@tagSearch, :tagModifiers => @@tagModifiers}
90
+ attr[:tags_tex],attr[:tex_vars] = @@tags_tex,@@tex_vars if TemplateManager.class_variables.include? "@@tag_tex"
91
+ attr
92
+ end
93
+
94
+ def initialize(tmpl_cfg={},with=true)
95
+ # just in case it is not yet initialized!
96
+ (Dyndoc.cfg_dyn[:langs] << :R).uniq! if with==true
97
+
98
+ #puts "DEBUT INIT TemplateManager"
99
+ @tmpl_cfg=tmpl_cfg
100
+ =begin
101
+ @cfg[:part_tag][0]=@cfg[:part_tag][0][1..-1] if !(@cfg[:part_tag].empty?) and (@partTag_add= (@cfg[:part_tag][0][0,1]=="+"))
102
+ =end
103
+ ## default system root appended
104
+ TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R
105
+ TemplateManager.initJulia if Dyndoc.cfg_dyn[:langs].include? :jl
106
+ rbenvir_init(binding)
107
+ @rEnvir=["Global"]
108
+ @envirs={}
109
+ @fmtContainer=[]
110
+ @echo=1
111
+ @strip=true
112
+ #puts "FIN INIT TemplateManager"
113
+ if Dyndoc.cfg_dyn[:devel_mode]==:test
114
+ puts "DYNDOC SEARCH PATH:"
115
+ puts Dyndoc.get_pathenv(Dyndoc.cfg_dyn[:root_doc]).join(":")
116
+ end
117
+ end
118
+
119
+ ## Make more readable the creation of newBlck
120
+ def cache(cache_={})
121
+ return @vars[blckName[-1]] if cache_.empty?
122
+ @vars[blckName[-1]]=cache_
123
+ end
124
+
125
+ def extract_var(id)
126
+ @vars.extract(id)
127
+ end
128
+
129
+ ## equivalent to :pre_doc for not interactive document
130
+ def require_first
131
+ require_dyndoc_libs("Dyn/Base")
132
+ end
133
+
134
+ def require_dyndoc_libs(libs)
135
+ libs="{#require]\n"+libs.split("\n").map{|lib| lib.split(",")}.flatten.uniq.join("\n")+"\n[#}\n"
136
+ parse(libs,@filterGlobal)
137
+ end
138
+
139
+ ## to set the current tmpl_mngr as the default one accessed via Dyndoc.tmpl_mngr
140
+ ## and used in #R> #rb> block
141
+ def as_default_tmpl_mngr!
142
+ Dyndoc.tmpl_mngr=self unless Dyndoc.tmpl_mngr == self
143
+ end
144
+
145
+ def init_doc(doc_cfg)
146
+ @cfg=doc_cfg
147
+ # register format
148
+ @fmt=@cfg[:format_doc].to_s.downcase
149
+ @Fmt=@fmt.capitalize
150
+ ##Dyndoc.warn "@cfg",@cfg
151
+ @fmtOutput=@cfg[:format_output].to_s if @cfg[:format_output]
152
+ @fmtOutput=@fmt if @fmt and ["html","tex","odt","tm"].include? @fmt
153
+ @dyndocMode=:cmdline
154
+ @global={}
155
+ @filterGlobal=FilterManager.global(self) #global filter needed to affect object before parsing the main document!
156
+ @blocks,@libs,@calls,@args,@meths,@def_blck={},{},{},{},[],[]
157
+ CallFilter.init(self,@calls,@args,@meths)
158
+ @filter=nil
159
+ @tags=[]
160
+ @keys={}
161
+ @alias={}
162
+ @savedBlocks={}
163
+ require_first if @@interactive
164
+ end
165
+
166
+ def format_output=(format)
167
+ @fmtOutput=format
168
+ end
169
+
170
+ def dyndoc_mode=(mode)
171
+ @dyndocMode=mode
172
+ end
173
+
174
+ def reinit
175
+ @blocks,@libs={},{}
176
+ end
177
+
178
+ ## init output
179
+ def init_path(input)
180
+ ##read in the main doc paths to include!
181
+ Dyndoc.setRootDoc(@cfg[:rootDoc],input.scan(/%%%path\((.*)\)/).flatten.map{|e| e.split(",")}.flatten.map{|e| e.strip.downcase}.join(":"))
182
+ p @cfg[:rootDoc] if @cfg[:cmd]==:cfg
183
+ end
184
+
185
+ def init_tags(input)
186
+ ## read the global aliases (config files alias)
187
+ TagManager.global_alias(@alias) # @alias increased
188
+ ## read the local aliases (in the main doc)
189
+ TagManager.local_alias(@alias,input) # @alias increased
190
+ #init @partTag
191
+ @tags=TagManager.init_input_tags(([@fmt]+@cfg[:tag_doc]+@tmpl_cfg[:tag_tmpl]).uniq)
192
+ #p @alias
193
+ #
194
+ Dyndoc.warn "init_tags",@tags
195
+ #To deal later: TagManager.apply_alias(@tags,@alias)
196
+ p [:init_tags, @tags] if @cfg[:cmd]==:cfg
197
+ end
198
+
199
+ def init_keys
200
+ @init_keys=KeysManager.init_keys((@cfg[:keys_doc]+@tmpl_cfg[:keys_tmpl]).uniq)
201
+ #puts "Manager:init_keys";p @init_keys
202
+ end
203
+
204
+
205
+ def init_model(input)
206
+ @pre_doc,@post_doc,@pre_model,@post_model=[],[],[],[]
207
+ if @cfg[:model_doc] and Dyndoc.cfg_dir[:tmpl_path][@cfg[:format_doc]]
208
+ @cfg[:model_doc]="Default" if @cfg[:model_doc].downcase=="default"
209
+ model_doc=File.join("Model",Dyndoc.cfg_dir[:tmpl_path][ @cfg[:format_doc]],@cfg[:model_doc])
210
+ @pre_model << File.read(Dyndoc.doc_filename(model_doc+"Pre"))
211
+ @post_model = [File.read(Dyndoc.doc_filename(model_doc+"Post"))]
212
+ #p @pre_model
213
+ #p @post_model
214
+ end
215
+
216
+ ## sort with respect to priority number and filter
217
+ @cfg[:pre_doc] += input.scan(/\[\#(?:plugin|preload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten
218
+ #p @cfg[:pre_doc]
219
+ input.gsub!(/\[\#(?:plugin|preload)\][^\[]*/m,"")
220
+ @cfg[:pre_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten!
221
+ ## sort with respect to priority number and filter
222
+ @cfg[:post_doc] += input.scan(/\[\#(?:postload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten
223
+ input.gsub!(/\[\#(?:postload)\][^\[]*/m,"")
224
+ @cfg[:post_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten!
225
+
226
+ #p @cfg[:pre_doc]
227
+ if @cfg[:pre_doc]
228
+ @cfg[:pre_doc].uniq.each{|t|
229
+ @pre_doc << File.read(Dyndoc.doc_filename(t))
230
+ }
231
+ end
232
+ #p @pre_doc
233
+
234
+ if @cfg[:post_doc]
235
+ @cfg[:post_doc].uniq.each{|t|
236
+ @post_doc << File.read(Dyndoc.doc_filename(t))
237
+ }
238
+ end
239
+
240
+ end
241
+
242
+ def output_pre_model
243
+ #pre_doc
244
+ out_pre=""
245
+ unless @pre_model.empty?
246
+ pre_model=@pre_model.join("\n") + "\n"
247
+ txt= pre_model
248
+ out_pre << parse(txt)
249
+ end
250
+ unless @pre_doc.empty?
251
+ pre_doc=@pre_doc.join("\n") + "\n"
252
+ txt= pre_doc
253
+ parse(txt,@filterGlobal) ##Style declares objects before compiling the document! Object are created in the global envir!
254
+ end
255
+ ##p [:out_pre,out_pre]
256
+ return out_pre
257
+ end
258
+ =begin
259
+ input = pre_doc.join("\n") + "\n" + input unless pre_doc.empty?
260
+ input = input + "\n" + post_doc.join("\n") unless post_doc.empty?
261
+ return input
262
+ =end
263
+
264
+ def output_post_model
265
+ #post_doc
266
+ out_post=""
267
+ #puts "output_post_model:post doc";p @post_doc
268
+ unless @post_doc.empty?
269
+ post_doc="\n"+@post_doc.join("\n")
270
+ txt= post_doc
271
+ parse(txt)
272
+ end
273
+ unless @post_model.empty?
274
+ post_model="\n"+@post_model.join("\n")
275
+ txt= post_model
276
+ out_post << parse(txt)
277
+ end
278
+ #p [:out_post,out_post]
279
+ return out_post
280
+ end
281
+
282
+
283
+ ## TO REMOVE????
284
+ def init_dtag(tmpl)
285
+ dtag=tmpl.scan(/(?:#{@cfg[:dtags].map{|e| "_#{e}_" }.join("|")})/)[0]
286
+ #p dtag
287
+ return @dtag=(dtag ? dtag[1...-1].to_sym : @cfg[:dtag])
288
+ end
289
+
290
+ def prepare_output(txt)
291
+ ## parse the content txt
292
+ out=output_pre_model
293
+ #p out
294
+ #p Dyndoc.dyn_block[:first]
295
+ ## dyn_block[:first] called in preloaded libraries!
296
+ out << parse(Dyndoc.dyn_block[:first]) if Dyndoc.dyn_block[:first]
297
+ #puts "prepare_output";p out
298
+ out << parse(txt)
299
+ #puts "prepare_output";p out
300
+ ## dyn_block[:last] (for example, used to record some information)
301
+ out << parse(Dyndoc.dyn_block[:last]) if Dyndoc.dyn_block[:last]
302
+ out << output_post_model
303
+ ## escape=true at the end in order to transform undefined variables in Latex!!!
304
+ ##puts "prepare output: BEFORE apply";puts out
305
+ out=@filter.apply(out,:post,false,true) if [:tex,:odt,:ttm,:html].include? @cfg[:format_doc]
306
+ ##p [:prepare_output, out]
307
+ #escape accolade!
308
+ Utils.escape!(out,CHARS_SET_LAST)
309
+ ##puts "prepare output: AFTER Utils.escape!";puts out
310
+ out=Utils.unprotect_format_blocktext(out)
311
+ ##p [:prepare_output, out]
312
+ return out
313
+ end
314
+
315
+ ##only once!!! Not like prepare_output which is called in {#dyn]pre:
316
+ def prepare_last_output(out)
317
+ #puts "DYNDOC_RAW_TEXT! BEFORE";p out
318
+ #p Utils.dyndoc_raw_text
319
+ Utils.dyndoc_raw_text!(out,:clean=>true)
320
+ #puts "DYNDOC_RAW_TEXT! AFTER";p out
321
+ return out
322
+ end
323
+
324
+ def clean_as_is(out)
325
+ out.gsub!(Dyndoc::AS_IS,"")
326
+ end
327
+
328
+ def prepare_user_input
329
+ ##puts "input";p @cfg[:input];p Dyndoc.cfg_dyn[:user_input]
330
+ if @cfg[:input]
331
+ @global["_"]={} unless @global["_"]
332
+ @cfg[:input].each{|k,v|
333
+ @global["_"][k.to_s] = {:val=>[v]}
334
+ }
335
+ end
336
+ if Dyndoc.cfg_dyn[:user_input]
337
+ @global["_"]={} unless @global["_"]
338
+ Dyndoc.cfg_dyn[:user_input].each{|k,v|
339
+ @global["_"][k.to_s] = {:val=>[v]}
340
+ }
341
+ end
342
+ end
343
+
344
+ ## output the result after parsing txt
345
+ def output(input,fromfile=nil)
346
+ @filename=@tmpl_cfg[:filename_tmpl]
347
+ input=Dyndoc.input_from_file(@filename=input) if fromfile
348
+ input=@tmpl_cfg[:lib_dyn_content]+"[#main][#>]"+input unless @tmpl_cfg[:lib_dyn_content].empty?
349
+ ## fetch the contents of all saved variables! This fasten the compilation!
350
+ Utils.saved_content_fetch_variables_from_file(@filename,self)
351
+
352
+ #p @filename
353
+ init_path(input)
354
+ init_tags(input)
355
+ init_keys
356
+ init_model(input)
357
+ #p input
358
+ ## add the tag document in order to replace the user tag preamble and etc. Introduction of styles because of the odt format and the new convention in general to use styles even in latex.
359
+ #txt="{#document][#content]"+input+"[#}"
360
+ txt=input
361
+ #p txt
362
+ prepare_user_input
363
+ ## parse the content txt
364
+ out=prepare_output(txt)
365
+ prepare_last_output(out)
366
+ clean_as_is(out)
367
+ ##p [:output,out]
368
+ return out
369
+ end
370
+
371
+ =begin
372
+ ## DONE: put in Document class
373
+ ## writing in final file
374
+ def write(file)
375
+ #@cfg[:append]="" unless @cfg[:append]
376
+ out = output(file,true)
377
+ #puts out
378
+ f=File.open(@cfg[:filename_doc],"w")
379
+ f << out
380
+ f.close
381
+ end
382
+ =end
383
+
384
+ def query_library(libname)
385
+ init_doc({:format_doc=>:tex})
386
+ parse(Dyndoc.input_from_file(libname))
387
+ p @calls.keys.sort
388
+ p @meths.sort
389
+ end
390
+
391
+ end
392
+
393
+ end
394
+ end
395
+
396
+ # String helpers ######################
397
+
398
+ class String
399
+
400
+ def to_keys
401
+ Dyndoc::Envir.to_keys(self)
402
+ end
403
+
404
+ def to_dyn
405
+ if Dyndoc.tmpl_mngr
406
+ return Dyndoc.tmpl_mngr.parse_string(self)
407
+ else
408
+ return self
409
+ end
410
+ end
411
+
412
+ def to_var
413
+ if Dyndoc.tmpl_mngr and (res=Dyndoc.tmpl_mngr.vars.extract(self))
414
+ res
415
+ else
416
+ self
417
+ end
418
+ end
419
+
420
+ def to_var=(val)
421
+ if Dyndoc.tmpl_mngr
422
+ Dyndoc.tmpl_mngr.vars[self]=val
423
+ end
424
+ end
425
+
426
+ end
427
+
428
+ # Symbol helpers ##################################
429
+
430
+ class Symbol
431
+
432
+ def to_keys
433
+ to_s.to_keys
434
+ end
435
+
436
+ def to_var
437
+ if Dyndoc.tmpl_mngr and (res=Dyndoc.tmpl_mngr.vars.extract(self.to_s))
438
+ res
439
+ else
440
+ self
441
+ end
442
+ end
443
+
444
+ def to_var=(val)
445
+ if Dyndoc.tmpl_mngr
446
+ Dyndoc.tmpl_mngr.vars[self.to_s]=val
447
+ end
448
+ end
449
+
450
+ end