Changeset 304
- Timestamp:
- 2007-02-23 09:19:36 (2 years ago)
- Files:
-
- trunk/app/controllers/main_controller.rb (modified) (1 diff)
- trunk/app/models/project.rb (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (4 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (4 diffs)
- trunk/lib/parser/test/zafu_insight.yml (modified) (1 diff)
- trunk/test/helpers/basic.yml (modified) (10 diffs)
- trunk/test/helpers/relations.yml (modified) (1 diff)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
- trunk/test/unit/link_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/main_controller.rb
r251 r304 24 24 @node = secure(Node) { Node.find_by_path(path) } 25 25 end 26 if path == @node.basepath(true) 26 if path == @node.basepath(true).split('/') 27 27 render_and_cache 28 28 else trunk/app/models/project.rb
r285 r304 21 21 # This project's notes 22 22 def notes(opts={}) 23 opts.delete(:conditions) 24 options = {:order=>'log_at DESC', :conditions=>["project_id = ?", self[:id] ]}.merge(opts) 25 @notes ||= secure(Note) { Note.find(:all, options) } 23 options = {:order=>'log_at DESC'}.merge(opts) 24 @notes ||= secure(Note) { Note.find(:all, relation_options(options)) } 26 25 end 27 26 trunk/lib/parser/lib/parser.rb
r281 r304 63 63 64 64 @options = {:mode=>:void, :method=>'void'}.merge(opts) 65 @params = @options[:params] || {}65 @params = @options[:params] 66 66 @method = @options[:method] 67 67 mode = @options[:mode] … … 262 262 263 263 def parse_params(text) 264 return {} unless text 264 265 params = {} 265 266 rest = text.strip trunk/lib/parser/lib/rules/zafu.rb
r303 r304 69 69 if @zafu_tag = @options[:zafu_tag] 70 70 @options.delete(:zafu_tag) 71 @zafu_tag_params = @options[:zafu_tag_params] || {}71 @zafu_tag_params = parse_params(@options[:zafu_tag_params]) 72 72 @options.delete(:zafu_tag_params) 73 73 @zafu_tag_count = 1 … … 82 82 @options.delete(:end_ztag) 83 83 84 if @ method == 'include'85 include_template86 elsif @options[:do]87 opts = {:method=> @options[:do]}84 if @params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 85 # we have a sub 'do' 86 @params = parse_params($1) 87 opts = {:method=>$3, :params=>$4} 88 88 89 89 # the matching zafu tag will be parsed by the last 'do', we must inform it to halt properly : … … 93 93 opts[:end_ztag] = @method 94 94 end 95 96 all_params = @options[:do_params]97 if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/98 # we have a sub 'do'99 match = $~100 opts[:do] = $3101 opts[:do_params] = $4102 opts[:params] = parse_params($1)103 else104 @options.delete(:do_params)105 @options.delete(:do)106 opts[:params] = parse_params(all_params)107 end108 95 make(:void, opts) 109 else 110 if mode == :tag 96 if @method == 'include' 97 include_template 98 end 99 else 100 @params = parse_params(@params) 101 if @method == 'include' 102 include_template 103 elsif mode == :tag 111 104 scan_tag 112 105 else … … 196 189 closed = ($3 != '') 197 190 eat $& 198 all_params = $2 199 opts = {:method=>$1} 200 if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 201 # we have a 'do' 202 match = $~ 203 opts[:do] = $3 204 opts[:do_params] = $4 205 opts[:params] = parse_params($1) 206 else 207 opts[:params] = parse_params(all_params) 208 end 209 if closed 210 make(:void, opts.merge(:text=>'')) 211 else 212 make(:void, opts) 213 end 214 elsif @text =~ /\A<(\w+)([^>]*?)zafu\s*=('|")([^\3]*?[^\\])\3([^>]*?)(\/?)>/ 215 # puts "ZAFU:[#{$&}]}" # zafu param tag 216 eat $& 217 match = $~ 218 all_params = match[5] 219 closed = (match[6] != '') 220 opts = {:method=>match[4], :zafu_tag=>match[1], :zafu_tag_params=>parse_params(match[2])} 221 if all_params =~ /\A([^>]*?)do\s*=('|")([^\2]*?[^\\])\2([^>]*)\Z/ 222 # we have a 'do' 223 match = $~ 224 opts[:do] = $3 225 opts[:do_params] = $4 226 opts[:params] = parse_params($1) 227 else 228 opts[:params] = parse_params(all_params) 229 end 230 if closed 231 make(:void, opts.merge(:text=>'')) 232 else 233 make(:void, opts) 234 end 191 opts = {:method=>$1, :params=>$2} 192 opts.merge!(:text=>'') if $3 != '' 193 make(:void, opts) 194 elsif @text =~ /\A<(\w+)([^>]*?)do\s*=('|")([^\3]*?[^\\])\3([^>]*?)(\/?)>/ 195 # puts "DO:[#{$&}]}" # do tag 196 eat $& 197 opts = {:method=>$4, :zafu_tag=>$1, :zafu_tag_params=>$2, :params=>$5} 198 opts.merge!(:text=>'') if $6 != '' 199 make(:void, opts) 235 200 elsif @zafu_tag && @text =~ /\A<#{@zafu_tag}([^>]*?)(\/?)>/ 236 201 # puts "SAME:[#{$&}]}" # simple html tag same as zafu_tag trunk/lib/parser/lib/rules/zena.rb
r303 r304 522 522 elsif value == 'current' 523 523 conditions << "user_id = '\#{#{node}[:user_id]}'" 524 elsif value == 'visitor' 525 conditions << "user_id = '\#{visitor[:id]}'" 524 526 elsif value =~ /\A\d+\Z/ 525 527 conditions << "user_id = '#{value.to_i}'" trunk/lib/parser/test/zafu.yml
r303 r304 40 40 41 41 zafu_tag: 42 src: "I say <p zafu='hello'>blah blah</p>"42 src: "I say <p do='hello'>blah blah</p>" 43 43 res: "I say <p>hello world!</p>" 44 44 45 45 zafu_tag_count: 46 src: "I say <p zafu='hello'>blah <p>super</p> blah</p> is good"46 src: "I say <p do='hello'>blah <p>super</p> blah</p> is good" 47 47 res: "I say <p>hello world!</p> is good" 48 48 49 49 zafu_tag_closed: 50 src: "I say <p zafu='hello'/> is good"50 src: "I say <p do='hello'/> is good" 51 51 res: "I say <p>hello world!</p> is good" 52 52 53 53 zafu_tag_block: 54 src: "I say <div zafu='test'>this <div>test</div> is ok</div> right?"54 src: "I say <div do='test'>this <div>test</div> is ok</div> right?" 55 55 res: "I say [test]<div>this <div>test</div> is ok</div>[/test] right?" 56 56 57 57 zafu_tag_at_end: 58 src: "I say <div zafu='test'>this <div>test</div> is ok</div>"58 src: "I say <div do='test'>this <div>test</div> is ok</div>" 59 59 res: "I say [test]<div>this <div>test</div> is ok</div>[/test]" 60 60 61 61 zafu_tag_with_ztags: 62 src: "I say <div zafu='test'>this <z:hello/></div>"62 src: "I say <div do='test'>this <z:hello/></div>" 63 63 res: "I say [test]<div>this [hello/]</div>[/test]" 64 64 65 65 zafu_keep_params: 66 src: "I love <div class='truc' id='machin' zafu='test' depth='3'>my wife</div>"66 src: "I love <div class='truc' id='machin' do='test' depth='3'>my wife</div>" 67 67 res: "I love [test {= :depth=>'3'}]<div class='truc' id='machin'>my wife</div>[/test]" 68 68 69 69 zafu_and_ztags: 70 src: "Hey <z:test>this is <p zafu='hello'>ok</p></z:test>"70 src: "Hey <z:test>this is <p do='hello'>ok</p></z:test>" 71 71 res: "Hey [test]this is [hello]<p>ok</p>[/hello][/test]" 72 72 73 73 zafu_same_tag: 74 src: "Hey <p zafu='test'> is <p zafu='hello'>hello <p>cool</p></p></p>"74 src: "Hey <p do='test'> is <p do='hello'>hello <p>cool</p></p></p>" 75 75 res: "Hey [test]<p> is [hello]<p>hello <p>cool</p></p>[/hello]</p>[/test]" 76 76 expand_with: … … 122 122 Some people say <z:hello/> 123 123 Some say <z:include template='menu'/> 124 <ul class='list' zafu='set_context' life='ok'>124 <ul class='list' do='set_context' life='ok'> 125 125 <li>truc</li> 126 126 <li>machin</li> 127 <li zafu='test'>sunny day</li>127 <li do='test'>sunny day</li> 128 128 </ul> 129 129 <z:set_context var='complex'><z:include template='/default/menu'/></z:set_context> … … 158 158 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 159 159 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 160 <title zafu='test'>node title</title>160 <title do='test'>node title</title> 161 161 res: | 162 162 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" … … 181 181 182 182 do_zafu: 183 src: "<p zafu='test' param='yo' do='hello' param='hey'>some thing</p>"183 src: "<p do='test' param='yo' do='hello' param='hey'>some thing</p>" 184 184 res: "[test {= :param=>'yo'}]<p>[hello {= :param=>'hey'}]some thing[/hello]</p>[/test]" 185 185 trunk/lib/parser/test/zafu_insight.yml
r282 r304 4 4 5 5 with_sub_tags: 6 src: "<z:inspect><z:with part='hello'>I say <h3 zafu='hello'>hello</h3></z:with></z:inspect>"6 src: "<z:inspect><z:with part='hello'>I say <h3 do='hello'>hello</h3></z:with></z:inspect>" 7 7 res: "[inspect {< 'hello'=>['I say ', [hello]<h3>hello</h3>[/hello]]}/]" 8 8 trunk/test/helpers/basic.yml
r303 r304 71 71 72 72 zafu_link: 73 src: "<li zafu='link'/>"73 src: "<li do='link'/>" 74 74 res: "<li><a href=\"/oo/projects/cleanWater/page12.html\">status title</a></li>" 75 75 … … 115 115 116 116 title: 117 src: "<h2 zafu='title'>super titre</h2>"117 src: "<h2 do='title'>super titre</h2>" 118 118 tem: "<h2><%= show_title(:node=>@node, :link=>false, :project=>false)%></h2>" 119 119 res: "<h2><span id='v_title12'>status title</span></h2>" 120 120 121 121 show_parent_title: 122 src: "<z:parent><h1 zafu='title'>parent title</h1></z:parent>"122 src: "<z:parent><h1 do='title'>parent title</h1></z:parent>" 123 123 tem: "<% if var1 = @node.relation(\"parent\") -%><h1><%= show_title(:node=>var1, :link=>false, :project=>false)%></h1><% end -%>" 124 124 res: "<h1><span id='v_title11'>Clean Water project</span></h1>" 125 125 126 126 node_id: 127 src: "I (<z:show attr='name'/>) know: <z:node node_id='2'><z:show attr='name'/> with <z:children><span zafu='each' join=', '><z:show attr='name'>child</z:show></span></z:children></z:node>"127 src: "I (<z:show attr='name'/>) know: <z:node node_id='2'><z:show attr='name'/> with <z:children><span do='each' join=', '><z:show attr='name'>child</z:show></span></z:children></z:node>" 128 128 res: "I (status) know: people with <span>ant</span>, <span>lion</span>, <span>tiger</span>" 129 129 … … 145 145 146 146 show_title_options: 147 src: "<h1 class='title' zafu='title' status='true' actions='all'>dummy</h1>"147 src: "<h1 class='title' do='title' status='true' actions='all'>dummy</h1>" 148 148 tem: "<h1 class='title'><div class='s<%= @node.version.status %>'><%= show_title(:node=>@node, :link=>false, :project=>false) + node_actions(:node=>@node, :actions=>\"all\")%></div></h1>" 149 149 res: "/<h1 class='title'><div class='s50'><span id='v_title12'>status title</span><ul class='actions'><li>.*\/z\/version\/edit\/12.*\/images\/page_edit.png'/><\/a><\/li><\/ul><\/div><\/h1>/" … … 164 164 165 165 lang_links: 166 src: "<div id='lang' zafu='lang_links'><a>en</a> | <b>fr</b></div>"166 src: "<div id='lang' do='lang_links'><a>en</a> | <b>fr</b></div>" 167 167 tem: "<div id='lang'><%= lang_links(:node=>@node) %></div>" 168 168 res: "/<div id='lang'><b>en.*test_render.*lang=es.*\|.*test_render.*=en.*fr/" 169 169 170 170 path_links: 171 src: "<div id='path' zafu='path_links'><ul><li><a href='#'>first</a></li> / <li><a href='#'>second</a></li> / <li><a href='#' class='current'>here</a></li></ul></div>"171 src: "<div id='path' do='path_links'><ul><li><a href='#'>first</a></li> / <li><a href='#'>second</a></li> / <li><a href='#' class='current'>here</a></li></ul></div>" 172 172 tem: "<div id='path'><%= path_links(:node=>@node) %></div>" 173 173 res: "/<div id='path'><ul class='path'><li>.*zena.*<li>.*oo\/page8.html.*<li><.*\/projects\/cleanWater.*cleanWater<\/a>.*\/oo\/projects\/cleanWater\/page12.html.*class='current'>status<\/a>/" … … 193 193 194 194 show_author_short: 195 src: "<div class='subtitle' zafu='show_author'><b>SI</b> - 05.12</div>"195 src: "<div class='subtitle' do='show_author'><b>SI</b> - 05.12</div>" 196 196 tem: "<div class='subtitle'><b><%= @node.version.author.initials %></b> - <%= format_date(@node.version.updated_at, \"%m.%d\") %></div>" 197 197 res: "<div class='subtitle'><b>SI</b> - 04.11</div>" … … 203 203 204 204 each_traductions: 205 src: "<z:traductions><ul><li zafu='each'><z:show attr='title'/></li></ul></z:traductions>"205 src: "<z:traductions><ul><li do='each'><z:show attr='title'/></li></ul></z:traductions>" 206 206 tem: "<% if list1 = @node.traductions -%><ul><% list1.each do |var1| -%><li><%= var1[:title] %></li><% end -%></ul><% end -%>" 207 207 res: "<ul><li>Etat des travaux</li></ul>" … … 242 242 context: 243 243 node: 'wiki' 244 src: "<z:children><z:each><li zafu='show' attr='name'>blah</li>\n</z:each><z:add><li>add new</li></z:add><z:form><li><form>this is the form</form></li></z:form></z:children>"244 src: "<z:children><z:each><li do='show' attr='name'>blah</li>\n</z:each><z:add><li>add new</li></z:add><z:form><li><form>this is the form</form></li></z:form></z:children>" 245 245 res: "/<li>bird.*<li>flower.*<li.*toggle.*Node_add.*Node_form.*<li .*Node_form.*style.*none.*Ajax.Request.*input type='hidden' name='template_url' value='/each/add/with/root_Node'/" 246 246 … … 252 252 253 253 set_attribute: 254 src: "<div class='machin' zafu='set_attribute' set_class='node[id]'/><z:set_attribute set_class='s[v_status]'/>"254 src: "<div class='machin' do='set_attribute' set_class='node[id]'/><z:set_attribute set_class='s[v_status]'/>" 255 255 tem: "<div class='node<%= @node[:id] %>'/><div class='s<%= @node.version[:status] %>'/>" 256 256 res: "<div class='node12'/><div class='s50'/>" … … 302 302 context: 303 303 node: 'wiki' 304 src: "<ul zafu='children' do='each' tag='li'><z:show attr='name'/></ul>"304 src: "<ul do='children' do='each' tag='li'><z:show attr='name'/></ul>" 305 305 res: "<ul><li>bird</li><li>flower</li></ul>" 306 306 … … 308 308 context: 309 309 node: 'wiki' 310 src: "<ul zafu='children' do='each' tag='li' do='link'/>"310 src: "<ul do='children' do='each' tag='li' do='link'/>" 311 311 res: "<ul><li><a href=\"/oo/image20.html\">bird</a></li><li><a href=\"/oo/image21.html\">flower</a></li></ul>" trunk/test/helpers/relations.yml
r302 r304 71 71 72 72 author_visitor: 73 src: "<z:pages from='site' author='visitor' ><z:each do='link'/></z:pages>"74 res: "ant, art, collections, lion, menu"73 src: "<z:pages from='site' author='visitor' limit='5'><z:each join=', ' do='show' attr='name'/></z:pages>" 74 res: "ant, lake, myLife, nature, status" trunk/test/helpers/test_all.rb
r303 r304 4 4 testfile :relations, :basic 5 5 def test_single 6 do_test(' basic', 'do_each_do')6 do_test('relations', 'author_visitor') 7 7 end 8 8 make_tests trunk/test/unit/link_test.rb
r299 r304 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 2 class LinkDummy < ActiveRecord::Base 3 class << self4 def parent_class5 LinkDummy6 end7 end8 3 acts_as_secure 9 4 acts_as_multiversioned … … 83 78 @node.add_link('tags', nodes_id(:status) ) 84 79 assert !@node.save, "Cannot save" 85 assert_equal 'invalid target', @node.errors['tag']80 assert_equal 'invalid', @node.errors['tag'] 86 81 end 87 82 … … 487 482 end 488 483 489 def test_alter_hot_for_no_publish_rights 490 LinkDummy.connection.execute "UPDATE nodes SET type='LinkDummy' WHERE id IN (20);" # bird_jpg 491 test_visitor(:ant) 492 @bird = secure(LinkDummy) { LinkDummy.find(nodes_id(:bird_jpg)) } 493 @cleanWater = secure_write(LinkDummy) { LinkDummy.find(nodes_id(:cleanWater)) } 494 assert @bird.can_visible?, "Can alter visible content." 495 assert !@cleanWater.can_visible?, "Cannot alter visible content." 496 assert @cleanWater.can_write?, "Can write in cleanwater" 497 @bird.hot_for = [@cleanWater] 498 assert !@bird.save, "Cannot save" 499 assert_equal "invalid target", @bird.errors[:hot_for] 500 assert_equal 1, @bird.send(:hot_for_for_form, :conditions=>["nodes.id IN (11,19)"]).size 501 test_visitor(:lion) 502 @bird = secure(LinkDummy) { LinkDummy.find(nodes_id(:bird_jpg)) } 503 assert_equal 2, @bird.send(:hot_for_for_form, :conditions=>["nodes.id IN (11,19)"]).size 504 end 505 506 def test_from_option 484 def test_in_option 507 485 test_visitor(:lion) 508 486 @node1 = secure(LinkDummy) { LinkDummy.find(nodes_id(:cleanWater)) } #11 … … 517 495 @node1 = secure(LinkDummy) { LinkDummy.find(nodes_id(:cleanWater)) } 518 496 assert_equal nodes_id(:bird_jpg), @node1.icon[:id] 519 assert_equal 2, @node1.fetch_link(Image.role['icon_for'], :from=>'project').size 520 assert_equal 2, Image.icon_for(:conditions=>["project_id = ?"], @node1[:project_id]) 497 assert_equal 2, @node1.icon(:in=>'project').size 521 498 end 522 499 end
