Changeset 560
- Timestamp:
- 2007-05-21 17:14:10 (2 years ago)
- Files:
-
- trunk/lib/parser/lib/parser.rb (modified) (5 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (1 diff)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (3 diffs)
- trunk/lib/parser/test/zafu_insight.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/parser/lib/parser.rb
r549 r560 141 141 end 142 142 143 def r_with144 return unless part = @params[:part]145 if @context[:preflight]146 @pass[:part] = {part => self}147 ""148 else149 r_void150 end151 end152 153 143 def r_void 154 144 expand_with 145 end 146 147 def r_ignore 155 148 end 156 149 … … 164 157 end 165 158 166 def r_include167 expand_with(:preflight=>true)168 if @parts != {}169 # first definitions in inclusion history have precedence170 expand_with(:parts => (@parts).merge(@context[:parts] || {}), :blocks => @included_blocks)171 else172 expand_with(:blocks => @included_blocks)173 end174 end175 176 159 # basic rule to display errors 177 160 def r_unknown … … 181 164 end 182 165 183 res = "<span class='parser_unknown'>< z:#{@method}#{sp}"166 res = "<span class='parser_unknown'><r:#{@method}#{sp}" 184 167 inner = expand_with 185 168 if inner != '' 186 res + "></span>#{inner}<span class='parser_unknown'>< z:/#{@method}></span>"169 res + "></span>#{inner}<span class='parser_unknown'><r:/#{@method}></span>" 187 170 else 188 171 res + "/></span>" … … 220 203 221 204 def include_template 205 @method = 'void' 206 text = @text 207 222 208 # fetch text 223 text = @text224 209 @options[:included_history] ||= [] 225 210 … … 239 224 enter(:void) # scan fetched text 240 225 if @params[:part] 241 @included_blocks = [find_part(@params[:part])]242 else 243 @included_blocks = @blocks226 included_blocks = [find_part(@blocks, @params[:part])] 227 else 228 included_blocks = @blocks 244 229 end 245 230 246 231 @blocks = [] 247 @text = text232 @text = text 248 233 enter(:void) # normal scan on content 249 end 250 251 def find_part(path) 234 235 # replace 'with' 236 @blocks.each do |b| 237 next if b.kind_of?(String) || b.method != 'with' 238 if target = find_part(included_blocks, b.params[:part]) 239 if target.kind_of?(String) 240 # error 241 elsif b.empty? 242 target.method = 'ignore' 243 else 244 name = target.params[:name] 245 target.replace_with(b) if !target.kind_of?(String) 246 target.params[:name] = name # make sure it is kept during 'replace' 247 end 248 else 249 # part not found 250 end 251 end 252 @blocks = included_blocks 253 end 254 255 def find_part(blocks, path) 252 256 res = self 253 257 found = [] 254 258 path.split('/').reject {|e| e==''}.each do |name| 255 if res = find_name( res.blocks, name)259 if res = find_name(blocks, name) 256 260 found << name 261 blocks = res.blocks 257 262 else 258 263 return "<span class='parser_error'>'#{(found + [name]).join('/')}' not found in template '#{@params[:template]}'</span>" trunk/lib/parser/lib/rules/zafu.rb
r542 r560 77 77 @html_tag_done = true 78 78 (@space_before || '') + res + (@space_after || '') 79 end 80 81 def r_ignore 82 super 83 @html_tag_done = true 84 "" 79 85 end 80 86 trunk/lib/parser/lib/rules/zena.rb
r554 r560 791 791 end 792 792 @context[:trans] ? "(#{res})" : "<%= #{res} %>" 793 end794 795 def r_ignore796 @html_tag_done = true797 ""798 793 end 799 794 trunk/lib/parser/test/parser_test.rb
r548 r560 44 44 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 45 45 def test_single 46 do_test('zafu', 'include_ self')46 do_test('zafu', 'include_part_far_away') 47 47 end 48 48 trunk/lib/parser/test/zafu.yml
r549 r560 160 160 unknown: 161 161 src: "this looks bad: <r:system truc='lala'/>" 162 res: "this looks bad: <span class='parser_unknown'>< z:system truc='lala'/></span>"162 res: "this looks bad: <span class='parser_unknown'><r:system truc='lala'/></span>" 163 163 164 164 check_params: … … 228 228 src: "include_super: <r:include template='/name'><p do='with' part='super/man' do='hello'/>" 229 229 res: "include_super: super: hey <p>hello world!</p>" 230 230 231 include_part_far_away: 232 src: "IPFA: <r:include template='/include/super/man' part='super'/> AFPI." 233 res: "IPFA: hey <p>hello world!</p> AFPI." 234 231 235 name_title: 232 236 src: "title: <h1 do='void' name='title' do='text' text='dummy'>blah <b do='void' name='comment'>nothing</b></h1>" … … 249 253 res: "from ii: keep name: title: <h1>hello world! <i>rabbit</i></h1>" 250 254 251 include_for_reverse:252 src: "from ifr: <r:include template='/name'><r:with part='super/comment'>IFR</r:with></r:include>"253 res: "from ifr: super: hey ho"254 255 255 include_replace_same: 256 256 src: "from IRS: <r:include template='/include/super/man'><span do='with' part='super/man'>goldorak</span></r:include>" 257 257 res: "from IRS: include_super: super: hey <span>goldorak</span>" 258 259 include_reverse:260 src: "from ir: <r:include template='/include/for/reverse'><h1 do='with' part='super'><i do='void' name='comment'>none</i> <r:hello/></h1></r:include>"261 res: "from ir: from ifr: super: <h1><i>IFR</i> hello world!</h1>"262 258 263 259 include_empty: trunk/lib/parser/test/zafu_insight.yml
r540 r560 1 simple:2 src: "<r:inspect><r:with part='a'>this is a</r:with><r:with part='b'>this is b</r:with></r:inspect>"3 res: "[inspect {< 'a'=>['this is a'], 'b'=>['this is b']}/]"4 5 with_sub_tags:6 src: "<r:inspect><r:with part='hello'>I say <h3 do='hello'>hello</h3></r:with></r:inspect>"7 res: "[inspect {< 'hello'=>['I say <h3>hello world!</h3>']}/]"8 9 1 menu: 10 2 src: "var a: <r:set_context menu='true'><r:void name='a'><r:hello/></r:void></r:set_context>" 11 3 res: "var a: hello world!" 12 13 include:14 src: "<r:include template='/menu'><r:with part='a'>do <r:inspect/></r:with></r:include>"15 res: "var a: do [inspect {> :menu=>'true', :name=>'a', :parts=>'ado [inspect {> :preflight=>'true'}/]'}/]"
