class Dyndoc::Ruby::TemplateManager
Attributes
Public Class Methods
# File lib/dyndoc/base/tmpl/manager.rb, line 108 def TemplateManager.attr attr={:cmd => @@cmd,:cmdAlias => @@cmdAlias, :argsSep => @@argsSep, :tags => @@tags,:prefix => @@prefix, :tagSearch => @@tagSearch, :tagModifiers => @@tagModifiers} attr[:tags_tex],attr[:tex_vars] = @@tags_tex,@@tex_vars if TemplateManager.class_variables.include? "@@tag_tex" attr end
# File lib/dyndoc/base/tmpl/manager.rb, line 83 def TemplateManager.initJulia Dyndoc.logger.info "initJulia: first" first=require "jl4rb" #save if it the first initialization! Dyndoc.logger.info "initJulia: require" Julia.init Dyndoc.logger.info "initJulia: init" # init rb4jl stuff # since inside ruby, no need Ruby.start and Ruby.stop like in rb4R. # sort of equivalent of JLServer.init_filter (but not yet defined)! #Julia << "Base.include(@__MODULE__,\"ruby.jl\")" Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","ruby.jl")+ "\")" Dyndoc.logger.info "initJulia: ruby.jl" Julia << "Base.include(@__MODULE__,\""+File.join(Dyndoc.cfg_dir[:gem_path],"share","julia","dynArray.jl")+ "\")" Dyndoc.logger.info "initJulia: dynArray.jl" #-| To debug ruby.jl and dynArray.jl => uncomment below and commnt above # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/ruby.jl")+"\")" # Julia << "include(\""+File.expand_path("~/Github/dyndoc/share/julia/dynArray.jl")+"\")" Julia << "using Main.Dyndoc" Dyndoc.logger.info "initJulia: using Dyndoc" Julia << "Dyndoc.Ruby.alive(true)" #Julia << "global const _dynArray=DynArray()" Dyndoc.logger.info "Julia initialized inside dyndoc!" end
Maybe better located inside server.rb
# File lib/dyndoc/base/tmpl/manager.rb, line 45 def TemplateManager.initR ## THIS IS JUST IMPOSSIBLE SINCE RUBY USES HOME TO EXPAND PATH ## NEEDS TO FIND AN ALTERNATIVE SOLUTION: R_LIBS_USER # For windows! R now change HOME variable by appending "/Documents" at the end. Ruby does not do that! if RUBY_PLATFORM =~ /mingw/ and !(File.exist? File.join(ENV["HOME"],"R","win-library")) and (File.exist? File.join(ENV["HOME"],"Documents","R","win-library")) ##ENV["HOME"] += "/Documents" if ENV["R_LIBS_USER"] puts "Warning (dyndoc): R_LIBS_USER already in use by dyndoc. Fix that by calling inside dyndoc .libPaths(\"#{ENV['R_LIBS_USER']}\")" end ENV["R_LIBS_USER"]=Dir[File.join(ENV["HOME"],"Documents","R","win-library","*")][-1] ## RMK: if R_LIBS_USER already exist then the second solution end first=require "R4rb" #save if it the first initialization! Dyndoc.warn "FIRST INIT OF R!!!! => #{first}" Array.initR TemplateManager.interactive #p "client";p Dyndoc.cfg_dyn;p interactive R4rb << "rm(list=ls(all=TRUE))" if !first and !@@interactive #remove all initial variables if previous documents session R4rb << ".dynStack<-new.env()" #used for R variables used by dyndoc RServer.init_envir RServer.init_filter ## ruby and R init for dynArray stuff require "dyndoc/common/dynArray" dyndocToolsR = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocTools.R").gsub('\\','/') ## WD is introduced by Msys and ConEmuDir by ConEmu dyndocToolsRoot = RUBY_PLATFORM =~ /msys/ ? (ENV['WD'] || ENV['ConEmuDir']).split('\\')[0...-2].join(File::Separator) : "" R4rb << "source('"+dyndocToolsRoot+dyndocToolsR+"',chdir=TRUE)" if RUBY_PLATFORM =~ /msys/ dyndocMsys2R = File.join(Dyndoc.cfg_dir[:gem_path],"share","R","dyndocMsys2.R").gsub('\\','/') R4rb << "source('"+dyndocToolsRoot+dyndocMsys2R+"',chdir=TRUE)" end if RUBY_PLATFORM =~ /mingw/ require File.join(ENV["DYNDOC_HOME"],"bin","msys2","file_tools.rb") if ENV["DYNDOC_HOME"] end Dyndoc.logger.info "R initialized inside dyndoc!" end
# File lib/dyndoc/base/tmpl/manager.rb, line 39 def TemplateManager.interactive @@interactive=Dyndoc.cfg_dyn[:dyndoc_session]==:interactive unless @@interactive @@interactive end
# File lib/dyndoc/base/tmpl/manager.rb, line 114 def initialize(tmpl_cfg={},with=true) # just in case it is not yet initialized! (Dyndoc.cfg_dyn[:langs] << :R).uniq! if with==true #puts "DEBUT INIT TemplateManager" @tmpl_cfg=tmpl_cfg =begin @cfg[:part_tag][0]=@cfg[:part_tag][0][1..-1] if !(@cfg[:part_tag].empty?) and (@partTag_add= (@cfg[:part_tag][0][0,1]=="+")) =end ## default system root appended unless Dyndoc.cfg_dyn[:ruby_only] TemplateManager.initR if Dyndoc.cfg_dyn[:langs].include? :R TemplateManager.initJulia if Dyndoc.cfg_dyn[:langs].include? :jl end rbenvir_init(binding) @rEnvir=["Global"] @envirs={} @fmtContainer=[] @echo=1 @strip=true #puts "FIN INIT TemplateManager" if Dyndoc.cfg_dyn[:devel_mode]==:test puts "DYNDOC SEARCH PATH:" puts Dyndoc.get_pathenv(Dyndoc.cfg_dyn[:root_doc]).join(":") end end
Public Instance Methods
# File lib/dyndoc/base/tmpl/parse_do.rb, line 38 def add_dtag(dtag,cmdAlias=nil) @scan=DevTagScanner.new(:dtag) unless @scan if dtag @scan.merge_tag(dtag) @@cmd += dtag[:instr] end if cmdAlias @@cmdAlias[dtag[:instr][0]]=cmdAlias end #p @@cmd;p @@cmdAlias end
# File lib/dyndoc/base/tmpl/extension.rb, line 224 def aggregate_newBlck(blck,aggrItems,allAggrItems,from) res,newBlck=blck[0...from],nil ##puts "debut aggr";p res;p aggrItems;p allAggrItems resAggr=[] #to save the different elements in the right order (from..(blck.length-1)).each do |i| if newBlck if allAggrItems.include? blck[i] if aggrItems.include? blck[i] resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]}) else newBlck = nil resAggr << blck[i] end else newBlck[:blck] << blck[i] end else if aggrItems.include? blck[i] resAggr << (newBlck={:tag=>blck[i],:blck=>[:blck]}) else resAggr << blck[i] end end end ## if defaultFmtCotainer defined use it as block starter! start=@defaultFmtContainer ? @defaultFmtContainer : :> ##puts "start";p start #puts "resAggr";p resAggr resAggr.each {|e| if e.is_a? Hash res << e[:tag] << ((e[:blck][1].is_a? Symbol) ? e[:blck] : [:blck,start]+e[:blck][1..-1]) else res << e end } ##puts "result";p res res end
# File lib/dyndoc/plugins/tex/tex_eval.rb, line 59 def append_to_begin_document(filter,content) ## _BEGINDOC_ already declared in DefaultPre_tmpl.tex if filter.envir.global["_BEGINDOC_"] filter.envir.global["_BEGINDOC_"][:val][0] << "\n" unless filter.envir.global["_BEGINDOC_"][:val][0].empty? filter.envir.global["_BEGINDOC_"][:val][0] << content end end
to set the current tmpl_mngr as the default one accessed via Dyndoc.tmpl_mngr
and used in R> rb> block
# File lib/dyndoc/base/tmpl/manager.rb, line 166 def as_default_tmpl_mngr! Dyndoc.tmpl_mngr=self unless Dyndoc.tmpl_mngr == self end
# File lib/dyndoc/base/tmpl/extension.rb, line 220 def blckMode_normal? (@@newBlcks.keys & @blckDepth).empty? end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 320 def blockFormat @fmtContainer[0] ? (@fmtContainer[0].to_s)[0...-1] : nil end
Make more readable the creation of newBlck
# File lib/dyndoc/base/tmpl/manager.rb, line 142 def cache(cache_={}) return @vars[blckName[-1]] if cache_.empty? @vars[blckName[-1]]=cache_ end
# File lib/dyndoc/base/tmpl/manager.rb, line 349 def clean_as_is(out) out.gsub!(Dyndoc::AS_IS,"") end
# File lib/dyndoc/base/tmpl/extension.rb, line 265 def completed_newBlck(cmd,blckname,blck,filter) ### IMPORTANT: blckname==nil means inside sub-blck :blckAnyTag and then no init performed as :pre and :post preprocess! ## As in [#rb>] for (i in 1..3) {#>][#bar]....[#} !!!! No blckname here! if blckname filter.envir["blckname"]=blckname end #Dyndoc.warn "completed_newBlck: blck init",[blckname,blck] i=(blckname ? 2 : 1) ## blckAnyTag behaves like the previous tag in @@newBlcks.keys (all the user-defined commands) cmd=@blckDepth.reverse.find{|e| @@newBlcks.keys.include? e} if cmd=="blckAnyTag" #Dyndoc.warn "extension",[i,cmd,@@newBlcks[cmd],@blckDepth] items=(@@newBlcks[cmd].keys)-[":pre",":post",:aggregate] #Dyndoc.warn "completed:items",items if @@newBlcks[cmd][:aggregate] #and blckname blck=aggregate_newBlck(blck,@@newBlcks[cmd][:aggregate].map{|e| e.to_sym},items.map{|e| e.to_sym},i) ##Dyndoc.warn "aggregate",blck end ## first replace :"," by :"=" while blck[i]==:"," blck[i]= :"=" i+=2 end ## prepend the pre code if it exists! ##Dyndoc.warn "blck.length(BEFORE pre)",[blckname,cmd,blck.length,blck] if @@newBlcks[cmd][":pre"] and blckname blck.insert(i,*(@@newBlcks[cmd][":pre"])) i+=@@newBlcks[cmd][":pre"].length end ##Dyndoc.warn "blck.length",[blck.length,blck] while i < blck.length-1 item=blck[i].to_s #Dyndoc.warn "item",[cmd,item] if items.include? item if @@newBlcks[cmd][item][:pre] blck.insert(i,*(@@newBlcks[cmd][item][:pre])) i+=@@newBlcks[cmd][item][:pre].length end if @@newBlcks[cmd][item][:do_code] and blck[i+1].respond_to? "[]" and blck[i+1][0]==:named blck.insert(i,blck[i+1]) blck.insert(i,:"=") i+=2 elsif !@@newBlcks[cmd][item][:do_code] blck[i]=(blck[i+1][0]==:named ? :"=" : :">") end i+=2 if @@newBlcks[cmd][item][:post] #puts "post";p blck[i-1];p blck[i];p blck[i+1];p *(@@newBlcks[cmd][item][:post]) blck.insert(i,*(@@newBlcks[cmd][item][:post])) i+=@@newBlcks[cmd][item][:post].length end else i+=1 end #Dyndoc.warn "completed_newBlck: blck iter",blck end #Dyndoc.warn "completed_newBlck: blck before end",blck ## prepend the pre code if it exists! if @@newBlcks[cmd][":post"] and blckname blck.insert(i+1,*(@@newBlcks[cmd][":post"])) i+=@@newBlcks[cmd][":post"].length end #p blck ## find tag #p @@newBlcks[cmd] #Dyndoc.warn "completed_newBlck: blck end",blck return blck end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 316 def currentFormat (@curFmtContainer.to_s)[0...-1] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 312 def defaultFormat (@defaultFmtContainer.to_s)[0...-1] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2096 def do_R(tex,blck,filter) ## rBlock stuff # Dyndoc.warn "do_R",blck dynBlock=dynBlock_in_doLangBlock?(blck) if dynBlock @doLangBlock=[] unless @doLangBlock @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} rBlockId=@doLangBlock.length-1 end ## this is R code! filter.outType=":r" ## Dyndoc.warn "do_R",filter.envir.local blck=make_do_lang_blck(blck,rBlockId,:R) #true at the end is for R! ## Dyndoc.warn "do_R",blck code = parse_args(blck,filter) ## Dyndoc.warn "R code="+code process_r(code) ## Dyndoc.warn "R CODE="+code if blck[0]==:"R>" ## Dyndoc.warn "R>",code as_default_tmpl_mngr! tex2=eval_RCODE(code,filter,:blockR => true) ## Dyndoc.warn "RRRRRRRRRRRRRRRR: tex2",tex2 tex << tex2 else # pretty is put to false because prettyNum does not accept empty output or something like that! eval_RCODE(code,filter,:pretty=> false) end ## revert all the stuff if dynBlock @doLangBlockEnvs -= @doLangBlock[rBlockId][:env] #first remove useless envRs @doLangBlock.pop end filter.outType=nil ## Dyndoc.warn "SORTIE R!",dynBlock,blck,tex2 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 329 def do_blck(tex,blck,filter) #begin puts "do_blck";p @curCmd;p blck; end if @curCmd=="blck" i=0 #blck[0]==:blck #New mode (071108): save and restore named block! curCmd,blckname=@curCmd,nil if blck[1].is_a? Array ## Fix blckAnyTag when starting with text => add :> if blck[0] == :blckAnyTag and blck[1][0]==:main blck.insert(1,:>) else blckname=parse([blck[1]],filter).strip end end ##Dyndoc.warn :blckname,[blckname,blck] if curCmd=="saved" #################################################################### ## TODO: all the stuff generated has to be saved! ## tex records all the generated content but what about the files! ## Maybe, keep tracks of all files generated! By default put it inside inside .dyn_out directory ## but also records which files have been generated in the saved mode! #################################################################### #blckname=parse([blck[1]],filter).strip ##puts "blckname";p blckname return if blckname.empty? unless blck[2] #p Utils.dyndoc_raw_var_ls #p blckname if Utils.dyndoc_raw_var_ls.include? blckname tex << Utils.dyndoc_raw_var_content(blckname,self) end else ## fetch the result from the saved result if it exists or force regeneration at the command line! res=Utils.saved_content_get(blckname,self,true) #true here is very important since input user is checked first to know if content needs to be regenerated! #puts "direct:res";p res unless res res=parse([blck[2..-1].unshift(:blck)],filter) #puts "created:res";p res ## saved_contents_file does not not contain this block! Utils.saved_content_add_as_variable(blckname,res,@filename) end tex << res ## stop here! end else #curCmd=="blck" @blckDepth ||= [] @blckDepth << curCmd #puts "blckDepth";p @blckDepth;p @@newBlcks.keys if !(cmdBlcks=@@newBlcks.keys & @blckDepth).empty? #puts "cmdBlcks";p cmdBlcks #puts "blckDepth";p @blckDepth #p blck @newBlckMode=true (["blckAnyTag"]+cmdBlcks).each do |cmd| #Dyndoc.warn "cmd",[cmd.to_sym,blck[0]] if blck[0]==cmd.to_sym # Fix bug when calling newBlck with no space at the beginning # blckname==nil only for blckAnyTag if !blckname and cmd!="blckAnyTag" blckname="" blck=blck[0,1]+[[:main,""]]+blck[1..-1] end #Dyndoc.warn "BEFORE COMPLETED_BLCK",[cmd,blckname,blck] blck=completed_newBlck(cmd,blckname,blck,filter) #Dyndoc.warn "AFTER COMPLETED_BLCK",blck end end elsif blck[1].is_a? Array #blckname=parse([blck[1]],filter).strip to_end=!blckname.empty? if blck[2] and to_end mode,to_exec=:normal,nil if ["+",">","$"].include? blckname[0,1] mode,blckname = :append,blckname[1..-1].strip elsif ["^","<"].include? blckname[0,1] mode,blckname = :prepend,blckname[1..-1].strip end to_exec,blckname=true,blckname[0...-1] if blckname[-1,1]=="!" #Dyndoc.warn "to_exec",[to_exec,blckname] @savedBlocks[blckname]= ( mode==:normal ? blck[2..-1].unshift(:blck) : ( mode==:append ? @savedBlocks[blckname]+blck[2..-1] : (blck[2..-1]+@savedBlocks[blckname][1..-1]).unshift(:blck) ) ) tex << parse([@savedBlocks[blckname]],filter) if to_exec elsif to_end #p @savedBlocks[blckname] #puts "blck #{blckname}" tex << parse([@savedBlocks[blckname]],filter) if @savedBlocks[blckname] end #p to_stop;p blck return if to_end end # normal (old) mode cond,cond_tag=true,true condArch=[] #p blck if curCmd=="tabbar" if @@newBlcks.keys.include? @blckDepth[-1] @blckName ||= [] tmp=blck[1][1].strip @blckName << (tmp.empty? ? SecureRandom.uuid.strip : tmp) #puts "blckNAME";p @blckName end begin case (current_block_tag=blck[i+=1]) when :"%" i,*b2=next_block(blck,i) when :"?" i,*b2=next_block(blck,i) if cond_tag filter.outType=":rb" ##Dyndoc.warn "do_block:?:b2",b2 code=parse_args(b2[0],filter).strip #puts "do_block:?:code"; p code mode=code.downcase #puts "do_block:?:mode";p mode if ["!","else"].include? mode cond = !cond elsif ["*","all","end"].include? mode cond,condArch=true,[] elsif mode=~/^prev/ nbPop=mode.scan(/ \d*$/) nbPop=(nbPop.empty? ? 1 : nbPop[0].to_i) nbPop.times{cond=condArch.pop} else mode,code=code[0,1],code[1..-1] if ["&","|"].include? code[0,1] cond2=@rbEnvir[0].eval(code) condArch << cond if mode=="&" cond= cond & cond2 elsif mode=="|" cond= cond | cond2 else cond=cond2 end end filter.outType=nil end #puts "cond in block #{code}=";p cond when :tag,:"??" ## Dyndoc.warn "tag:blck",blck i,*b2=next_block(blck,i) ## Dyndoc.warn "tag:b2",b2 code=parse(b2,filter).strip.downcase ## Dyndoc.warn "tag",code if ["!","else"].include? code cond_tag = !cond_tag elsif ["*","all","end"].include? code cond_tag=true else mode=nil mode,code=code[0,1],code[1..-1] if ["&","|","-"].include? code[0,1] ## Dyndoc.warn "mode and code",[mode,code] tags=TagManager.make_tags(code) ## Dyndoc.warn "tags, @tags",[tags,@tags] cond2_tag=TagManager.tags_ok?(tags,@tags) #puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag if mode=="&" #puts "tags, @tags";p tags;p @tags #puts "mode, cond_tag et cond2_tag";p mode; p cond_tag;p cond2_tag; p cond_tag.class;p cond2_tag.class;p cond_tag and cond2_tag #RMK: a=0 and nil => a=0 because a stays to be a FixNum. cond_tag= (cond_tag and cond2_tag ? 0 : nil) #puts "INTER cond_tag->";p cond_tag elsif mode=="|" cond_tag = (cond_tag or cond2_tag ? 0 : nil) elsif mode=="-" cond_tag = !cond2_tag else cond_tag = cond2_tag end #puts "FINAL cond_tag->";p cond_tag end #puts "cond_tag in block #{code}=";p cond_tag when :do,:< i,*b2=next_block(blck,i) parse(b2,filter) if cond_tag and cond when :"r<",:"rb<",:"R<",:"m<",:"M<",:"jl<",:"sh<" # if current_block_tag==:"jl<" # ##p "iciiiii" # end newblck=blck[i] #puts "newblock";p newblck;p blck i,*b2=next_block(blck,i) #p b2 code=b2[0][1..-1] ##p code #need to be cleaned with no bracket at the beginning and the end of the block! clean_block_without_bracket(code) if cond_tag and cond b2=[code.unshift(newblck)] ##puts "r<;rb<";p b2 filter.outType=":"+(blck[i].to_s)[0...-1] #Dyndoc.warn "rb,jl,R block",filter.outType parse(b2,filter) filter.outType=nil end #equivalent of :var but DO NOT USE :var when :"=",:"tex=",:"md=",:"adoc=",:"txtl=",:"html=",:"rb=",:"R=",:"jl=" i,*b2=next_block(blck,i) if cond_tag and cond #puts "=:b2";p b2 b=make_var_block(b2.unshift(:var),filter) #puts "=:b";p b eval_VARS(b,filter) end when :"-" i,*b2=next_block(blck,i) if cond_tag and cond #puts "-:b2" parse(b2,filter).strip.split(",").each{|key| @vars.remove(key)} end when :+,:"tex+",:"md+",:"adoc+",:"txtl+",:"html+",:"rb+",:"R+",:"jl+" ##Dyndoc.warn "+:-1:block",[i,blck] i,*b2=next_block(blck,i) ##Dyndoc.warn "+:0:i,b2",[i,b2] if cond_tag and cond var,pos=b2[0][1].split(",") ## Dyndoc.warn "+:1:var,pos",[var,pos] pos = -1 unless pos pos=pos.to_i var=filter.apply(var) varObj=@vars.extract_raw(var) ## Dyndoc.warn "+:2:var",[var,varObj,(varObj.is_a? Array)] if varObj if varObj.is_a? Array pos=varObj.length+pos+1 if pos<0 varNew=var+".#{pos}" #new element ## Needs to deep dup (dup is not enough!) b2dup=Marshal.load( Marshal.dump(b2) ) b2dup[0][1]="::ADDED_ELT" ## Dyndoc.warn "+:3:b2,b2dup,blck",[b2,b2dup,blck] b=make_var_block(b2dup.unshift(:var),filter) ## Dyndoc.warn "b",b eval_VARS(b,filter) type=@vars.extract_raw("::ADDED_ELT").class res={:val=>[""]} res=[] if type==Array res={} if type==Hash varObj.insert(pos,res) ## Dyndoc.warn "varObj",[varObj,b2] b2dup[1][1]=varNew b=make_var_block(b2dup,filter) ## Dyndoc.warn "+:4:b2,b2dup,blck",[b2,b2dup,blck] eval_VARS(b,filter) elsif varObj.is_a? Hash and varObj[:val] ## Dyndoc.warn "+:else1:blck",blck ## Needs to deep dup (dup is not enough!) b2dup=Marshal.load( Marshal.dump(b2) ) b2dup[0][1]="::ADDED_ELT" ## Dyndoc.warn "+:3else:b2",[b2,b2dup] ## Dyndoc.warn "+:else2:blck",blck ## Dyndoc.warn "+:else2:b2.unshift(:var)",b2dup.unshift(:var) b=make_var_block(b2dup.unshift(:var),filter) ## Dyndoc.warn "+:4else:b",b ## Dyndoc.warn "+:else2:blck",blck eval_VARS(b,filter) res=@vars.extract_raw("::ADDED_ELT") varObj[:val][0].insert(pos,res[:val][0]) ## Dyndoc.warn "+:5else:varObj",[varObj,b] end #puts "varNew:#{var}";p @vars.extract_raw(var) end end when :out,:>,:">!" # :>! is in some sense equivalent of :set i,*b2=next_block(blck,i) #puts "block >, cond_tag, cond";p cond_tag ;p cond if cond_tag and cond and !b2.empty? #puts "do_blck:out";p b2 #p blck vars,b2=get_named_blck(b2,filter) #Dyndoc.warn "do_blck:out, >!",[vars,b2] if current_block_tag==:">!" #p b2 #p current_block_tag #p current_block_tag==:">!" make_named_blck(tex,filter,vars,b2,current_block_tag==:">!") if b2 end when :"_<" i,*b2=next_block(blck,i) val=parse(b2,filter).strip @defaultFmtContainer=(val+">").to_sym if ["","html","tex","txtl","ttm","md","adoc"].include? val when :"txtl>",:"ttm>",:"tex>",:"html>",:"_>",:"__>",:"md>",:"adoc>" newblck=blck[i] @curFmtContainer=:"tex>" unless @curFmtContainer if newblck==:"__>" newblck=@curFmtContainer #the previous one elsif newblck==:"_>" newblck=(@defaultFmtContainer ? @defaultFmtContainer : @curFmtContainer) #the default one else @curFmtContainer=nil #to redefine at the end end i,*b2=next_block(blck,i) if cond_tag and cond and !b2.empty? #if b2 empty nothing to do! @fmtContainer.unshift newblck val=parse(b2,filter) if @fmtContainer[1] and @fmtContainer[1]==@fmtContainer[0] #no need to convert! tex << val else #convert ##Dyndoc.warn "txtl formats",[@fmtContainer[0],@fmtOutput,@fmtContainer[1]] ##Dyndoc.warn :val, val tex << Dyndoc::Converter.convert(val,@fmtContainer[0],@fmtOutput,@fmtContainer[1]) #last parameter: true means to protect end @curFmtContainer=@fmtContainer[0] unless @curFmtContainer @fmtContainer.shift end when :"r>",:"rb>",:"R>",:"m>",:"M>",:"jl>" newblck=blck[i] i,*b2=next_block(blck,i) #puts "RB>";p b2;p i;p blck if cond_tag and cond and !b2.empty? #if b2 empty nothing to do! vars,b2=get_named_blck(b2,filter) if b2 b2=[b2.unshift(newblck)] filter.outType=":"+(blck[i].to_s)[0...-1] make_named_blck(tex,filter,vars,b2) filter.outType=nil end end when :"r>>",:"R>>",:rout,:rverb newblck=blck[i] i,*b2=next_block(blck,i) if cond_tag and cond vars,b2=get_named_blck(b2,filter) if b2 b2=[b2.unshift(newblck)] filter.outType=":r" #+(blck[i].to_s)[0...-1] =begin val=parse(b2,filter) #puts "make_named_blck:val";p val val=Utils.format_blocktext(val) #puts "format_blocktext:val";p val if vars vars.split(",").each{|var| eval_SET(var.strip,val,filter) } else tex << val end =end make_named_blck(tex,filter,vars,b2) filter.outType=nil end end when :"jl>>",:jlverb,:"rb>>",:rbverb newblck=blck[i] i,*b2=next_block(blck,i) if cond_tag and cond vars,b2=get_named_blck(b2,filter) if b2 b2=[b2.unshift(newblck)] filter.outType=newblck.to_s[0,2].to_sym #":jl" #+(blck[i].to_s)[0...-1] =begin val=parse(b2,filter) #puts "make_named_blck:val";p val val=Utils.format_blocktext(val) #puts "format_blocktext:val";p val if vars vars.split(",").each{|var| eval_SET(var.strip,val,filter) } else tex << val end =end make_named_blck(tex,filter,vars,b2) filter.outType=nil end end when :>> i,*b2=next_block(blck,i) if cond_tag and cond file,b2=get_named_blck(b2,filter) if b2 and file mode=:save case file[-1,1] when "?" mode=:exist file=file[0...-1] when "!" mode=:nothing file=file[0...-1] end mode=(File.exist?(file) ? :nothing : :save ) if mode==:exist tex2=parse(b2,filter) tex2==Utils.format_blocktext(tex2) if mode==:save File.open(file,"w") do |f| f << tex2 end end end end when :nl,:"\\n" i,*b2=next_block(blck,i) if cond_tag and cond tex << "\n" << parse(b2,filter) #puts "nl";p tex end when :yield #only inside a {#def] block! i,*b2=next_block(blck,i) if cond_tag and cond codename=parse(b2,filter).strip #p codename #p @def_blck make_yield(tex,codename,filter) end when :<< #input without variable entries i,*b2=next_block(blck,i) if cond_tag and cond #p b2 var,b2=get_named_blck(b2,filter) #p var;p b2 tmpl=parse(b2,filter).strip #p tmpl val=eval_INPUT(tmpl,[],filter) if var eval_SET(var.strip,val,filter) else tex << val end end else i,*b2=next_block(blck,i) blckCmd=(current_block_tag.is_a? Symbol) ? ("do_blck_"+curCmd+"_"+current_block_tag.to_s).to_sym : nil #Dyndoc.warn :blckCmd,[current_block_tag,blckCmd,(methods.include? blckCmd),methods.sort] blckCmd=nil if blckCmd and !(methods.include? blckCmd) #Dyndoc.warn :blckCmd2,blckCmd if cond_tag and cond and blckCmd #Dyndoc.warn :blck_command #, [blckCmd,b2] method(blckCmd).call(tex,b2,filter) end end end while i<blck.length-1 @blckName.pop if @blckName and @@newBlcks.keys.include? @blckDepth[-1] @blckDepth.pop @newBlckMode=nil end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1260 def do_call(tex,blck,filter) #Dyndoc.warn "do_call",blck call=parse_args(blck[1],filter) #puts "do_call";p call #p args #this corrects a bad behavior of the scanner when the call directive is called directly. if blck[2]==:"," var_block= blck[3..-1].unshift(:var) else var_block=blck[2..-1].unshift(:var) end #puts "var_block";p var_block var,code=make_call(var_block,filter) #puts "VAR" #p code #Dyndoc.warn "do_call:var",var #p var =begin if @meths.include? call @meth_var=(var[3..-1] ? var[0,1]+var[3..-1] : nil) var=var[0..1] end =end #puts "VAR2";p blck[2..-1].unshift(:var) #puts "var block (AV)";p var #19/10/08: this complete the method name if necessary in order to provide args! Now, meth may be used with partial argument completed in the R spirit! call4args,vars4args=call.dup,[] isMeth=CallFilter.isMeth?(call) ##puts "#{call} isMeth => #{isMeth}!!!" if isMeth #puts "meth:call=#{call}" obj=parse((var[1][0]==:named ? var[1][2..-1] : [var[1]] ),filter) #puts "obj=#{obj}" if @vars.extract(obj) and @vars.extract(obj).respond_to? "keys" #puts "extract obj";p @vars.extract(obj).keys vars4args=(@vars.extract(obj).keys.select{|e| e.is_a? String} - ["Renvir","ObjectName","Class"]).map{|e| "."+e} #obj=parse([blck[2]],filter) #p @vars[obj+".Class"] get_method(call4args,@vars[obj+".Class"].split(",")) if @vars[obj+".Class"] #=> call4args is modified inside get_method!!! end end #puts "call4args=#{call4args}" #p @args[call4args] args=(@args[call4args] ? @args[call4args].dup : nil) args+=vars4args if args #puts "args";p args #TODO: for method, args has to be initialized by finding the class of the object! Pb: how to know that it is a method => make a method in Call??? b=(var.length==1 ? [] : make_var_block(var,filter,args)) #puts "var block (AP)";p b b,meth_args_b=CallFilter.argsMeth(call,b) #puts "call";p call #p @calls[call] #Dyndoc.warn "var2 block",b #p meth_args_b #Dyndoc.warn "call:out",eval_CALL(call,b,filter) tex << eval_CALL(call,b,filter,meth_args_b,code) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1692 def do_case(tex,blck,filter) choices=parse_args(blck[1],filter).strip #puts "choices";p choices #p blck var="__elt_case__" tmp=choices.scan(/(^\w*):(.*)/)[0] var,choices=tmp[0].strip,tmp[1].strip if tmp choices=choices.split(",").map{|e| e.strip} choices.each{|choice| i=1 todo,cond,all=true,false,false begin case blck[i+=1] when :when #puts "when";p blck[i] c=parse_args(blck[i+=1],filter).strip.split(",").map{|e| e.strip} #p "#{choice} in #{c.join(",")}" cond=(c.include? choice) all |= cond when :else cond=!all end i,*b2=next_block(blck,i) @vars[var]=choice tex << parse(b2,filter) if cond #if cond # puts "tex in case";p tex #end end while todo and i<blck.length-1 } #puts "tex in case";p tex end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1134 def do_def(tex,blck,filter) call,code,rbEnvir=make_def(blck,filter) #puts "do_def";p call;p code;p rbEnvir eval_func(call,code,rbEnvir) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 200 def do_do(tex,blck,filter) i=-1 begin case blck[i+=1] when :do,:< i,*b2=next_block(blck,i) parse(b2,filter) when :out,:> i,*b2=next_block(blck,i) tex << parse(b2,filter) when :nl,:"\\n" i,*b2=next_block(blck,i) tex << "\n" << parse(b2,filter) end end while i<blck.length-1 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1488 def do_document(tex,blck,filter) i=0 #puts "document:blck" #p blck begin var,mode="","" to_parse=true #p i;p blck[i+1] case blck[i+=1] ########################## Commands when :main,:content var,mode=nil,:view when :require var,mode=nil,:load when :helpers var,mode,to_parse=nil,:helpers,true when :path var,mode=nil,:path when :first #p blck[i+=1] var,mode,to_parse=nil,:first,false when :last var,mode,to_parse=nil,:last,false when :texinputs ## Latex var,mode,to_parse=nil,:texinputs,true when :optclass ## Latex var,mode,to_parse=nil,:optclass,true ################################ MODEL VARIABLES when :class ## Latex var,mode="_DOCUMENTCLASS_","" when :preamble var,mode="_PREAMBLE_","+" when :postamble var,mode="_POSTAMBLE_","+" when :style var,mode="_STYLEDOC_","+" when :package var,mode="_USEPACKAGE_","+" when :title var,mode="_TITLE_","+" when :before var,mode="_BEGINDOC_","+" when :after var,mode="_ENDDOC_","+" ### specific for HTML! Different from tilt mode! when :js var,mode="_JSDOC_","+" when :css var,mode="_STYLEDOC_","+" when :header var,mode="_HEADER_","+" when :footer var,mode="_FOOTER_","+" when :default var,mode=nil,:default when :cfg var,mode=nil,:cfg end i,*b2=next_block(blck,i) #p b2 res=parse(b2,filter) if to_parse #p var #puts "res";p res unless var case mode when :view tex << res when :default, :cfg ## nothing to do: used in document.rb when :load #puts "document:require";p res eval_LOAD(res.strip.split("\n"),filter) when :helpers eval_LOAD_HELPERS(res.strip.split("\n"),filter) when :path #Dyndoc.warn "document:path",res Dyndoc.user_root_doc=res.strip.split("\n").map{|e| e.strip unless e.strip.empty?}.compact.join(Dyndoc::PATH_SEP) unless res.strip.empty? #### OBSOLETE from 27/09/2016!!! ### TODO: - operation possibly in init/config.rb # unless res.strip.empty? # #p paths # #Dyndoc.warn "root_doc",@tmpl_cfg[:root_doc] # rootpaths=@tmpl_cfg[:root_doc].split(Dyndoc::PATH_SEP) # #Dyndoc.warn "rootpaths",rootpaths # newpaths=[] # paths.each{|e| # #if File.exist?(e) # # newpaths << e # #els # if e[0,1]=="-" and File.exist?(e[1..-1]) # rootpaths.delete(e[1..-1]) # elsif (ind=e.to_i)<0 # rootpaths.delete_at(-ind-1) # else # newpaths << e # end # } # rootpaths=newpaths+rootpaths # #Dyndoc.warn :last, rootpaths # @tmpl_cfg[:root_doc]=rootpaths.join(Dyndoc::PATH_SEP) # end when :first Dyndoc.dyn_block[:first]=[] unless Dyndoc.dyn_block[:first] Dyndoc.dyn_block[:first]+=b2 #Dyndoc "firstblock#{i}",Dyndoc.dyn_block[:first] when :last Dyndoc.dyn_block[:last]=[] unless Dyndoc.dyn_block[:last] Dyndoc.dyn_block[:last]+=b2 #Dyndoc "lastblock#{i}",Dyndoc.dyn_block[:last] when :texinputs sep=(RUBY_PLATFORM=~/mingw32/ ? ";" : ":") ENV["TEXINPUTS"]="" unless ENV["TEXINPUTS"] ENV["TEXINPUTS"]+=sep+res.strip.split("\n").join(sep) when :optclass optclass=res.strip.split("\n").join(",").split(",").map { |e| "\""+e.strip+"\"" }.join(",") #puts "optclass";p optclass eval_RbCODE("_optclass_ << ["+optclass+"]",filter) end else res=res.strip if var=="_DOCUMENTCLASS_" eval_GLOBALVAR(var,res,filter,mode) eval_TEX_TITLE(filter) if var=="_TITLE_" and @cfg[:format_doc]==:tex end end while i<blck.length-1 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 982 def do_eval(tex,blck,filter) i=0 #puts "do_eval";p blck #puts '#{code}';p @vars["code"] i,*b2=next_block(blck,i) code=parse(b2,filter) #puts "do_eval: code";p code Utils.escape_delim!(code) #puts "do_eval2: code";p code mode=[] while code=~/^(atom|test|pre|last|raw)\|.*/ code = code[($1.length+1)..-1] mode << $1.to_sym end code=Dyndoc::Utils.dyndoc_raw_text(code) if mode.include? :test code=Dyndoc::Utils.unprotect_dyn_block_for_atom(code) if mode.include? :atom #puts "do_eval:mode";p mode;p code #PUT THE FOLLOWING IN THE DOCUMENTATION: #puts "WARNING: {#dyn] accept :last and :raw in this order!" unless (mode - [:last,:raw]).empty? if mode.include? :pre tex2=prepare_output(code) #puts "TOTO";p output_pre_model;p @pre_model #puts "do_eval:PRE tex2";p tex2 else code="{#document][#main]"+code+"[#}" #puts "do_eval:code";p code tex2=parse(code,filter) end Utils.dyndoc_raw_text!(tex2) if mode.include? :last #puts "do_eval:tex2";p tex2 tex2=Utils.dyndoc_raw_text_add(tex2) if mode.include? :raw tex << tex2 if i<blck.length-1 and blck[i+=1]==:to i,*b2=next_block(blck,i) file=parse(b2,filter) unless file.empty? File.open(file,"w") do |f| f << tex2 end end end end
BIENTOT OBSOLETE!
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1667 def do_for(tex,blck,filter) filter.outType=":rb" code="" # @forFilter is here to make available the dyn variables! @cptRbCode,@rbCode,@texRbCode,@forFilter=-1,{},{},filter unless @rbCode code << "if res; for " << parse_args(blck[1],filter).strip << " do\n" cpt=(@cptRbCode+=1) #local value to delete later! #p cpt @rbCode[cpt]=[blck[2..-1].unshift(:blck)] @texRbCode[cpt]=tex code << "@texRbCode[#{cpt}] << parse(@rbCode[#{cpt}],@forFilter)\n" code << "end;end\n" #p code #puts "titi";p filter.envir.local #p @rbCode[cpt] #Dyndoc.warn :for_code,[code.encoding,code,__ENCODING__] @rbEnvir[0].eval(code) @rbCode.delete(cpt) #p @rbCode @texRbCode.delete(cpt) filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 769 def do_format(tex,blck,filter) i=0 i,*b2=next_block(blck,i) format=parse(b2,filter).strip puts "format=#{format}" @fmtOutput=format end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1062 def do_func(tex,blck,filter) call=parse_args(blck[1],filter) code=blck[2..-1] #p "code func";p code eval_func(call,code) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2446 def do_get(tex,blck,filter) blckname=filter.apply(blck[1][1]) codename=filter.apply(blck[3][1]) if @def_blck[-1] and @def_blck[-1].keys.include? codename @savedBlocks[blckname]=@def_blck[-1][codename] #puts "do_get";p @savedBlocks[blckname] end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 934 def do_hide(tex,blck,filter) ## nothing to do!!! end
## PB! never stop whenever condition is true => ex: if false (not exec), elsif true (exec), elsif false (not exec), else (is then exec) def do_if(tex,blck,filter) i,cond=-1,true
p blck
begin filter.outType=":rb" case blck[i+=1] when :if
puts “do_if:blck”;p blck
cond=eval_args(blck[i+=1],filter) when :unless cond=!eval_args(blck[i+=1],filter) when :elsif cond= (!cond and eval_args(blck[i+=1],filter)) #p blck[i] #p eval_args(blck[i],filter) #p cond when :else cond= !cond end filter.outType=nil i,*b2=next_block(blck,i) tex << parse(b2,filter) if cond end while i<blck.length-1
puts “tex”;p tex
end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1644 def do_if(tex,blck,filter) i,cond=-1,nil #p blck begin filter.outType=":rb" case blck[i+=1] when :if, :elsif #puts "do_if:blck[i+1]";p blck[i+1] cond=eval_args(blck[i+=1],filter) when :unless cond=!eval_args(blck[i+=1],filter) when :else cond= true end filter.outType=nil i,*b2=next_block(blck,i) tex << parse(b2,filter) if cond end while !cond and i<blck.length-1 #puts "tex";p tex end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1025 def do_ifndef(tex,blck,filter) i=0 i,*b2=next_block(blck,i) file=parse(b2,filter).strip #p file if File.exist?(file) tex << File.read(file) elsif blck[i+=1]==:<< #p blck[(i+1)..-1] tex2=parse(blck[(i+1)..-1],filter) #p tex2 file=file[1..-1] if file[0,1]=="!" File.open(file,"w") do |f| f << tex2 end tex << tex2 end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1044 def do_input(tex,blck,filter) tmpl=parse_args(blck[1],filter) #p tmpl b=make_var_block(blck[2..-1].unshift(:var),filter) #puts "do_input:b";p b tex << eval_INPUT(tmpl,b,filter) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2158 def do_jl(tex,blck,filter) return unless Dyndoc.cfg_dyn[:langs].include? :jl ## jlBlock stuff ## Dyndoc.warn "do_jl",blck as_default_tmpl_mngr! if dynBlock=dynBlock_in_doLangBlock?(blck) if dynBlock @doLangBlock=[] unless @doLangBlock @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} jlBlockId=@doLangBlock.length-1 end ## Dyndoc.warn "do_jl";p blck filter.outType=":jl" # i=0 # i,*b2=next_block(blck,i) # code=parse(b2,filter) blck=make_do_lang_blck(blck,jlBlockId,:jl) ## Dyndoc.warn "do_jl",blck code = parse_args(blck,filter) ## Dyndoc.warn "DO_JL",code ## Dyndoc.warn "@doLangBlock",@doLangBlock[0][:code] if @doLangBlock[0] process_jl(code) ## Dyndoc.warn "code_jl",code if [:"jl>"].include? blck[0] as_default_tmpl_mngr! tex << JLServer.outputs(code,:block => true) else JLServer.outputs(code) end ## revert all the stuff if dynBlock @doLangBlockEnvs -= @doLangBlock[jlBlockId][:env] #first remove useless envRs @doLangBlock.pop end filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1870 def do_jlverb(tex,blck,filter) # require 'pry' # binding.pry newblck=blck[0] filter.outType=":jl" i=0 i,*b2=next_block(blck,i) #puts "rverb:b2";p b2 code=parse(b2,filter) i+=1 mode=@cfg[:mode_doc] #p [mode,@fmt,@fmtOutput] mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode if blck[i]==:mode i,*b2=next_block(blck,i) mode=parse(b2,filter).strip.to_sym end process_jl(code) #puts "rverb:rcode";p code res=JLServer.echo_verb(code,@@interactive ? :raw : mode) require "dyndoc/common/uv" if @@interactive warn_level = $VERBOSE;$VERBOSE = nil ## puts "jlverb:result";p res tex << (@@interactive ? Uv.parse(res.force_encoding("utf-8"), "xhtml", File.join(Uv.syntax_path,"source.julia.syntax") , false, "solarized",false) : res ) $VERBOSE = warn_level # puts "jlverb:result";p res filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2248 def do_keys(tex,blck,filter) arg=parse_args(blck[1],filter).strip #puts "do_keys: @keys";p @keys #Register! if arg[0..8]=="register:" #puts ">>>>>>>>> Keys->Register";p arg #puts "@keys:";p @keys $dyn_keys={} unless $dyn_keys unless $dyn_keys[:crit] $dyn_keys[:crit]={:pre=>[],:user=>[]} $dyn_keys[:index]=$dyn_keys[:crit][:user] ## predefined $dyn_keys[:crit][:pre]=["order","required"] $dyn_keys["order"]={:type=>:order} $dyn_keys["required"]={:type=>:required} ## user defined $dyn_keys[:alias]=[] $dyn_keys[:current]=[] $dyn_keys[:begin]=[] $dyn_keys[:end]=[] end arg[9..-1].split(":").each{|e| type=e.split("=").map{|e2| e2.strip} res={:type=>type[1].to_sym} crit,*aliases=type[0].split(",").map{|e2| e2.strip} $dyn_keys[:index] << crit $dyn_keys[crit]=res #which criteria need some further treatments $dyn_keys[:begin] << crit if [:section].include? res[:type] $dyn_keys[:end] << crit if [:section].include? res[:type] unless aliases.empty? $dyn_keys[:alias]+=aliases aliases.each{|e| $dyn_keys[e]=crit} end } $dyn_keys[:index] << "order" << "required" #puts "$dyn_keys";p $dyn_keys #puts "Before: @keys:";p @keys #p @init_keys @keys.merge!(KeysManager.make_keys(@init_keys)) if @init_keys #puts "After make_keys: @keys";p @keys #if @tmpl_cfg[:debug] #p @init_keys #Set! elsif arg[0..3]=="set:" ##puts ">>>>>>>>> Keys->Set" @init_keys=KeysManager.init_keys([arg[4..-1].strip]) @keys.merge!(KeysManager.make_keys(@init_keys)) #Require! elsif arg[0..7]=="require:" ##puts ">>>>>>>>> Keys->Require" $dyn_keys[:require]=":"+arg[8..-1] #Select! else #puts ">>>>>>>>> Keys->Select" to_merge=(arg[0,1]=="+") if $dyn_keys[:current].empty? mode_keys=:init $dyn_keys[:cpt]=0 $dyn_keys[:tex]={} lock_parent=nil unless to_merge else mode_keys=:fetch lock_parent=$dyn_keys[:current][-1] unless to_merge $dyn_keys[:cpt]+=1 end #puts "mode_keys";p mode_keys #p arg arg=arg[1..-1] if to_merge lock=KeysManager.make(arg) lock=KeysManager.var_names(lock) KeysManager.simplify(lock) #simplify default value! lock_keys_orig=lock.keys if to_merge KeysManager.merge(lock) elsif lock_parent KeysManager.merge(lock,lock_parent) end #p lock KeysManager.make_title(lock) #p $dyn_keys[:title] #puts "do_keys:lock";p lock # remember the last lock! $dyn_keys[:lastlock]=lock $dyn_keys[:current] << lock ##IMPORTANT: put here and not after the parsing otherwise cpt increases abnormally. unless mode_keys==:init tex << "__DYNKEYS#{$dyn_keys[:cpt]}__" end KeysManager.begin(lock_keys_orig,lock,@keys) @lock=lock #to use inside dyndoc! $dyn_keys[:tex][$dyn_keys[:cpt]] = {:lock=>lock,:content=>parse([blck[2..-1].unshift(:blck)],filter)} if mode_keys==:init #puts "$dyn_keys[:tex]";p $dyn_keys[:tex] texAry=keys_recurse($dyn_keys[:tex][0]) #puts "texAry";p texAry texAry=[texAry] unless texAry.is_a? Array keys_print(tex,texAry) end KeysManager.end(lock_keys_orig,lock,@keys) $dyn_keys[:current].pop end end
# File lib/dyndoc/plugins/tex/tex_parse_do.rb, line 19 def do_list(tex,blck,filter) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1466 def do_loop(tex,blck,filter) ## last executing !!! ## To think about environment!!! cond=true #p blck while cond i=-1 begin case blck[i+=1] when :loop i,*b2=next_block(blck,i) tex << parse(b2,filter) when :break cond=!eval_args(blck[i+=1],filter) i,*b2=next_block(blck,i) tex << parse(b2,filter) if cond end end while cond and i<blck.length-1 end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2204 def do_m(tex,blck,filter) newblck=blck[0] # Dyndoc.warn "do_m";p blck filter.outType=":m" i=0 i,*b2=next_block(blck,i) code=parse(b2,filter) #p ["Mathematica",code] code='TeXForm['+code+']' if blck[0]==:"M>" tex2=Dyndoc::Converter.mathlink(code) if [:"M>",:"m>"].include? blck[0] tex << (blck[0]==:"M>" ? ('$'+tex2+'$').gsub("\\\\","\\") : tex2 ) end filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 777 def do_main(tex,b,filter) #OLD: @userTag.evalUserTags(tex,b[1],filter) #NEW: simply apply the filter on the text #b[1]="" unless b[1] #puts "do_main";p b[1] res=filter.apply(b[1]) unless res.scan(/^__RAW__/).empty? res=Utils.protect_format_blocktext(res) else res=Utils.format_blocktext(res) end #puts res tex << res #TODO: maybe propose a language like textile to be converted in any format end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1140 def do_meth(tex,blck,filter) #puts "do_meth";p blck call,code=make_def(blck,filter) #puts "do_meth";p call;p code eval_meth(call,code) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1147 def do_new(tex,blck,filter) #first declaration of the object #puts "do_new";p blck var=parse_args(blck[1],filter).strip var = var[1..-1] if var[0,1]==":" i=2 if blck[i]==:of i,*b2=next_block(blck,2) klass=parse(b2,filter).split(",").map{|e| e.strip}.join(",") else return end i+=1 inR=@rEnvir[0] if blck[i]==:in i,*b2=next_block(blck,i) #p b2 #p filter.envir.local["self"] inR=parse(b2,filter).strip #p inR inR,parentR=inR.split("<").map{|e| e.strip} parentR=@rEnvir[0] unless parentR or RServer.exist?(parentR) #p parentR RServer.new_envir(inR,parentR) unless RServer.exist?(inR) i+=1 end #puts "do_new:var,klass";p var;p klass =begin b2=blck[4..-1].map{|e| if e.is_a? Array and e[0]==:named e[1]=var+"."+e[1] end e } =end b2=[[:named,var+".Class",[:main,klass]]] b2+=[:",",[:named,var+".Renvir",[:main,inR]]] #puts "do_new:b2";p b2 b=make_var_block(b2.unshift(:var),filter) #puts "do_new:var";p b eval_VARS(b,filter) #puts "do_new:eval_VARS";p filter.envir.local # and then call of the initialize method here called new.(Class) =begin call="new" bCall=get_method(call,get_klass(klass)) p call =end b2=[] << :call<< [:args,[:main,"new"]] << [:named,"self",[:main,var]] #p blck[4..-1] b2+=blck[i..-1] #puts "do_new:new b2";p b2 tex << parse([b2],filter) #tex << eval_CALL("new",b,filter) end
# File lib/dyndoc/base/tmpl/extension.rb, line 151 def do_newBlck(tex,b,filter) blckMngr=BlckMngr.new(self,b,tex,filter) blckname=b[1][1].strip ##p blckname if ["saved"].include? blckname Dyndoc.warn "Warning: Impossible to redefine an existing instruction!" end #puts "new_blck:b";p b blckMngr.pos=1 items=[] return unless [:blck,:aggregate].include? blckMngr.next_tag @@newBlcks[blckname]={} if blckMngr.next_tag==:aggregate blckMngr.next_tag! @@newBlcks[blckname][:aggregate]= blckMngr.next_tag![1].strip.split(",") end while blckMngr.next_tag! == :blck and !blckMngr.at_end? items << (item=blckMngr.next_tag![1].strip) blcks=[] while (blckMngr.next_tag != :blck) and !blckMngr.at_end? blcks << blckMngr.next_tag! end if [":pre",":post"].include? item @@newBlcks[blckname][item]=blcks else i,subBlcks=-1,{} while ([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1) subname=blcks[i+=1] subBlcks[subname]=[] while !([:pre,:post,:do_code].include? blcks[i+1]) and !(i==blcks.length-1) subBlcks[subname] << blcks[i+=1] end end @@newBlcks[blckname][item]=subBlcks end end ## declare the new block! add_dtag({ :instr=>[blckname], :keyword_reg=>{ blckname.to_sym=> '[%.\w,><?=+:-]+' }, :with_tagblck=>[blckname.to_sym], },"blck") #alias of blck! #=begin (items-[":pre",":post"]).each do |item| #p @@newBlcks[blckname][item] if @@newBlcks[blckname][item][:do_code] blckRbCode= %Q[def do_blck_#{blckname}_#{item}(tex,blck,filter) ##Dyndoc.warn :newBlck, blck blckMngr=BlckMngr.new(self,blck,tex,filter) ## the next code is automatically generated! #{@@newBlcks[blckname][item][:do_code][0][1]} end] #Dyndoc.warn :blckRbCode, blckRbCode Dyndoc::Ruby::TemplateManager.module_eval(blckRbCode) #Dyndoc.warn :methods, methods.sort end end #=end #p methods.sort #Dyndoc.warn "newBlck[\"#{blckname}\"]",@@newBlcks[blckname] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2417 def do_opt(tex,blck,filter) #p blck #p parse(blck[1..-1],filter) #p parse(blck[1..-1],filter).split(",").map{|e| e.strip} #p @tags taglist=parse(blck[1..-1],filter).strip taglist.split(",").map{|e| e.strip}.each{|tag| if tag[0,1]=="-" @tags.delete(TagManager.init_input_tag(tag[1..-1])) else tag=tag[1..-1] if tag[0,1]=="+" @tags << TagManager.init_input_tag(tag) end } #puts "ici";p @tags end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2462 def do_part(tex,blck,filter) i=0 i,*b2=next_block(blck,i) file=parse(b2,filter).strip # prepare the filename file,part=file.split("|").map{|e| e.strip} file,out=file.split("#").map{|e| e.strip} out=(out ? out.to_sym : @cfg[:format_doc]) out=:dyn if [:*,:all].include? out file=File.join("part",file+"_part"+Dyndoc::EXTS[out]) # part tags prepended by "part:" part=TagManager.make_tags(part.split(",").map{|e| "part:"+e}.join(",")) if part # if File.exist?(file) and (!part or !TagManager.tags_ok?(part,@tags)) puts "partial #{file} loaded" tex << File.read(file) else puts "partial #{file} generated" tex2=parse([blck[(i+1)..-1].unshift(:blck)],filter) #puts tex2 Dyndoc.make_dir("part") File.open(file,"w") do |f| f << tex2 end tex << tex2 end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1725 def do_r(tex,blck,filter) newblck=blck[0] #puts "do_r";p blck filter.outType=":r" i=0 i,*b2=next_block(blck,i) code=parse(b2,filter) inR=nil if blck[i+=1]==:in i,*b2=next_block(blck,i) inR=parse(b2,filter).strip RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR) end @rEnvir.unshift(inR) if inR #puts "do_r:code";p code;p eval_RCODE(code,filter,true,true) if newblck==:"r>" if newblck==:"r>" tex2=eval_RCODE(code,filter,:pretty=> true,:capture=> true) ## Dyndoc.warn "rrrrrrrrrrrrrrr: tex2", tex2 tex << tex2 else # pretty is put to false because prettyNum does not accept empty output or something like that! eval_RCODE(code,filter,:pretty=> false) end @rEnvir.shift if inR filter.outType=nil end
begin NEW STUFF!!!¶ ↑
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2025 def do_rb(tex,blck,filter) require 'stringio' @rbIO=[] unless @rbIO @rbIO << (blck[0]==:"rb>" ? StringIO.new : STDOUT) $stdout=@rbIO[-1] ## Dyndoc.warn "blck",blck ## Dyndoc.warn "do_rb binding",binding,local_variables dynBlock=dynBlock_in_doLangBlock?(blck) if dynBlock @doLangBlock=[] unless @doLangBlock @doLangBlock << {:tex=>'',:code=>[],:out=>'',:filter=>filter,:env=>[]} #@filterRbBlock} rbBlockId=@doLangBlock.length-1 end ## this is ruby code! filter.outType=":rb" ## Dyndoc.warn "do_rb",filter.envir.local blck=make_do_lang_blck(blck,rbBlockId) ## Dyndoc.warn "do_rb",blck code = parse_args(blck,filter) ## Dyndoc.warn "rb code="+code process_rb(code) if Utils.raw_code_to_process ## Dyndoc.warn "rb CODE="+code as_default_tmpl_mngr! if blck[0]==:"rb>" res=eval_RbCODE(code,filter) if blck[0]==:"rb>" tex2=@rbIO.pop.string #Dyndoc.warn "res",res #Dyndoc.warn "RbRbRbRbRbRbRb:", (tex2.empty? ? res : tex2) tex << (tex2.empty? ? res : tex2) else @rbIO.pop end ## revert all the stuff if dynBlock @doLangBlockEnvs -= @doLangBlock[rbBlockId][:env] #first remove useless envRs @doLangBlock.pop end $stdout=@rbIO.empty? ? STDOUT : @rbIO[-1] filter.outType=nil ## Dyndoc.warn "SORTIE RB!",dynBlock,blck,tex2 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1837 def do_rbverb(tex,blck,filter) # require 'pry' # binding.pry newblck=blck[0] filter.outType=":rb" i=0 i,*b2=next_block(blck,i) #puts "rverb:b2";p b2 code=parse(b2,filter) i+=1 mode=@cfg[:mode_doc] #p [mode,@fmt,@fmtOutput] mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode if blck[i]==:mode i,*b2=next_block(blck,i) mode=parse(b2,filter).strip.to_sym end process_rb(code) ## Dyndoc.warn "rverb:rcode";p code res=RbServer.echo_verb(code,@@interactive ? :raw : mode,@rbEnvir[0]) ## Dyndoc.warn "rbverb:res",res require "dyndoc/common/uv" if @@interactive warn_level = $VERBOSE;$VERBOSE = nil tex << (@@interactive ? Uv.parse(res.force_encoding("utf-8"), "xhtml", File.join(Uv.syntax_path,"source.ruby.syntax") , false, "solarized",false) : res ) $VERBOSE = warn_level #puts "rverb:result";p res filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1752 def do_renv(tex,blck,filter) inR=parse_args(blck,filter).strip #p inR mode=:ls case inR[-1,1] when "+" mode=:attach inR=inR[0...-1] when "-" mode=:detach inR=inR[0...-1] when "?" mode=:show inR=inR[0...-1] end unless [:detach,:ls].include? mode #puts "#{inR} EXIST?";p RServer.exist?(inR);"print(ls(.GlobalEnv$.env4dyn))".to_R RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR) end case mode when :ls unless inR.empty? begin inRTmp=eval(inR) inR=(inRTmp.is_a? Regexp) ? inRTmp : /#{inR}/ rescue inR=/#{inR}/ end end tex << ((inR.is_a? Regexp) ? @rEnvir.select{|rEnv| rEnv=~ inR} : @rEnvir ).join(",") when :attach @rEnvir.unshift(inR) unless inR.empty? when :detach if inR.empty? @rEnvir.shift else if w=@rEnvir.index(inR) @rEnvir.delete_at(w) end end when :show tex << (inR.empty? ? @rEnvir[0] : (@rEnvir[0]==inR).to_s) end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1052 def do_require(tex,blck,filter) ## just load and parse : read some FUNCs and EXPORT some variables ## in the header #Dyndoc.warn "do_require",blck #p parse_args(blck,filter) tmpl=parse_args(blck,filter).strip.split("\n") #Dyndoc.warn "require",tmpl eval_LOAD(tmpl,filter) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1797 def do_rverb(tex,blck,filter) # require 'pry' # binding.pry newblck=blck[0] filter.outType=":r" i=0 i,*b2=next_block(blck,i) #Dyndoc.warn "rverb:b2",b2 code=parse(b2,filter) i+=1 inR=nil if blck[i]==:in i,*b2=next_block(blck,i) inR=parse(b2,filter).strip RServer.new_envir(inR,@rEnvir[0]) unless RServer.exist?(inR) i+=1 end mode=@cfg[:mode_doc] #p [mode,@fmt,@fmtOutput] mode=@fmtOutput.to_sym if @fmtOutput and ["html","tex","txtl","raw"].include? @fmtOutput mode=(@fmt and !@fmt.empty? ? @fmt.to_sym : :default) unless mode if blck[i]==:mode i,*b2=next_block(blck,i) mode=parse(b2,filter).strip.to_sym end mode=:default if newblck==:rout #or newblck==:"r>>" @rEnvir.unshift(inR) if inR process_r(code) #Dyndoc.warn "rverb:rcode",code,@@interactive res=RServer.echo_verb(code,@@interactive ? :raw : mode,@rEnvir[0], prompt: (@@interactive ? "R" : "")) require "dyndoc/common/uv" if @@interactive warn_level = $VERBOSE;$VERBOSE = nil tex << (resUV=(@@interactive ? Uv.parse(res.force_encoding("utf-8"), "xhtml", File.join(Uv.syntax_path,"source.r.syntax") , false, "solarized",false) : res.force_encoding("utf-8") )) $VERBOSE = warn_level #Dyndoc.warn "rverb:result",resUV @rEnvir.shift if inR filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 926 def do_set(tex,blck,filter) i,*b2=next_block(blck,1) #puts "set";p blck[1] #p b2 #p parse_args(blck[1],filter) eval_SET(parse_args(blck[1],filter),parse(b2,filter),filter) #,true) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2195 def do_sh(tex,blck,filter) #Dyndoc.warn "do_sh: blck ";p blck[1..-1] filter.outType="none" code=parse(blck[1..-1],filter) %x[ #{code} ] #Dyndoc.warn "do_sh: code ";p code filter.outType=nil end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1374 def do_style(tex,blck,filter) call=parse_args(blck[1],filter) #p call call=call.split(":") #puts "style:call";p call #p @styles #p blck[2..-1] if call[0][0,1]=~/[A-Z]/ # style declaration unless call[1] # instance of new object b=make_style_new(call[0],blck[2..-1]) do_new(tex,b,filter) style=parse_args(b[1],filter) #p style register_style_cmds(@styles[:class][call[0]],style) else case call[1] when "new" # constructor style method called instance is demanded register_style_init b=make_style_meth("new",call[0],blck[2..-1]) #p b do_meth(tex,b,filter) b=make_style_new(call[0],[[:main,call[0][0,1].downcase+call[0][1..-1] ]]) #,:<]) #p b #p filter.envir do_new(tex,b,filter) #p filter.envir else #puts "register style meth:#{call[1]}.#{call[0]}" # style cmd method b=make_style_meth(call[1],call[0],blck[2..-1]) do_meth(tex,b,filter) # register a new meth for this new Style Class register_style_meth(call[0],call[1]) register_style_cmds([call[1]],call[0][0,1].downcase+call[0][1..-1]) end end elsif call[0]=="style" if call[1]=="cmds" style=blck[2][1].strip cmds=(blck[4] ? blck[4][1] : nil) cmds=cmds.split(",").map{|cmd| cmd.strip} if cmds if @vars[style+".Class"] klass=@vars[style+".Class"][5..-1] cmds=(cmds ? cmds & @styles[:class][klass] : @styles[:class][klass] ) register_style_cmds(cmds,style,true) end elsif call[1]=="alias" and @styles aliases=parse([blck[2]],filter).split(",") value=parse([blck[4]],filter) aliases.each{|a| @styles[:alias][a]=value } end else # cmd style call no_obj=call.length==1 obj,cmds=(no_obj ? [nil]+call : call) =begin if obj and !@vars[obj+".Class"] cmds.unshift(obj) obj=nil end =end #recursive alias replacement ##TODO: it seems that no call in new is possible! #p cmds #register_style_init #p @styles while !(aliases=(cmds.split("|") & @styles[:alias].keys)).empty? aliases.each{|a| cmds.gsub!(a,@styles[:alias][a])} end #puts "cmds";p cmds cmds=cmds.split("|") #puts "cmds2";p cmds #TODO: facility to define alias for style!?!?! b=blck[2..-1] #p cmds cmds.reverse.each{|cmd| obj=@styles[:cmd][cmd] if no_obj #p @filter.envir b=make_style_call(cmd,obj,b) #p b } #puts "style:call";p b do_call(tex,b,filter) end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1203 def do_super(tex,blck,filter) #first declaration of the object var=parse_args(blck[1],filter).strip i=2 parent=1 if blck[i]==:parent i,*b2=next_block(blck,2) parent=parse(b2,filter).to_i parent=1 if parent==0 i+=1 end #find next class! super_meth=get_super_method(parent) #p super_meth return "" unless super_meth #build the updtaed block b2=[] << :call<< [:args,[:main,super_meth]] << [:named,"self",[:main,var]] b2+=blck[i..-1] #puts "super b2";p b2 tex << parse([b2],filter) #tex << eval_CALL("new",b,filter) end
# File lib/dyndoc/plugins/tex/tex_parse_do.rb, line 8 def do_title(tex,blck,filter) =begin mode="" mode=filter.apply(splitter.key[i].strip).downcase if splitter.key[i] ## apply R filtering txt=filter.apply(b[1...-1].join("\n")) ## _TITLE_ is redefined! eval_TITLE(txt,filter,mode) =end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 938 def do_txt(tex,blck,filter) #p blck code=blck[1].dup #puts "do_txt:code";p code ##p @curCmd ## to name some code block! #name="" ##JUST IN CASE, OLD: if code=~ /^\s*([\w\.\-_:]*)\s*\[(.*)\]\s*$/m #multiline! if code=~ /^\s*([\w\.\-_:]+)\s*\[(.*)\]\s*$/m #multiline! name,code=$1.strip,$2 ##code="["+code+"]" if name.empty? end #puts "do_txt:name,code";p [name,code] ## @unprotected_txt=code @protected_txt=Utils.protect_txt_block(code) #puts "do_txt:@protected_code";p @protected_code #puts "do_txt2:code";p name;p code res = (@curCmd=="txt" ? code : @protected_txt ) #puts "res";p res if name #unless name.empty? #Dyndoc.warn "txt:name",[name,code] ## the following is only applied when @curCmd==">" or maybe ">>" filter.envir[name]=[code] outType=nil outType=filter.outType+"=" if filter.outType tex << filter.convert(name+"!",outType) if @curCmd==">" #useful for templating as in Table.dyn else #Dyndoc.warn "res",res tex << res end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 918 def do_var(tex,blck,filter) #p blck b=make_var_block(blck,filter) #puts "do_var:b";p b #puts "do_var:filter.local";p filter.envir.local eval_VARS(b,filter) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 972 def do_verb(tex,blck,filter) i=0 i,*b2=next_block(blck,i) code=parse(b2,filter) Utils.escape!(code,[["{","__OPEN__"],["}","__CLOSE__"]]) tex << Dyndoc::VERB[@cfg[:format_doc]][:begin] << "\n" tex << code.strip << "\n" tex << Dyndoc::VERB[@cfg[:format_doc]][:end] << "\n" end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2455 def do_yield(tex,blck,filter) #p blck #p parse(blck[1..-1],filter) codename=parse(blck[1..-1],filter) make_yield(tex,codename,filter) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1903 def dynBlock_in_doLangBlock?(blck) blck.map{|b| b.respond_to? "[]" and [:>,:<,:<<].include? b[0] }.any? end
# File lib/dyndoc/base/tmpl/manager.rb, line 195 def dyndoc_mode=(mode) @dyndocMode=mode end
# File lib/dyndoc/plugins/tex/tex_eval.rb, line 12 def echo_verb(txt,verbatim=true,env="Global") txtout=Dyndoc::RServer.echo(txt,env) header= verbatim and txtout.length>0 out="" out << BEGINVERB << "\n" if header out << txtout out << ENDVERB << "\n" if header out end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2134 def evalJlBlock(id,cpt,tag,lang=:jl) ## Dyndoc.warn "evalJlBlock!!!" ## this deals with the problem of newBlcks! ## Dyndoc.warn "block_normal",blckMode_normal? ## Dyndoc.warn "@doLangBlock",@doLangBlock code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" ) ## Dyndoc.warn "codeJL",code ## Dyndoc.warn "filter",@doLangBlock[id][:filter] @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter]) ## Dyndoc.warn "code2JL",@doLangBlock[id][:out] ## Dyndoc.warn tag if tag == :> outcode=@doLangBlock[id][:out] #.gsub(/\\/,'\\\\\\\\') #to be compatible with R outcode='print("'+outcode+'")' ## Dyndoc.warn "outcode",outcode Julia.exec outcode,:get=>nil # CLEVER: directly redirect in R output that is then captured end if tag == :<< return ( lang==:jl ? JLServer.eval(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) ) else return @doLangBlock[id][:out] end end
end¶ ↑
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2073 def evalRBlock(id,cpt,tag,lang=:R) ## this deals with the problem of newBlcks! ## Dyndoc.warn "block_normal",blckMode_normal? code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" ) ## Dyndoc.warn "codeR",code @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter]) ## Dyndoc.warn "code2R", @doLangBlock[id][:out] if tag == :> outcode=@doLangBlock[id][:out].gsub(/\\/,'\\\\\\\\') #to be compatible with R outcode=outcode.gsub(/\'/,"\\\\\'") #Dyndoc.warn outcode='cat(\''+outcode+'\')' #Dyndoc.warn "outcode",outcode outcode.to_R # CLEVER: directly redirect in R output that is then captured end if tag == :<< return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) ) else return @doLangBlock[id][:out] end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1959 def evalRbBlock(id,cpt,tag,lang=:rb) ## Dyndoc.warn "@doLangBlock[#{id.to_s}][:code][#{cpt.to_s}]",@doLangBlock[id][:code][cpt]#,@doLangBlock[id][:filter] ## this deals with the problem of newBlcks! ##puts "block_normal";p blckMode_normal? code=(blckMode_normal? ? @doLangBlock[id][:code][cpt] : "{#blckAnyTag]"+@doLangBlock[id][:code][cpt]+"[#blckAnyTag}" ) #puts "code";p code @doLangBlock[id][:out]=parse(code,@doLangBlock[id][:filter]) ##Dyndoc.warn "evalRbBlock:doLangBlock",[id,code,@doLangBlock[id][:out]] if tag == :> ######################################### ## THIS IS FOR OLD ##@doLangBlock[id][:tex] << @doLangBlock[id][:out] if tag == :> ## THIS IS NEW print @doLangBlock[id][:out] if tag == :> ## #Dyndoc.warn "EVALRBBLOCK: @doLangBlock[id][:out]",@doLangBlock[id][:out] if tag == :> ####################################### if tag == :<< return ( lang==:R ? RServer.output(@doLangBlock[id][:out],@rEnvir[0],true) : eval(@doLangBlock[id][:out]) ) else return @doLangBlock[id][:out] end end
# File lib/dyndoc/base/tmpl/eval.rb, line 40 def eval_BINDING(env,b,filter) eval_VARS(b,filter) @envirs[env]=filter.envir.local #p "BINDING#{env}";p filter; p "\n" end
# File lib/dyndoc/base/tmpl/eval.rb, line 261 def eval_CALL(call,b,filter,meth_args_b=nil,blckcode=nil) txt="" #puts "eval_CALL:call,b,filter,@calls";p call;p b #p filter.envir #p @calls #p @calls.keys.sort #puts "meth_args_b"; p meth_args_b call,export=call[0...-1],true if call[-1,1]=="!" if @calls.keys.include? call # envir task b2=b.map{|e| filter.apply(e)} if b and b.length>0 #puts "b2 init";p b2 dict2={:prev=>filter.envir.local} if b and b.length>0 #puts "b2";p b2;p b2.map{|e| e.split("\n")}.flatten dict=FilterManager.eval_dict(b2.map{|e| e.split("\n")}.flatten) #puts "dict";p dict dict.each{|k,v| dict2[k.to_s]=v } end #puts "dict2";p dict2 #p dict2["envir"] #if dict2["envir"] ## local consideration: special ":envir" dict2[:prev]=@envirs[dict2["envir"][0]] if dict2["envir"] and (dict2["envir"][1].include? :local) and @envirs[dict2["envir"][0]] and (@envirs[dict2["envir"][0]].is_a? Hash) #p dict2 if dict2["envir"] and (dict2["envir"][1].include? :local) and @envirs[dict2["envir"][0]] and (@envirs[dict2["envir"][0]].is_a? Hash) #puts "CALL:#{call}";p @global #puts "dict2[\"envir\"]?";p dict2 # new filter to evualate the call filter2=FilterManager.new({:global=>@global},self) #puts "filter2.envir";p filter2.envir # init body call bCall=@calls[call] #is a method ? tmpCall=call.split(".") isMeth=(bCall==:meth) or (tmpCall.length==2 and (@meths.include? tmpCall[0])) # assign self if exists in :prev? #puts "Assign";p dict2["self"]; p dict2[:prev] #puts "isMeth?";p isMeth if isMeth and dict2["self"] #puts "dict2";p dict2 #and dict2[:prev][objName=dict2["self"][0]] objName=dict2["self"][0] #puts "objName";p objName objName=objName[1..-1] if objName[0,1]==":" objName="self"+objName if objName[0,1]=="." #puts "objName2";p objName #filter2.envir.local["self"]=dict2[:prev][objname] objKeys=Envir.to_keys(objName) #puts "objKeys";p objKeys #puts "dict2[:prev]";p dict2[:prev] #puts "Envir.keys_defined.";p Envir.keys_defined?(dict2[:prev],objKeys) # RMK: 5/9/08 it seems that Envir.get_elt! is only used here and replaced by Envir.keys_defined? newly created! #Envir.get_elt!(dict2[:prev],objKeys) # find in dict2[:prev] and their sub :prev dictObj=dict2[:prev] begin objEnv=Envir.elt_defined?(dictObj,objKeys) dictObj=dictObj[:prev] end while !objEnv and dictObj #p @klasses #p @global #puts "objEnv(local)";p objEnv # otherwise, find in @global envir objEnv=Envir.elt_defined?(@global,objKeys) unless objEnv #puts "objEnv(global)";p objEnv # otherwise return empty env objEnv={} unless objEnv #puts "objEnv";p objEnv #at least {} and then nonempty! #puts "objKeys[0]";p objKeys[0] if objKeys[0]=="self" #p dict2 #p @vars objName=([dict2[:prev]["self"]["ObjectName"][:val][0]]+objKeys[1..-1]).join(".") #puts "objName4Self";p objName end ##PB HERE: objEnv does not return the right envir because the object is in :prev and then objEnv[objKeys[-1]] is not correct! # filter2.envir.local["self"] is then unset! #puts "objKeys[-1]";p objKeys[-1] #puts "objEnv";p objEnv #p objEnv[objKeys[-1]] filter2.envir.local["self"]=objEnv[objKeys[-1]] #puts 'filter2.envir.local["self"]';p filter2.envir.local["self"] dict2.delete("self") #puts "dict2Self";p dict2 #attempt of autobuilding of object! (10/03/08) elt={} #test if it is an internal Dyn Object (DynVar, Array, ) i.e. if Class is a field? #puts "filter2.local";p filter2.envir.local["self"] if !objEnv.empty? and filter2.envir.local["self"] if filter2.envir.local["self"].is_a? Array #is an Array object elt["content"]=objEnv[objKeys[-1]] elt["Class"]={:val=>["Array,Object"]} elsif !filter2.envir.local["self"]["Class"] #no Class specified => A DynVar or List object if filter2.envir.local["self"][:val] #is a DynVar object elt["content"]= filter2.envir.local["self"] elt["Class"]={:val=>["DynVar,Object"]} else #is a List object #puts "List";p objEnv[objKeys[-1]] elt["content"]=objEnv[objKeys[-1]] elt["Class"]={:val=>["List,Object"]} end end elt["ObjectName"]={:val=>[objName]} unless elt.empty? #puts "class";p elt["Class"] #puts "content";p elt["content"] end if objEnv.empty? or !filter2.envir.local["self"] if (elt=AutoClass.find(objName)).empty? #is a String Vector i.e. of the form # name1,name2,...,nameN vals=objName.split(",").map{|e| e.strip}.map{|e| {:val=>[e]}} elt["content"]={"value"=>{:val=>[objName]},"ary"=>vals} elt["Class"]={:val=>["String,Object"]} elt["ObjectName"]={:val=>[nil]} #empty ObjectName used in inspect method! end end #puts "Elt:";p elt #creation of the new object! filter2.envir.local["self"]=elt unless elt.empty? #p filter2.envir.local filter2.envir.local["self"]["ObjectName"]={:val=>[objName]} unless objName=="self" or filter2.envir.local["self"]["ObjectName"] end #puts "filter2";p filter2.envir #puts "dict2[:prev](???)";p dict2[:prev] #Really IMPORTANT: for pointer tricks: first import :prev environment filter2.import_dict({:prev=>dict2[:prev]}) dict2.delete(:prev) #puts "dict2";p dict2 #puts "filter2a";p filter2.envir #Really IMPORTANT: and then pointers could be recognized! filter2.import_dict(dict2) #puts "filter22";p filter2.envir inR=nil if isMeth if bCall==:meth #p filter2.envir #puts "extract self";p call;p filter2.envir.extract("self") #ICI: tester si l'objet a un champ Klass sinon faire comme avant et le déclarer en klass=get_klass(filter2.envir.extract("self")["Class"]) #puts "call";p call #puts "klass";p klass #p @calls.keys =begin i,bCall=-1,nil bCall=@calls[call+"."+klass[i+=1]] until bCall call+="."+klass[i] =end bCall=get_method(call,klass) #puts "call meth";p call;p klass #p bCall #puts some raise Error! return "" unless bCall unless bCall puts "DYN WARNING: Method #{call} undefined for class #{klass} (object: #{objName})" return "" end #init the parameter of the true method! if (args=@args[call]) args=args[1..-1] args=nil if args.empty? #p args if meth_args_b #puts "ICI1";p meth_args_b CallFilter.parseArgs(call,meth_args_b,true) #puts "eval CALL meth_b";p call;p meth_args_b #p meth_args_b b2=meth_args_b.map{|e| filter.apply(e)} if meth_args_b and meth_args_b.length>0 #puts "call(2)";p call;p b2 dict=FilterManager.eval_dict(b2) #puts "dict(eval_CALL)";#p dict #IMPORTANT: (19/10/08) remove self from dict because already imported! dict.map!{|e| e if e[0]!="self"}.compact! #puts "Import dict in filter2" #p dict #puts "eval_CALL:filter2.envir";p filter2.envir filter2.import_dict(dict) #puts "self";p filter2.envir.local["self"] #p filter2.envir.local end end end # R envir inR=filter2.envir.extract("self")["Renvir"] #p inR #p @args[call] #p b2 #p filter2 end # deal with blckcodes #puts "<<def_blck #{call}" #p blckcode #puts "av:";p @def_blck @def_blck << blckcode if blckcode and !blckcode.empty? #puts "ap:";p @def_blck #p blckcode ## Tex part ### this is wondeful (10/08/04) ## apply filter2 for fragment before parsing @rEnvir.unshift(inR) if inR =begin if call=="new.TotoIn" puts "AVANT" p bCall p filter2.envir.local["self"] end =end # deal with _args_ argument #puts "filter2.local";p filter2.envir.local #p filter2.envir.local["_args_"] #p Envir.is_listElt?(filter2.envir.local["_args_"]) if filter2.envir.local["_args_"] and Envir.is_listElt?(filter2.envir.local["_args_"]) #puts "IICCII" filter2.envir.local["_args_"].each{|key,val| filter2.envir.local[key]=val} filter2.envir.local.delete("_args_") end #puts "filter2.local";p filter2.envir.local #puts "bCall";p bCall #puts "call binding";p filter2.envir.local #Dyndoc.warn "rbEnvir tricks", [filter2.envir.extract("binding"),@rbEnvir4calls] inRb=filter2.envir.extract("binding") #first the call parameter inRb=@rbEnvir4calls[call] unless inRb #second, the tag binding rbenvir_go_to(inRb) #puts "eval_CALL:bCall";p bCall txt=parse(bCall,filter2) #puts "eval_CALL:txt";p txt rbenvir_back_from(inRb) #p filter2.envir.local =begin if call=="new.TotoIn" puts "APRES" p filter2.envir.local["self"] end =end #puts ">>def_blck #{call}" #puts "av";p @def_blck;p blckcode @def_blck.pop if blckcode and !blckcode.empty? #puts "ap";p @def_blck; ## post-filtering txt=filter2.apply(txt,:post,false) ##IMPORTANT: EST-CE VRAIMENT UTILE??? VOIR vC!!!! @rEnvir.shift if inR filter.envir.local=filter2.envir.local if export end #puts "FIN CALL" return txt end
# File lib/dyndoc/base/tmpl/eval.rb, line 51 def eval_ENVIR(env,filter) filter.envir.local=@envirs[env] if @envirs[env] #p "ENVIR#{env}";p filter; p "\n" end
# File lib/dyndoc/base/tmpl/eval.rb, line 250 def eval_FUNC(bloc,b) bloc,code=Utils.end_line(bloc,b) ##p bloc;p code key,args=bloc.strip.split(/[|:]/) key.strip! #p "@calls[#{key}]" @args[key]=args.split(",").map{|e| e.strip} if args #p @args[key];p code @calls[key]=code end
# File lib/dyndoc/base/tmpl/eval.rb, line 569 def eval_GLOBALVAR(var,txt,filter,mode="") return unless filter.envir.global[var] ## texvar already declared in DefaultPre_tmpl.tex if mode.empty? or !(["add","append","+"].include? mode) filter.envir.global[var][:val][0]="" else filter.envir.global[var][:val][0] << "\n" unless filter.envir.global[var][:val][0].empty? end filter.envir.global[var][:val][0] << txt end
# File lib/dyndoc/base/tmpl/eval.rb, line 120 def eval_INPUT(tmpl,b,filter) ## register tmpl in @blocks to avoid next the same call!!! #=begin TO REMOVE tmpl,tags,rest=tmpl.split(/\((.*)\)/) tags=TagManager.init_input_tags(tags.split(",").map{|e| e.strip.downcase}) if tags #=end tmpl,export=tmpl[0...-1],true if tmpl[-1,1]=="!" #p tmpl;p tags;p rest tmpl_name=tmpl tmpl_orig=Dyndoc.doc_filename(tmpl.strip) tmpl=Dyndoc.directory_tmpl? tmpl_orig #TO REMOVE: init_dtag(tmpl) #p tmpl block=tmpl #TO REMOVE: +(partTag.empty? ? "" : "("+partTag.join(',')+")") unless @blocks.keys.include? block #TO REMOVE: input=PartTag.part_doc(File.read(tmpl),partTag2) #puts "inside INPUT";p tmpl return "Dyndoc Error: "+tmpl_name+" is not reacheable!!! " unless tmpl input=Dyndoc.read_content_file(tmpl,{:doc => @doc}) @blocks[block]=input #p block;p @blocks[block] end ## apply R filtering b2=b.map{|e| filter.apply(e)} if b.length>0 dict2={:prev=>filter.envir.local} if b.length>0 dict=FilterManager.eval_dict(b2) ###eval("{"+b2.join(",")+"}") dict.each{|k,v| dict2[k.to_s]=v} end filter2=FilterManager.new({:global=>@global},self) filter2.import_dict(dict2) ################################### # added to set the current filename # of the template in the local environment # _FILENAME_ is maybe obsolete now # (see also "parse" in parse_do.rb file) ################################### filter2.envir["_FILENAME_CURRENT_"]=tmpl.dup filter2.envir["_FILENAME_"]=tmpl.dup #register name of template!!! ##################################### filter2.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!! filter2.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!! =begin Envir.set_textElt!(["_FILENAME_"],tmpl.dup,filter2.envir.local) #register name of template!!! Envir.set_textElt!(["_PWD_"],File.dirname(tmpl),filter2.envir.local) #register name of template!!! =end ## Text part ## pre-filtering b2=@blocks[block] @current_tmpl=block #puts "eval_INPUT:tags";p tags txt=parse(b2,filter2,tags) #puts "eval_INPUT:txt";p txt ## post-filtering txt=filter2.apply(txt,:post,false) txt.strip! ##clean whitespace txt += "\n" ##need one at the end!!! filter.envir.local=filter2.envir.local if export return txt end
# File lib/dyndoc/base/tmpl/eval.rb, line 181 def eval_LOAD(b,filter) ## just load and parse : read some FUNCs and EXPORT some variables ## in the header if b.length>0 b2=b.map{|e| filter.apply(e)} #puts "b2";p b2 #Dyndoc.warn "LOAD",b2 b2.each{|lib| lib,tags,rest=lib.split(/\((.*)\)/) #p lib;p tags;p rest tags=tags.split(",").map{|e| e.strip.downcase} if tags #puts "lib";p lib tmpl_orig=Dyndoc.doc_filename(lib.strip) tmpl=Dyndoc.directory_tmpl? tmpl_orig #puts "tmpl";p tmpl #TO REMOVE: init_dtag(tmpl) =begin TO REMOVE partTag2=@partTag.dup PartTag.append(partTag2,partTag) input=PartTag.part_doc(File.read(tmpl),partTag2) #p input =end # REPLACEMENT of ABOVE! unless @libs.keys.include? tmpl if tmpl and File.exist? tmpl input=Dyndoc.read_content_file(tmpl) @libs[tmpl]=input filter.envir["_FILENAME_"]=tmpl.dup #register name of template!!! filter.envir["_FILENAME_ORIG_"]=tmpl_orig.dup #register name of template!!! filter.envir["_PWD_"]=File.dirname(tmpl) #register name of template!!! txt=parse(@libs[tmpl],filter,tags) end end } end end
# File lib/dyndoc/base/tmpl/eval.rb, line 218 def eval_LOAD_HELPERS(b,filter) ## just load and parse ## in the header if b.length>0 b2=b.map{|e| filter.apply(e)} #p b2 pathenv=File.read(File.join(Dyndoc.cfg_dir[:home],"helpers")).strip helpers = "" b2.each{|lib| #p lib filename=lib.strip unless filename[0,1]=="#" dirname,filename=File.split(filename) filename=File.basename(filename,"*.rb")+".rb" filename=File.join(dirname,filename) unless dirname=="." #p filename #p pathenv filename2=Dyndoc.absolute_path(filename,pathenv) #puts "names";p names if filename2 helpers << File.read(filename2) << "\n" else puts "WARNING: helper #{filename} is unreachable in #{pathenv}!" end end } #p helpers Dyndoc::Ruby::Helpers.module_eval(helpers) end end
# File lib/dyndoc/base/tmpl/eval.rb, line 46 def eval_PARENT(env,filter) filter.envir.local[:prev]=@envirs[env] if @envirs[env] #p "PARENT#{env}";p filter; p "\n" end
# File lib/dyndoc/base/tmpl/eval.rb, line 87 def eval_RCODE(code,filter,opts={:pretty => true}) #pretty=true,capture=nil) #Dyndoc.warn "eval_RCODE",p code #Dyndoc.warn "rEnvir[0]",@rEnvir[0] #;"print(ls(.env4dyn$#{@rEnvir[0]}))".to_R #Dyndoc.warn "output",RServer.output(code.strip,@rEnvir[0],pretty) Utils.clean_eol(code) #puts "eval_RCODE";p RServer.safe_output(code,@rEnvir[0],pretty,capture) return filter.convert(RServer.safe_output(code,@rEnvir[0],opts),"#") end
# File lib/dyndoc/base/tmpl/eval.rb, line 102 def eval_RbCODE(code,filter,opts={}) #p @rbEnvir[0];p filter.apply(code) #puts "code";p code if code[0,1]=="<" i=(code=~/>/) envir,code=code[1...i],code[(i+1)..-1] #p envir #p code envir=(envir.empty? ? TOPLEVEL_BINDING : eval(envir)) #p envir opts[:error] = "RbCode Error" return filter.convert(RbServer.output(code,envir,opts),"#") else opts[:error] = "RbCode Error" return filter.convert(RbServer.output(code,@rbEnvir[0],opts),"#") end end
# File lib/dyndoc/base/tmpl/eval.rb, line 56 def eval_SET(var,txt,filter,newline=nil) ## apply R filtering #puts "SET";p var; p txt key=filter.apply(var) key,opt=key.scan(/([#{FilterManager.letters}]+)\s*(!?\+?\??)/).flatten key=filter.envir.keyMeth(key) #puts "SET:key";p key;p Envir.to_keys(key);p opt #p filter.envir.local #p filter.envir.elt_defined?(Envir.to_keys(key)) txt=filter.apply(txt) #puts "SET:txt";p txt curElt=((opt.include? "!") ? filter.envir.elt_defined?(Envir.to_keys(key),true) : Envir.elt_defined?(filter.envir.local,Envir.to_keys(key),true) ) #puts "curElt"; p curElt #puts "curElt if opt?"; p curElt if opt.include? "?" return if curElt and opt.include? "?" if key and curElt if opt.include? "+" curElt[:val][0] << txt else txt=[txt] if curElt[:attr] and curElt[:attr].include? :array curElt[:val][0] =txt end curElt[:val][0] << "\n" if newline and !(curElt[:attr] and curElt[:attr].include? :array) else #unless ! in opt only local key=":"+key unless opt.include? "!" #puts "SET:new key";p key;p txt filter.envir[key]=txt end end
# File lib/dyndoc/plugins/tex/tex_eval.rb, line 51 def eval_TEX_TITLE(filter) ## _BEGINDOC_ already declared in DefaultPre_tmpl.tex if filter.envir.global["_BEGINDOC_"] and filter.envir.global["_BEGINDOC_"][:val][0].scan(/\\maketitle/).empty? filter.envir.global["_BEGINDOC_"][:val][0] << "\n" unless filter.envir.global["_BEGINDOC_"][:val][0].empty? filter.envir.global["_BEGINDOC_"][:val][0] << "\\maketitle" end end
# File lib/dyndoc/base/tmpl/eval.rb, line 8 def eval_TXT(b,filter,strip=@strip) b.delete_if{|s| !s.scan(/^\s*%%%/).empty?} unless @echo>0 if b.length>0 txt=b.map{|l| l2=filter.apply(l) if (l.strip).scan(/^\#\{.*\}$/).empty? l2 else ## do not deal with empty result!!! l2 unless l2.empty? end }.compact #p "txt";p txt txt.map!{|l| l.lstrip} if strip #p "txt2";p txt txt=txt.join("\n") else txt=nil end return txt end
# File lib/dyndoc/base/tmpl/eval.rb, line 30 def eval_VARS(b,filter) ## apply R filtering ##b=b.map{|e| filter.apply(e)} -> apply to each line!! ## read the bloc dict=FilterManager.eval_dict(b,true) #puts "eval_VARS:dict";p dict filter.import_dict(dict) #puts "eval_VARS:filter";p filter.envir.local end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 169 def eval_args(blck,filter) @rbEnvir[0].eval(parse(blck[1..-1],filter)) end
# File lib/dyndoc/base/tmpl/eval.rb, line 522 def eval_func(call,code,rbEnvir) ##p call;p code key,args=call.strip.split(/\|/) #no longer ":" key.strip! #p "@calls[#{key}]" @args[key]=args.split(",").map{|e| e.strip} if args #p @args[key];p code @calls[key]=code @rbEnvir4calls={} unless @rbEnvir4calls @rbEnvir4calls[key]=rbEnvir if rbEnvir #p @rbEnvir4calls end
# File lib/dyndoc/base/tmpl/eval.rb, line 535 def eval_meth(call,code) #p call key,args=call.strip.split(/\|/) #no longer ":" args=(args ? "self,"+args : "self") key.strip! key2,klass=key.split(".") #p "@calls[#{key}]" #p key2;p klass @args[key]=args.split(",").map{|e| e.strip} #p @args[key] #p code @calls[key]=code #this is a method! @calls[key2]=:meth @meths << key2 @meths.uniq! #p @meths @args[key2]=["self"] =begin #update method parameters if @args[key2] #update (only the first common parameters, the rest have to be named to be used) ok=true @args[key2]=(0...([@args[key].length,@args[key2].length].min)).map{|i| ok&=(@args[key][i]==@args[key2][i]);@args[key][i] if ok }.compact else #first init @args[key2]=@args[key] end =end #p @calls #puts "args[new]";p @args["new"] #p @meths end
# File lib/dyndoc/base/tmpl/eval.rb, line 96 def eval_rout(code,filter) #p code Utils.clean_eol(code) return RServer.rout(code,@rEnvir[0]) end
# File lib/dyndoc/base/tmpl/manager.rb, line 147 def extract_var(id) @vars.extract(id) end
format helpers
# File lib/dyndoc/base/tmpl/parse_do.rb, line 297 def format(which=:all) formats={ :output => outputFormat, :blck => blockFormat, :parent => parentFormat, :default => defaultFormat, :current => currentFormat } which==:all ? formats : formats[which] end
# File lib/dyndoc/base/tmpl/manager.rb, line 191 def format_output=(format) @fmtOutput=format end
# File lib/dyndoc/base/tmpl/oop.rb, line 6 def get_klass(klass) return klass.split(",").map{|e| e.strip} end
# File lib/dyndoc/base/tmpl/oop.rb, line 10 def get_method(call,klass0) i,bCall=-1,nil klass=klass0+["Object"] #p call;p klass;p call+"."+klass[i+1];p @calls.keys bCall=@calls[call+"."+klass[i+=1]] until bCall or i==klass0.length if bCall @meth,@klasses= call.dup,klass @called = call << "."+ (@meth_klass=klass[i]) end return bCall end
new syntax: [#>] tag1,tag2,… > var […]
# File lib/dyndoc/base/tmpl/parse_do.rb, line 241 def get_named_blck(b2,filter) vars=nil #default: no named block! if b2[0][0]==:named vars=filter.apply(b2[0][1].strip) vars.gsub!("#",@Fmt) b2=b2[0][2..-1] if vars.include? ">" fmts,vars=vars.split(">") b2=nil unless fmts.split(",").map{|e| e.strip}.include? @fmt #TODO: changer et mettre la condition sur les tags!!!! et non uniquement sur le format! #HOWTO: b2 non nil s'il existe un document pour lequel cette partie est à évaluer! else #if a variable ends with FORMATS element if (ind=vars.rindex(/(#{Dyndoc::FORMATS.join("|")})$/)) #do not evaluate unless right format b2=nil unless vars[ind..-1]==@Fmt end end end return [vars,b2] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 263 def get_named_blck_simple(b2,filter) vars=nil #default: no named block! if b2[0][0]==:named vars=filter.apply(b2[0][1].strip) b2=b2[0][2..-1] end return [vars,b2] end
# File lib/dyndoc/base/tmpl/oop.rb, line 22 def get_super_method(parent=1) (@klasses.map{|e| @meth+"."+e} & @calls.keys)[parent] end
# File lib/dyndoc/base/tmpl/manager.rb, line 170 def init_doc(doc_cfg) @cfg=doc_cfg # register format @fmt=@cfg[:format_doc].to_s.downcase @Fmt=@fmt.capitalize ##Dyndoc.warn "@cfg",@cfg @fmtOutput=@cfg[:format_output].to_s if @cfg[:format_output] @fmtOutput=@fmt if @fmt and ["html","tex","odt","tm"].include? @fmt @dyndocMode=:cmdline @global={} @filterGlobal=FilterManager.global(self) #global filter needed to affect object before parsing the main document! @blocks,@libs,@calls,@args,@meths,@def_blck={},{},{},{},[],[] CallFilter.init(self,@calls,@args,@meths) @filter=nil @tags=[] @keys={} @alias={} @savedBlocks={} require_first if @@interactive end
TO REMOVE????
# File lib/dyndoc/base/tmpl/manager.rb, line 309 def init_dtag(tmpl) dtag=tmpl.scan(/(?:#{@cfg[:dtags].map{|e| "_#{e}_" }.join("|")})/)[0] #p dtag return @dtag=(dtag ? dtag[1...-1].to_sym : @cfg[:dtag]) end
# File lib/dyndoc/base/tmpl/manager.rb, line 224 def init_keys @init_keys=KeysManager.init_keys((@cfg[:keys_doc]+@tmpl_cfg[:keys_tmpl]).uniq) #puts "Manager:init_keys";p @init_keys end
# File lib/dyndoc/base/tmpl/manager.rb, line 230 def init_model(input) @pre_doc,@post_doc,@pre_model,@post_model=[],[],[],[] if @cfg[:model_doc] and Dyndoc.cfg_dir[:tmpl_path][@cfg[:format_doc]] @cfg[:model_doc]="Default" if @cfg[:model_doc].downcase=="default" model_doc=File.join("Model",Dyndoc.cfg_dir[:tmpl_path][ @cfg[:format_doc]],@cfg[:model_doc]) @pre_model << File.read(Dyndoc.doc_filename(model_doc+"Pre")) @post_model = [File.read(Dyndoc.doc_filename(model_doc+"Post"))] #p @pre_model #p @post_model end ## sort with respect to priority number and filter @cfg[:pre_doc] += input.scan(/\[\#(?:plugin|preload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten #p @cfg[:pre_doc] input.gsub!(/\[\#(?:plugin|preload)\][^\[]*/m,"") @cfg[:pre_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten! ## sort with respect to priority number and filter @cfg[:post_doc] += input.scan(/\[\#(?:postload)\]([^\[]*)/m).flatten.map{|e| e.strip.split("\n").map{|e2| e2.strip}}.flatten input.gsub!(/\[\#(?:postload)\][^\[]*/m,"") @cfg[:post_doc].sort!.map!{|e| e.scan(/^\d*(.*)/)}.flatten! #p @cfg[:pre_doc] if @cfg[:pre_doc] @cfg[:pre_doc].uniq.each{|t| @pre_doc << File.read(Dyndoc.doc_filename(t)) } end #p @pre_doc if @cfg[:post_doc] @cfg[:post_doc].uniq.each{|t| @post_doc << File.read(Dyndoc.doc_filename(t)) } end end
init output
# File lib/dyndoc/base/tmpl/manager.rb, line 204 def init_path(input) ##read in the main doc paths to include! Dyndoc.setRootDoc(@cfg[:rootDoc],input.scan(/%%%path\((.*)\)/).flatten.map{|e| e.split(",")}.flatten.map{|e| e.strip.downcase}.join(":")) p @cfg[:rootDoc] if @cfg[:cmd]==:cfg end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2384 def keys_compare(e1,e2) i,res=0,0 #p @keys["order"] while res ==0 and i<@keys["order"].length a=@keys["order"][i] #puts "a";p a res=a[:order]*(e1[:lock][a[:val]] <=> e2[:lock][a[:val]]) i+=1 end #because of pb of sort to deal with equality! res=e1[:index]<=>e2[:index] if res==0 res end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2407 def keys_print(tex,texAry) #keys_show(texAry.flatten) if @tmpl_cfg[:debug] texAry=keys_select(texAry.flatten) keys_show(texAry) if @tmpl_cfg[:debug] texAry=keys_sort(texAry) if @keys["order"] #puts "SORTED" #keys_show(texAry) texAry.each{|e| tex << e[:content]} end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2354 def keys_recurse(tex) #puts "keys_recurse: tex";p tex texAry=tex[:content].split(/__DYNKEYS(\d+)__/,-1) if texAry.length==1 tex else (0...texAry.length).map do |i| if i%2==1 keys_recurse($dyn_keys[:tex][texAry[i].to_i]) else {:lock=>tex[:lock],:content=>texAry[i]} end end end end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2378 def keys_select(texAry) texAry.find_all{|e| KeysManager.unlocked?(e[:lock],@keys) } end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2370 def keys_show(texAry) puts "@keys";p @keys texAry.each{|e| p e[:lock] p e[:content] } end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2398 def keys_sort(texAry) texAry.each_with_index{|e,i| e[:index]=i} texAry.sort{|e1,e2| #p e1;p e2 keys_compare(e1,e2) } end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1226 def make_call(blck,filter) code,codename,var={"default"=>[:blck]},"default",[] i=-1 begin case blck[i+=1] when :blck, :"->" #todo: change codename with the arg of blck i,*b2=next_block(blck,i) codename=parse(b2,filter).strip code[codename]=[:blck] when :do,:<,:out,:>,:"r<",:"R<",:"rb<",:"r>",:"r>>",:"R>",:"R>>",:"jl<",:"jl>",:"jl>>",:"rb>",:nl,:"\n",:>>,:"?",:tag,:"??",:"=",:"+",:<<,:"%",:"html>",:"tex>",:"txtl>",:"md>",:"adoc>" #NO :yield because of infinite loops code[codename] << blck[i] i,*b2=next_block(blck,i) code[codename] += b2 when :var,:"," var << blck[i] i,*b2=next_block(blck,i) #puts "var et ,";p b2 var += b2 else var << :"," res=[:named,blck[i].to_s] i,*b2=next_block(blck,i) res += b2 var << res #p var end end while i<blck.length-1 ## IMPORTANT: special treatment for default empty block to avoid infinit loop code["default"] << :out << [:main,""] if code["default"].length==1 code.each_key{|k| code.delete(k) if code[k].length==1 } return [var,code] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1069 def make_def(blck,filter) call=parse_args(blck[1],filter) code,arg,var,rbEnvir=nil,[],[:var],nil i=1 begin case blck[i+=1] when :binding i,*b2=next_block(blck,i) rbEnvir=b2[0][1].strip 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>",:"_>" code = blck[i..-1].unshift(:blck) when :"," i,*b2=next_block(blck,i) #p blck;p b2 #deal with b2=b2[0] if b2[0]==:named =begin if false #Old one! #puts "b2";p b2 b2 << [:main,""] unless b2[2] arg << b2[1] var0=b2[2..-1] var0[0][1]= ":"+b2[1]+"[?]=>" + var0[0][1] var << :"," unless var.length==1 #p var0 var += var0 #next: New one else =end #puts "b2";p b2 # 151108: Adding "!" at the end of the parameter name disables the default ability. This is completed with arg << (b2[1][-1,1]=="!" ? b2[1][0...-1]+"-USER-" : b2[1]) #p arg b2[1]+="?" b2 << [:main,""] unless b2[2] #p b2 var << :"," unless var.length==1 var << b2 #end elsif b2[0]==:main #puts "make_def";p call parse([b2],filter).split(",").map{|v| v.strip}.each{|v| var << :"," unless var.length==1 var << [:named, v+"?" , [:main, ""]] arg << v } #p var #var << b2 end else #just after the arg is a comment and not dealt i,*b2=next_block(blck,i) end end while i<blck.length-1 and !code #if no block code is provided (possible for method) nothing to do is represented by the following code! code=[:blck, :<] unless code code=[code] #puts "var";p var code.unshift(var) unless var.length==1 #puts "code def #{call}";p code call+= ((call.include? "|") ? "," : "|")+arg.join(",") unless arg.empty? return [call,code,rbEnvir] end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1909 def make_do_lang_blck(blck,id,lang=:rb) #p blck cptCode=-1 ## Dyndoc.warn "make_do_lang_blck",blck blck2=blck.map{|b| ## Dyndoc.warn "b",b if b.respond_to? "[]" and [:>,:<,:<<].include? b[0] cptCode+=1 @doLangBlock[id][:code][cptCode]=Utils.escape_delim!(b[1]) codeLangBlock = "Dyndoc.tmpl_mngr.eval"+ lang.to_s.capitalize+"Block(#{id.to_s},#{cptCode.to_s},:#{b[0].to_s},:#{lang})" @doLangBlockEnvs=[0] unless @doLangBlockEnvs #never empty? @doLangBlockEnvs << (doLangBlockEnv=@doLangBlockEnvs.max + 1) @doLangBlock[id][:env] << doLangBlockEnv ## NEW: Special treatment for R code because environment is different from GlobalEnv case lang when :R # first, get the environment codeLangBlock="{.GlobalEnv$.env4dyn$rbBlock#{doLangBlockEnv.to_s} <- environment();.rb(\""+codeLangBlock+"\");invisible()}" # use it to evaluate the dyn block with R stuff! (renv) @doLangBlock[id][:code][cptCode]= "[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}+[#}[#>]"+@doLangBlock[id][:code][cptCode]+"[#<]{#renv]rbBlock#{doLangBlockEnv.to_s}-[#}" when :jl # Nothing since no binding or environment in Julia # Toplevel used codeLangBlock="begin Ruby.run(\""+codeLangBlock+"\") end" @doLangBlock[id][:code][cptCode]= "[#>]"+@doLangBlock[id][:code][cptCode] when :rb ##DEBUG: codeRbBlock="begin $curDyn.tmpl.rbenvir_go_to(:rbBlock#{rbBlockEnv.to_s},binding);p \"rbBlock#{doBlockEnv.to_s}\";p \"rbCode=#{codeRbBlock}\";$result4BlockCode="+codeRbBlock+";$curDyn.tmpl.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end" codeLangBlock="begin Dyndoc.tmpl_mngr.rbenvir_go_to(:rbBlock#{doLangBlockEnv.to_s},binding);$result4BlockCode="+codeLangBlock+";Dyndoc.tmpl_mngr.rbenvir_back_from(:rbBlock#{doLangBlockEnv.to_s});$result4BlockCode; end" end case lang when :R process_r(@doLangBlock[id][:code][cptCode]) when :jl # TODO process_jl(@doLangBlock[id][:code][cptCode]) when :rb process_rb(@doLangBlock[id][:code][cptCode]) end [:main,codeLangBlock] else b end } ## Dyndoc.warn "cptRb",cptRb ## Dyndoc.warn "blck2",blck2 blck2 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 272 def make_named_blck(tex,filter,vars,b2,bang=false) #puts "make_named_blck:b2";p b2 val=parse(b2,filter) #puts "make_named_blck:val";p val # NB: bang is processed only at the end and not in the recursive process of parsing! # The reason is that maybe the form <NAME>! is not correct in some old document! #Dyndoc.warn "make_named_blck:val",[val,process_bang(val),filter.rbEnvir] if bang #DEBUG ONLY: val2=val if bang val=parse(process_bang(val),filter) if bang #Dyndoc.warn "make_named_blck:val2",[val2,val] if bang val=Utils.format_blocktext(val) #puts "format_blocktext:val";p val if vars vars.split(",").each{|var| eval_SET(var.strip,val,filter) } else tex << val.force_encoding("utf-8") end end
# File lib/dyndoc/plugins/tex/tex_eval.rb, line 22 def make_outR(tex,b,i,splitter,filter,header=true) normal= splitter.key[i].nil? if !normal filename=filter.apply(splitter.key[i]).strip normal = ["#","%"].include? filename[0,1] end if normal txt=filter.apply(b[1...-1].map{|l| l.strip}.join("\n")) txt=echo_verb(txt,header) else filename=File.expand_path(filename) if (!File.exist?(filename)) require 'fileutils' tmp=File.dirname(filename) FileUtils.mkdir_p(tmp) unless File.exist? tmp f=File.open(filename,"w") txt=filter.apply(b[1...-1].join("\n")) txt=echo_verb(txt,header) f << txt f.close else txt=File.read(filename) end end tex << "%%" << b[0] << "\n" if @echo>0 tex << txt unless @echo<0 tex << "%%" << b[-1] << "\n" if @echo>0 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1343 def make_style_call(call,obj,blck) b=[:call, [:args, [:main, name_style(call)]], [:main, obj]] unless blck.empty? #call not of the form {@toto@} b += [:","] #if only a block is given without parameter => no comma! => THIS IS NOT POSSIBLE BECAUSE OF THE CODE ARGUMENT! #puts "make_style_call:blck";p blck b += ((blck[0].is_a? Array) ? blck : [blck]) end #puts "make_style_call";p b b end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1324 def make_style_meth(meth,klass,blck) b=[:meth, [:args, [:main, "#{name_style(meth)}.Style#{klass}"]]] b += [:","] if ((blck[0].is_a? Array) and ([:main,:named].include? blck[0][0])) b += blck #p b return b end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1332 def make_style_new(klass,blck) b=[:new, [:args,blck[0]],:of, [:main, "Style#{klass}"]]+blck[1..-1] #puts "make_style_new";p b return b end
def do_TXT(tex,b,i,splitter,filter) out = eval_TXT(b,filter)
p “OUT”;p out
return unless out tex << out << "\n" unless @echo<0 end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 802 def make_var_block(blck,filter,dict=nil) b,i,go=[],-1,true cpt=0 #p blck begin #p blck[i+1] case blck[i+=1] when :var, :"," #p blck[i] i,*b2=next_block(blck,i) #puts "make_var";p i;p b2 #deal with unless b2.empty? name=nil if b2[0][0]==:named b2=b2[0] if b2[0]==:named b2 << [:main,""] unless b2[2] var=b2[2..-1] name=filter.apply(b2[1]) #puts "make_var_block:name";p name #p dict if dict and (name2=dict.find{|v| v=~/^#{name}/}) name=name2 dict.delete(name) end b2=var end end end #p name #p b2 #p dict # DO NOT remove lstrip! Otherwise, there is an error of compilation in test/V3/testECO2.dyn! => README.250808: OK now! The explanation was that is was needed only by @varscan (solved now)! The __STR__ escape the first and last whitespaces #p b2 b2=parse(b2,filter) #.lstrip #.split("\n") #puts "name";p name #puts "b2222";p b2 sep=(dict ? "__ELTS__" : "\n" ) #OLD: unless b2.empty? or b2=~/^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/ unless b2=~ /^:?:[#{FilterManager.letters}]*(?:\[(.*)\])?\s*=?(?:=>|,)/ #puts "ICCIII";p b2 name=(dict ? dict.shift : "var#{cpt+=1}" ) unless name if name #puts "name0";p name #p name[0,1]==":" #puts "name";p name modif,affect="","=>" if name[-1,1]=="?" name=name[0...-1] if name[-1,1]=="!" name=name[0...-1] #p filter.envir.local keys2=Envir.to_keys((name[0,1]=="." ? "self"+name : name)+"-USER-" ) #p keys2 env=Envir.elt_defined?(filter.envir.local,keys2) #p env if env=Envir.elt_defined?(filter.envir.local,keys2) env[keys2[-1][0..-7]]=env[keys2[-1]] env.delete(keys2[-1]) modif=nil b2=nil end #p env #p filter.envir.extract(name) else modif="?" end end if modif if name[-1,1]=="+" name=name[0...-1] modif+="+" end if name[-1,1]=="!" #p "!!!!";p name name=name[0...-1] affect="==>" end name=":"+name unless name[0,1]==":" affect="["+modif+"] "+affect unless modif.empty? #p b2.strip if (arr=@varscan.build_vars(b2.strip)) #the stuff for parsing array #puts "arr";p arr #p b2 b2=arr.map{|k,v| name+"."+k+affect+Utils.protect_blocktext(v) }.join(sep) ## add the order! ## ONLY for list not array! #b2+=sep+name+"._order_"+affect+Utils.protect_blocktext(arr.map{|k,v| k}.join(",")) #p b2 else #puts "named";p b2 b2=name+affect+Utils.protect_blocktext(b2) #see README.250808! end #p b2 end else #puts "b2";p b2 b2=Utils.protect_blocktext(b2) #see README.250808! #p b2 end end #puts "b2:#{name}";p b2 #p b2.split(sep) b += b2.split(sep) if b2 #puts "b";p b end end while i<blck.length-1 #puts "make_var_block";p b return b end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 2435 def make_yield(tex,codename,filter) if @def_blck[-1] and @def_blck[-1].keys.include? codename #codename="default" unless @def_blck[-1].keys.include? codename #p codename #p @def_blck[-1][codename] #p parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename] tex << parse([@def_blck[-1][codename]],filter) if @def_blck[-1][codename] #p filter.envir.local["self"] end end
this allows us to consider independently the calls {#p] and {@p] for user-defined only methods!!!!
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1339 def name_style(call) call=="new" ? call : "_style_"+call end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 173 def next_block(blck,i) b=[] while (i+1<blck.length and blck[i+1].is_a? Array) i+=1 b << blck[i] end return b.unshift(i) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 182 def next_block_until(blck,i,tagset) b=[] while (i+1<blck.length and !(tagset.include? blck[i+1])) i+=1 b << blck[i] end return b.unshift(i) end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 191 def next_block_while(blck,i,tagset) b=[] while (i+1<blck.length and (tagset.include? blck[i+1])) i+=1 b << blck[i] end return b.unshift(i) end
output the result after parsing txt
# File lib/dyndoc/base/tmpl/manager.rb, line 370 def output(input,fromfile=nil) @filename=@tmpl_cfg[:filename_tmpl] input=Dyndoc.input_from_file(@filename=input) if fromfile input=@tmpl_cfg[:lib_dyn_content]+"[#main][#>]"+input unless @tmpl_cfg[:lib_dyn_content].empty? ## fetch the contents of all saved variables! This fasten the compilation! Utils.saved_content_fetch_variables_from_file(@filename,self) #p @filename init_path(input) init_tags(input) init_keys init_model(input) #p input ## 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. #txt="{#document][#content]"+input+"[#}" txt=input #p txt prepare_user_input ## parse the content txt out=prepare_output(txt) prepare_last_output(out) clean_as_is(out) ##p [:output,out] return out end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 308 def outputFormat @fmtOutput end
input = pre_doc.join(“n”) + “n” + input unless pre_doc.empty? input = input + “n” + post_doc.join(“n”) unless post_doc.empty? return input
# File lib/dyndoc/base/tmpl/manager.rb, line 289 def output_post_model #post_doc out_post="" #puts "output_post_model:post doc";p @post_doc unless @post_doc.empty? post_doc="\n"+@post_doc.join("\n") txt= post_doc parse(txt) end unless @post_model.empty? post_model="\n"+@post_model.join("\n") txt= post_model out_post << parse(txt) end #p [:out_post,out_post] return out_post end
# File lib/dyndoc/base/tmpl/manager.rb, line 267 def output_pre_model #pre_doc out_pre="" unless @pre_model.empty? pre_model=@pre_model.join("\n") + "\n" txt= pre_model out_pre << parse(txt) end unless @pre_doc.empty? pre_doc=@pre_doc.join("\n") + "\n" txt= pre_doc parse(txt,@filterGlobal) ##Style declares objects before compiling the document! Object are created in the global envir! end ##p [:out_pre,out_pre] return out_pre end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 324 def parentFormat(level=1) @fmtContainer[level] ? (@fmtContainer[level].to_s)[0...-1] : nil end
insert text between start and stop marks the text is automatically loaded from
# File lib/dyndoc/base/tmpl/parse_do.rb, line 52 def parse(texblock,filterLoc=nil,tags=nil) #Dyndoc.warn "texblock",texblock @scan=DevTagScanner.new(:dtag) unless @scan @varscan=VarsScanner.new unless @varscan #puts "parse";p texblock if texblock.is_a? String texblock=texblock.force_encoding("utf-8") ## Dyndoc.warn "parse",texblock if @@interactive Utils.parse_dyn_block_for_interactive!(texblock) else Utils.parse_raw_text!(texblock,self) end #Dyndoc.warn "After parse_raw_text",texblock #puts "raw_key and raw_text";p Utils.dyndoc_raw_text #escape accolade every time a new text is scanned! Utils.escape!(texblock,CHARS_SET_FIRST) Utils.clean_bom_utf8!(texblock) Utils.silence_warnings do texblock=@scan.process("{#document][#content]" + texblock + "[#document}") end ##Dyndoc.warn "parsed",texblock end #p "texblock";p texblock unless filterLoc filterLoc=FilterManager.new({:global=>@global},self) filterLoc.envir["_FILENAME_CURRENT_"]=@filename.to_s if @filename Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_"],@filename.to_s) if @filename Envir.set_textElt!(filterLoc.envir.global,["_FILENAME_ORIG_"], @tmpl_cfg[:filename_tmpl_orig].to_s) if @tmpl_cfg[:filename_tmpl_orig] Envir.set_textElt!(filterLoc.envir.global,["_PWD_"],Dir.pwd) if @filename #puts "filterLoc";p @filename;p filterLoc.envir["_PWD_"] end Dyndoc.cfg_dir[:current_doc_path]=filterLoc.envir["_PWD_"] || "" ##Dyndoc.warn :current_doc_path,Dyndoc.cfg_dir[:current_doc_path] ##partTag tricks tagsOld=@tags.dup if tags #save @tags @tags+=tags if tags @vars,varsOld=filterLoc.envir,@vars Dyndoc.vars=@vars @filter=filterLoc unless @filter ##root filter out,$outError ="","" #p texblock texblock.map{|b| #p b cmd=b[0].to_s @curCmd=cmd cmd=@@cmdAlias[cmd] if @@cmdAlias.keys.include? cmd #Dyndoc.warn "parse:cmd,b",[cmd,b] @@depth+=1 ## To deactivate, put it inside ~/.dyndoc.yml if Dyndoc.cfg_dyn[:parse_rescue] begin ## Dyndoc.warn "cmd",[cmd,b] method("do_"+cmd).call(out,b,filterLoc) ## Dyndoc.warn [:out,out] if cmd=="eval" rescue $outError << "=> Leaving block depth #{@@depth}: " << "\n" codeText = b.inspect ##Dyndoc.warn "codeText",codeText nbChar=(Dyndoc.cfg_dyn[:nbChar_error]) ? Dyndoc.cfg_dyn[:nbChar_error] : 80 if codeText.length > nbChar codeText=codeText[0..((nbChar*2/3).to_int)]+" ...... "+codeText[(-(nbChar/3).to_int)..-1] end $outError << codeText << "\n" if $outRbError && !$outRbError.empty? $outError << $outRbError << "\n" $outRbError = "" end if @@depth==1 $outError << "=> Exiting abnormally!</code>" << "\n" @@outError << "<pre style='background-color: #EBECE4;'><code>"+$outError+"</code></pre>" << "\n" puts "@@outError: \n"+@@outError #raise SystemExit out << @@outError @@outError="" else @@outError << "<pre style='background-color: #EBECE4;'><code>Dyn Runtime Error\n"+$outError+"</code></pre>" $outError="" if Dyndoc.cfg_dyn[:parse_rescue_mode]==:simple out << @@outError @@outError="" else raise RuntimeError, "Dyn Runtime Error" end end Dyndoc.warn "out #{@@depth} :",$outError ensure @@depth -= 1 end else method("do_"+cmd).call(out,b,filterLoc) end } ##restore old partTag and vars @tags=tagsOld if tags @tags.uniq! @vars=varsOld Dyndoc.vars=@vars #Dyndoc.warn "parse:out",out return out end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 164 def parse_args(blck,filter) ## Dyndoc.warn "parse_args",blck parse(blck[1..-1],filter) end
same as parse except that input is a string and the filterLoc is the current one. Rmk: used in String::to_dyn
# File lib/dyndoc/base/tmpl/parse_do.rb, line 158 def parse_string(input,filterLoc=@filter,tags=[]) init_tags(input) txt=input return parse(txt,filterLoc,tags) end
only once!!! Not like prepare_output
which is called in {#dyn]pre:
# File lib/dyndoc/base/tmpl/manager.rb, line 341 def prepare_last_output(out) #puts "DYNDOC_RAW_TEXT! BEFORE";p out #p Utils.dyndoc_raw_text Utils.dyndoc_raw_text!(out,:clean=>true) #puts "DYNDOC_RAW_TEXT! AFTER";p out return out end
# File lib/dyndoc/base/tmpl/manager.rb, line 315 def prepare_output(txt) ## parse the content txt out=output_pre_model #p out #p Dyndoc.dyn_block[:first] ## dyn_block[:first] called in preloaded libraries! out << parse(Dyndoc.dyn_block[:first]) if Dyndoc.dyn_block[:first] #puts "prepare_output";p out out << parse(txt) #puts "prepare_output";p out ## dyn_block[:last] (for example, used to record some information) out << parse(Dyndoc.dyn_block[:last]) if Dyndoc.dyn_block[:last] out << output_post_model ## escape=true at the end in order to transform undefined variables in Latex!!! ##puts "prepare output: BEFORE apply";puts out out=@filter.apply(out,:post,false,true) if [:tex,:odt,:ttm,:html].include? @cfg[:format_doc] ##p [:prepare_output, out] #escape accolade! Utils.escape!(out,CHARS_SET_LAST) ##puts "prepare output: AFTER Utils.escape!";puts out out=Utils.unprotect_format_blocktext(out) ##p [:prepare_output, out] return out end
# File lib/dyndoc/base/tmpl/manager.rb, line 353 def prepare_user_input ##puts "input";p @cfg[:input];p Dyndoc.cfg_dyn[:user_input] if @cfg[:input] @global["_"]={} unless @global["_"] @cfg[:input].each{|k,v| @global["_"][k.to_s] = {:val=>[v]} } end if Dyndoc.cfg_dyn[:user_input] @global["_"]={} unless @global["_"] Dyndoc.cfg_dyn[:user_input].each{|k,v| @global["_"][k.to_s] = {:val=>[v]} } end end
## DONE: put in Document class ## writing in final file def write(file) #@cfg[:append]="" unless @cfg[:append] out = output(file,true)
puts out
f=File.open(@cfg[:filename_doc],"w") f << out f.close end
# File lib/dyndoc/base/tmpl/manager.rb, line 409 def query_library(libname) init_doc({:format_doc=>:tex}) parse(Dyndoc.input_from_file(libname)) p @calls.keys.sort p @meths.sort end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 29 def rbenvir_back_from(inRb) @rbEnvir.shift if inRb end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 47 def rbenvir_current @rbEnvirs.keys.select{|b| @rbEnvirs[b]==@rbEnvir[0]} end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 40 def rbenvir_get(rbEnvir=nil) rbEnvir=@rbEnvir[0] unless rbEnvir #the current if nil rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer rbEnvir end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 16 def rbenvir_go_to(inRb,envir=nil) if inRb #puts "rbenvir_go_to #{inRb.inspect}" inRb=":new" if ["new","none",":none","nil"].include? inRb @rbEnvirs={} unless @rbEnvirs #p inRb @rbEnvirs[inRb]=rbenvir_new if inRb==":new" or !@rbEnvirs[inRb] @rbEnvirs[inRb]=envir if envir and inRb!=":new" #puts "rbenvir_go_to";p envir @rbEnvir.unshift(@rbEnvirs[inRb]) end end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 6 def rbenvir_init(envir) @rbEnvir=[envir] end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 33 def rbenvir_ls(rbEnvir=nil) rbEnvir=@rbEnvir[0] unless rbEnvir rbEnvir=@rbEnvirs[rbEnvir] if rbEnvir.is_a? Symbol rbEnvir=@rbEnvir[rbEnvir] if rbEnvir.is_a? Integer eval("local_variables",rbEnvir) end
# File lib/dyndoc/base/tmpl/rbenvir.rb, line 10 def rbenvir_new #l'objectif est que comme c'est une méthode toutes les #fonctions de parsing de l'objet sont connues! binding end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1366 def register_style_cmds(cmds,style,force=nil) ## register cmds register_style_init cmds.each{|cmd| @styles[:cmd][cmd]=style if force or !@styles[:cmd][cmd] } end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1355 def register_style_init @styles={:cmd=>{},:class=>{},:alias=>{}} unless @styles end
# File lib/dyndoc/base/tmpl/parse_do.rb, line 1359 def register_style_meth(klass,meth) register_style_init @styles[:class][klass]=[] unless @styles[:class][klass] @styles[:class][klass] << meth @styles[:class][klass].uniq! end
# File lib/dyndoc/base/tmpl/manager.rb, line 199 def reinit @blocks,@libs={},{} end
# File lib/dyndoc/base/tmpl/manager.rb, line 159 def require_dyndoc_libs(libs) libs="{#require]\n"+libs.split("\n").map{|lib| lib.split(",")}.flatten.uniq.join("\n")+"\n[#}\n" parse(libs,@filterGlobal) end
equivalent to :pre_doc for not interactive document
# File lib/dyndoc/base/tmpl/manager.rb, line 152 def require_first require_dyndoc_libs("Dyn/Base") Dyndoc.cfg_dyn[:require_first].each do |libs| require_dyndoc_libs(libs) end end