Changeset 617
- Timestamp:
- 2007-06-07 17:23:44 (2 years ago)
- Files:
-
- trunk/lib/parser/lib/parser.rb (modified) (8 diffs)
- trunk/lib/parser/lib/rules/zazen.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/zazen.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/parser/lib/parser.rb
r604 r617 46 46 47 47 class Parser 48 attr_accessor :text, :method, :pass, :options, :blocks, :params 48 attr_accessor :text, :method, :pass, :options, :blocks, :params, :name 49 49 50 50 class << self … … 93 93 @options.delete(:mode) 94 94 95 95 96 if opts[:sub] 96 97 @text = text … … 100 101 101 102 start(mode) 103 104 # set name 105 @name = @params[:name] if @params 102 106 103 107 unless opts[:sub] … … 178 182 179 183 def before_render 180 # name param is propagated into children (used to label parts of a large template)181 if @params && (name = @params[:name])182 if @context[:name]183 @context[:name] += "/#{name}"184 else185 @context[:name] = name186 end187 if replacer = (@context[:parts] || {})[@context[:name]]188 return false if replacer.empty?189 replace_with(replacer)190 @params[:name] = name # in case replaced again191 end192 end193 184 true 194 185 end … … 207 198 208 199 def include_template 200 if @options[:part] && @options[:part] == @params[:part] 201 # fetching only a part, do not open this element (same as original caller) as it is useless and will make use loop the loop. 202 @method = 'ignore' 203 enter(:void) 204 return 205 end 209 206 @method = 'void' 210 207 text = @text … … 216 213 217 214 absolute_url += "::#{@params[:part].gsub('/','_')}" if @params[:part] 215 absolute_url += "??#{@options[:part].gsub('/','_')}" if @options[:part] 218 216 if absolute_url 219 217 if @options[:included_history].include?(absolute_url) … … 226 224 227 225 @text = before_parse(@text) 228 enter(:void) # scan fetched text229 226 if @params[:part] 227 part_bak = @options[:part] 228 @options[:part] = @params[:part] 229 enter(:void) # scan fetched text 230 @options[:part] = part_bak 230 231 included_blocks = [find_part(@blocks, @params[:part])] 231 232 else 233 enter(:void) # scan fetched text 232 234 included_blocks = @blocks 233 235 end 234 235 236 @blocks = [] 236 237 @text = text 237 238 enter(:void) # normal scan on content 238 239 239 # replace 'with' 240 240 @blocks.each do |b| … … 274 274 blocks.each do |b| 275 275 next if b.kind_of?(String) 276 return b if b. params[:name]== name277 next if b. params[:name]# bad name276 return b if b.name == name 277 next if b.name # bad name 278 278 if res = find_name(b.blocks,name) 279 279 return res trunk/lib/parser/lib/rules/zazen.rb
r615 r617 97 97 if id =~ /(.*?)#(.*)/ 98 98 id, sharp = *id.split('#') 99 sharp = title if sharp. blank?99 sharp = title if sharp.nil? || sharp == '' 100 100 end 101 101 store @helper.make_link(:title=>title,:id=>id,:sharp=>sharp) trunk/lib/parser/lib/rules/zena.rb
r616 r617 300 300 301 301 def r_inspect 302 ["params: #{@params.inspect}",302 out ["params: #{@params.inspect}", 303 303 "name: #{@context[:name]}", 304 304 "node: #{node}", trunk/lib/parser/test/parser_test.rb
r615 r617 56 56 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 57 57 def test_single 58 do_test('za zen', 'link_sharp_attribute')58 do_test('zafu', 'default_tag') 59 59 end 60 60 trunk/lib/parser/test/zafu.yml
r599 r617 104 104 named_parts: 105 105 src: "named_parts: <r:void><r:void name='lala'>lala</r:void> <r:test name='start'>start from here to <r:hello name='sub'>sub</r:hello></r:test></r:void> ok." 106 res: "named_parts: lala [test {= :name=>'start'} {> :name=>'start'}]start from here to [hello {= :name=>'sub'}]sub[/hello][/test] ok."106 res: "named_parts: lala [test {= :name=>'start'}]start from here to [hello {= :name=>'sub'}]sub[/hello][/test] ok." 107 107 108 108 include_part: … … 113 113 src: "IS: I like <r:void name='sub'>sub <r:hello/></r:void> and <r:include template='/include/self' part='sub'/>" 114 114 res: "IS: I like sub hello world! and sub hello world!" 115 116 a_b_c: 117 src: "<r:void name='a'>A<r:void name='b'>B<r:void name='c'>C</r:void></r:void></r:void>" 118 res: "ABC" 119 120 include_self_included: 121 src: "<r:include template='/a/b/c'><r:with part='a/b'>X<r:include template='/include/self/included' part='a/b/y'/> and <r:void name='y'>Y</r:void></r:with></r:include>" 122 res: "AXY and Y" 115 123 116 124 include_bad_part: … … 279 287 [/test]ok 280 288 281 names:282 src: "<p do='void' name='root'><p do='inspect' name='first'/><p do='inspect' name='second'/></p>"283 res: "<p>[inspect {= :name=>'first'} {> :name=>'root/first'}]<p/>[/inspect][inspect {= :name=>'second'} {> :name=>'root/second'}]<p/>[/inspect]</p>"284 289 285 290 default_tag: trunk/lib/parser/test/zazen.yml
r615 r617 132 132 res: "<p>[make_link id:|23| sharp:|hello| title:|hello|] I love you</p>" 133 133 134 link_sharp_attribute:135 src: '"hello":23#[name] I love you'136 res: "<p>[make_link id:|23| sharp:|[name]| title:|hello|] I love you</p>"137 138 134 wiki_link: 139 135 src: "why use ?ruby? ?"
