Class: Dyndoc::CallFilter
- Inherits:
-
Object
- Object
- Dyndoc::CallFilter
- Defined in:
- lib/dyndoc/base/filter/call.rb
Constant Summary collapse
- @@scan =
StringScanner.new("")
- @@start =
/\\?@[\{\[]/
- @@start2 =
{"{"=>/\{/,"["=>/\[/}
- @@stop =
{"{"=>/\}@?/,"["=>/\]@?/}
Class Method Summary collapse
- .argsMeth(call, b) ⇒ Object
- .filter(str, filter) ⇒ Object
-
.init(tmpl, calls, args, meths) ⇒ Object
Common useful part.
- .isMeth?(call) ⇒ Boolean
- .output(w, filter) ⇒ Object
- .parseArgs(call, args, isMeth = nil) ⇒ Object
- .token(txt) ⇒ Object
Class Method Details
.argsMeth(call, b) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/dyndoc/base/filter/call.rb', line 43 def CallFilter.argsMeth(call,b) meth_args_b=nil if @@meths.include? call meth_args_b=b[1..-1] #for the called method b=b[0,1] end #puts "argsMeth";p call;p b;p meth_args_b return [b,meth_args_b] end |
.filter(str, filter) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dyndoc/base/filter/call.rb', line 111 def CallFilter.filter(str,filter) res=str.dup ##p res deb=nil begin deb,fin=CallFilter.token(res) if deb ##p res[deb..fin] res[deb..fin]= CallFilter.output(res[deb..fin],filter) end end while deb res end |
.init(tmpl, calls, args, meths) ⇒ Object
Common useful part
9 10 11 |
# File 'lib/dyndoc/base/filter/call.rb', line 9 def CallFilter.init(tmpl,calls,args,meths) @@tmpl,@@calls,@@args,@@meths=tmpl,calls,args,meths end |
.isMeth?(call) ⇒ Boolean
39 40 41 |
# File 'lib/dyndoc/base/filter/call.rb', line 39 def CallFilter.isMeth?(call) @@meths.include? call end |
.output(w, filter) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dyndoc/base/filter/call.rb', line 53 def CallFilter.output(w,filter) if w[0,1]=="\\" w[1..-1] else call,args,rest=w.split(/\((.*)\)/) #p call;p args;p rest if args call,args=call[2,call.length-2],args.split(/\||@/).map{|e| e.strip} else call,args=call[2,call.length-3],[] end #puts "call,args";p call; p args args,meth_args=CallFilter.argsMeth(call,args) #puts "call2,args,meth_args";p call;p args;p meth_args CallFilter.parseArgs(call,args) #puts "call3,args";p call;p args res2=@@tmpl.eval_CALL(call,args,filter,meth_args) #puts "res2";p res2 res2 end end |
.parseArgs(call, args, isMeth = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dyndoc/base/filter/call.rb', line 13 def CallFilter.parseArgs(call,args,isMeth=nil) call2= (call[-1,1]=="!" ? call[0...-1] : call) #TODO: pas de "!" à la fin normalement! names=@@args[call2].dup if @@args[call2] names=names[1..-1] if names and isMeth #puts "parseArgs:call,args,names";p call2;p args; p names args.map!{|e| v,k,o,t=e.scan(/(:?)([#{FilterManager.letters}]*)\s*(=?>?)(.*)/).flatten #p [v,k,o,t] if o=="=" ## name=value ":"+k.strip+"=>"+t elsif v==":" and !o.empty? ## :name => value e elsif names and names.length==1 and names[0][-1,1]=="*" ":"+names[0]+"=>"+e elsif names ##no named with names #puts "names";p call;p names; p e p "No enough named parameter!!!" if names.empty? ":"+(names.shift)+"=>"+e else ##no named witout names e end } args.map!{|e| e.split("\n")}.flatten! #puts "parseArgs:args";p args end |
.token(txt) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/dyndoc/base/filter/call.rb', line 85 def CallFilter.token(txt) @@scan.string=txt @@scan.pos=0 deb=nil while @@scan.scan_until(@@start) ##p @@scan.matched;p @@scan.matched.length m=@@scan.matched deb=@@scan.pos-(m.length) end return nil unless deb i=0 m=m[-1,1] while (r0=@@scan.exist?(@@stop[m])) and (r1=@@scan.exist?(@@start2[m])) and (r1<r0) @@scan.scan_until(@@start2[m]) i+=1 end begin i-=1 @@scan.scan_until(@@stop[m]) fin=@@scan.pos - (@@scan.matched.length) end while i>=0 return [deb,fin] end |