Changeset 311
- Timestamp:
- 2007-02-24 15:45:58 (2 years ago)
- Files:
-
- trunk/lib/parser/lib/parser.rb (modified) (7 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (2 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (2 diffs)
- trunk/lib/parser/test/zafu.yml (modified) (1 diff)
- trunk/lib/parser/test/zafu_insight.yml (modified) (2 diffs)
- trunk/test/helpers/basic.yml (modified) (1 diff)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/parser/lib/parser.rb
r305 r311 82 82 def render(context={}) 83 83 return '' if context["no_#{@method}".to_sym] 84 return '' unless before_render 84 85 @context = context 85 @context[:name] = @params[:name] if @params[:name] # name param is propagated into children (used to label parts of a large template) 86 # name param is propagated into children (used to label parts of a large template) 87 if name = @params[:name] 88 @params.delete(:name) 89 if @context[:name] 90 @context[:name] << "/#{name}" 91 else 92 @context[:name] = name 93 end 94 if replacer = (@context[:parts] || {})[@context[:name]] 95 new_parts = @context[:parts].dup 96 new_parts.delete(@context[:name]) 97 return replacer.render(context.merge(:parts=>new_parts)) 98 end 99 end 86 100 @result = "" 87 101 @pass = {} # used to pass information to the parent 88 if blocks = @context[@params[:name]]89 # replaced content throught name='..' param90 @context.delete(@params[:name])91 @blocks = blocks92 end93 102 res = nil 94 103 if self.respond_to?("r_#{@method}".to_sym) … … 100 109 res = @result 101 110 elsif !res.kind_of?(String) 102 res = "#{@method}"111 res = @method 103 112 end 104 113 res + @text 114 end 115 116 def r_with 117 return unless part = @params[:part] 118 if @context[:preflight] 119 @pass[:part] = {part => self} 120 "" 121 else 122 r_void 123 end 105 124 end 106 125 … … 108 127 expand_with 109 128 end 129 110 130 alias to_s r_void 111 131 112 def r_with113 return unless @params[:part]114 @pass[@params[:part]] = @blocks115 ""116 end117 118 132 def r_inspect 119 expand_with 133 expand_with(:preflight=>true) 120 134 @blocks = [] 135 @pass.merge!(@parts||{}) 121 136 self.inspect 122 137 end 123 138 124 139 def r_include 125 expand_with 140 expand_with(:preflight=>true) 126 141 @blocks = @included_blocks || @blocks 127 expand_with(@pass) 142 if @parts != {} 143 expand_with(:parts=>@parts) 144 else 145 expand_with 146 end 128 147 end 129 148 … … 142 161 res + "/></span>" 143 162 end 163 end 164 165 def before_render 166 true 144 167 end 145 168 … … 331 354 def expand_with(acontext={}) 332 355 res = "" 333 @pass = {} # current object sees some information from it's direct descendants 356 @pass = {} # current object sees some information from it's direct descendants 357 @parts = {} 334 358 new_context = @context.merge(acontext) 335 359 @blocks.each do |b| … … 338 362 else 339 363 res << b.render(new_context) 340 @pass.merge!(b.pass||{}) 364 if pass = b.pass 365 if pass[:part] 366 @parts.merge!(pass[:part]) 367 pass.delete(:part) 368 end 369 @pass.merge!(pass) 370 end 341 371 end 342 372 end … … 368 398 pass << "#{k.inspect.gsub('"', "'")}=>#{v.inspect.gsub('"', "'")}" 369 399 elsif v.kind_of?(Parser) 370 pass << "#{k.inspect.gsub('"', "'")}=> '<#{v.method}>'"400 pass << "#{k.inspect.gsub('"', "'")}=>['#{v}']" 371 401 else 372 pass << "#{k.inspect.gsub('"', "'")}=> '#{v.inspect.gsub('"', "'")}'"402 pass << "#{k.inspect.gsub('"', "'")}=>#{v.inspect.gsub('"', "'")}" 373 403 end 374 404 end trunk/lib/parser/lib/rules/zafu.rb
r305 r311 5 5 6 6 def render(context={}) 7 @context = context 7 8 @html_tag_done = false 8 res = render_html_tag(super) 9 res = super 10 if (@context[:parts] || {})[@context[:name]] 11 res 12 else 13 render_html_tag(res) 14 end 9 15 end 10 16 trunk/lib/parser/lib/rules/zena.rb
r310 r311 26 26 inline_methods :login_link, :visitor_link, :search_box, :menu, :path_links, :lang_links 27 27 direct_methods :uses_calendar 28 29 def before_render 30 if @params[:store] 31 @context["stored_#{@params[:store]}".to_sym] = node 32 @params.delete(:store) 33 end 34 true 35 end 28 36 29 37 def r_show … … 499 507 end 500 508 501 def r_void502 if @params[:store]503 @context["stored_#{@params[:store]}".to_sym] = node504 end505 expand_with506 end507 508 509 def r_ignore 509 510 @html_tag_done = true trunk/lib/parser/test/parser_test.rb
r305 r311 4 4 def r_hello 5 5 'hello world!' 6 end 7 8 def r_text 9 @params[:text] 6 10 end 7 11 … … 22 26 testfile :zafu, :zafu_asset, :zafu_insight 23 27 def test_single 24 do_test('zafu ', 'do_class_params')28 do_test('zafu_insight', 'simple') 25 29 end 26 30 make_tests trunk/lib/parser/test/zafu.yml
r305 r311 199 199 src: "<z:hello tag='p'/>" 200 200 res: "<p>hello world!</p>" 201 202 name: 203 src: "super: <z:void name='super'>hey <z:text text='ho' name='man'/></z:void>" 204 res: "super: hey ho" 205 206 include_super: 207 src: "include_super: <z:include template='/name'><p do='with' part='super' do='hello'/>" 208 res: "include_super: super: <p>hello world!</p>" 209 210 include_super_man: 211 src: "include_super: <z:include template='/name'><p do='with' part='super/man' do='hello'/>" 212 res: "include_super: super: hey <p>hello world!</p>" 213 214 name_title: 215 src: "title: <h1 do='text' text='dummy' name='title'>blah</h1>" 216 res: "title: <h1>dummy</h1>" 217 218 include_with: 219 src: "include_with: <z:include template='/name/title'><h1 do='with' part='title' do='hello'/></z:include>" 220 res: "include_with: title: <h1>hello world!</h1>" trunk/lib/parser/test/zafu_insight.yml
r304 r311 5 5 with_sub_tags: 6 6 src: "<z:inspect><z:with part='hello'>I say <h3 do='hello'>hello</h3></z:with></z:inspect>" 7 res: "[inspect {< 'hello'=>['I say ', [hello]<h3>hello</h3>[/hello]]}/]"7 res: "[inspect {< 'hello'=>['I say <h3>hello world!</h3>']}/]" 8 8 9 9 menu: … … 13 13 include: 14 14 src: "<z:include template='/menu'><z:with part='a'>do <z:inspect/></z:with></z:include>" 15 res: "var a: do [inspect {> :menu=>'true', :name=>'a' }/]"15 res: "var a: do [inspect {> :menu=>'true', :name=>'a', :parts=>''}/]" trunk/test/helpers/basic.yml
r307 r311 331 331 src: "<ul do='ignore' do='children' do='each' tag='li'><z:link/></ul>" 332 332 res: "" 333 334 name_title: 335 src: "title: <h1 do='show' name='title' attr='name'>blah</h1>" 336 res: "title: <h1>status</h1>" 337 338 include_with: 339 src: "include_with: <z:include template='/name/title'><h1 do='with' part='title' do='show' attr='id'/>" 340 res: "include_with: title: <h1>12</h1>" trunk/test/helpers/test_all.rb
r309 r311 4 4 testfile :relations, :basic 5 5 def test_single 6 do_test(' relations', 'date_select')6 do_test('basic', 'include_with') 7 7 end 8 8
