Changeset 283
- Timestamp:
- 2007-02-20 14:45:52 (2 years ago)
- Files:
-
- trunk/app/helpers/application_helper.rb (modified) (1 diff)
- trunk/app/models/node.rb (modified) (3 diffs)
- trunk/app/views/comment/_li_simple.rhtml (modified) (1 diff)
- trunk/app/views/layouts/popup.rhtml (modified) (1 diff)
- trunk/app/views/search/_results.rhtml (modified) (1 diff)
- trunk/lib/linkable.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zafu.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (6 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/zafu.yml (modified) (1 diff)
- trunk/test/helpers/basic.yml (modified) (3 diffs)
- trunk/test/helpers/relations.yml (added)
- trunk/test/helpers/test_all.rb (modified) (1 diff)
- trunk/test/unit/node_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/helpers/application_helper.rb
r281 r283 242 242 title = (opts[:title] && opts[:title] != '') ? opts[:title] : node.v_title 243 243 if opts[:id][0..0] == '0' 244 link_to title, {:prefix => prefix, :controller => 'main', :action=>'show', :path=>node.fullpath }, :popup=>true245 else 246 link_to title, :prefix => prefix, :controller => 'main', :action=>'show', :path=>node.fullpath 244 link_to title, {:prefix => prefix, :controller => 'main', :action=>'show', :path=>node.fullpath.split('/')}, :popup=>true 245 else 246 link_to title, :prefix => prefix, :controller => 'main', :action=>'show', :path=>node.fullpath.split('/') 247 247 end 248 248 rescue ActiveRecord::RecordNotFound trunk/app/models/node.rb
r280 r283 131 131 def fullpath 132 132 if self[:fullpath] 133 self[:fullpath] .split('/')133 self[:fullpath] 134 134 else 135 135 if parent 136 path = parent.fullpath + [name]136 path = parent.fullpath.split('/') + [name] 137 137 else 138 138 path = [] 139 139 end 140 140 self.connection.execute "UPDATE #{self.class.table_name} SET fullpath='#{path.join('/')}' WHERE id='#{self[:id]}'" 141 path 141 path.join('/') 142 142 end 143 143 end … … 222 222 end 223 223 224 # This is defined by the linkable lib, we add access to 'root', 'project', 'parent', 'children', ... 225 def relation(method) 226 return nil unless ['root', 'project', 'parent', 'children', 'pages', 'documents', 'documents_only', 'images', 'notes'] || self.class.role[method] 227 self.send(method.to_sym) 228 end 229 230 def root 231 secure(Node) { Node.find(ZENA_ENV[:root_id])} 232 rescue ActiveRecord::RecordNotFound 233 nil 234 end 224 235 # Find all children 225 236 def children … … 387 398 [self, self.project, self.parent].compact.uniq.each do |obj| 388 399 ZENA_ENV[:languages].each do |lang| 389 filepath = File.join(RAILS_ROOT,'public',lang, *(obj.fullpath))400 filepath = File.join(RAILS_ROOT,'public',lang,obj.fullpath) 390 401 filepath = "#{filepath}.html" 391 402 if File.exist?(filepath) trunk/app/views/comment/_li_simple.rhtml
r132 r283 1 1 <li id='comment<%= li_simple[:id] %>' <%= "class='c40' " if li_simple[:status] < Zena::Status[:pub] %>> 2 <a href='<%= url_for(:controller=>'main', :action=>'show', :path=>li_simple.discussion.node.fullpath ) %>'><span class='title'><%= li_simple.title %></span> <span class='sign'><%= li_simple.author_name || li_simple.author.fullname %></span></a>2 <a href='<%= url_for(:controller=>'main', :action=>'show', :path=>li_simple.discussion.node.fullpath.split('/')) %>'><span class='title'><%= li_simple.title %></span> <span class='sign'><%= li_simple.author_name || li_simple.author.fullname %></span></a> 3 3 </li> trunk/app/views/layouts/popup.rhtml
r199 r283 4 4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 5 5 <head> 6 <title><%= @node ? @node.fullpath .join("/"): 'Zena' %></title>6 <title><%= @node ? @node.fullpath : 'Zena' %></title> 7 7 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 8 8 <meta http-equiv="Content-Language" content="fr-fr" /> trunk/app/views/search/_results.rhtml
r199 r283 22 22 <% end %> 23 23 <p class='result_id'><%= node[:id] %></p> 24 <p class='result_name'><%= link_to(node.name, {:controller=>'main', :action=>'show', :path=>node.fullpath , :prefix=>prefix}, :popup=>params[:edit]) %></p>24 <p class='result_name'><%= link_to(node.name, {:controller=>'main', :action=>'show', :path=>node.fullpath.split('/'), :prefix=>prefix}, :popup=>params[:edit]) %></p> 25 25 <p class='result_path'><%= node.rootpath.join('/ ') %></p> 26 26 <div class='clear'></div> trunk/lib/linkable.rb
r217 r283 152 152 end 153 153 return true 154 end 155 156 # calls the method defined with link. This is a wrapper used by templating systems to avoid calling arbitrary methods 157 def relation(method) 158 return nil unless self.class.role[method] 159 self.send(method.to_sym) 154 160 end 155 161 trunk/lib/parser/lib/rules/zafu.rb
r282 r283 101 101 if @text[1..1] == '/' 102 102 scan_close_tag 103 elsif @text[0..3] == '<!--' 104 scan_html_comment 103 105 else 104 106 scan_tag … … 144 146 end 145 147 end 148 149 def scan_html_comment 150 if @text =~ /<!--\|(.*?)-->/m 151 # zafu html escaped 152 eat $& 153 @text = $1 + @text 154 elsif @text =~ /<!--.*?-->/m 155 # html comment 156 flush $& 157 else 158 # error 159 flush 160 end 161 end 146 162 147 163 def scan_tag trunk/lib/parser/lib/rules/zena.rb
r282 r283 323 323 elsif lang = @params[:lang] 324 324 cond = "#{node}.version[:lang] == #{lang.inspect}" 325 elsif node_cond = @params[:node] 326 if node_kind_of?(Node) 327 case node_cond 328 when 'self' 329 cond = "#{node}[:id] == @node[:id]" 330 when 'parent' 331 cond = "#{node}[:id] == @node[:parent_id]" 332 when 'project' 333 cond = "#{node}[:id] == @node[:project_id]" 334 when 'ancestor' 335 cond = "@node.fullpath =~ /\\A\#{#{node}.fullpath}/" 336 else 337 cond = nil 338 end 339 else 340 cond = nil 341 end 325 342 else 326 343 cond = nil … … 345 362 end 346 363 364 def r_root 365 return unless check_node_class(:Node) 366 do_var("secure(Node) { Node.find(ZENA_ENV[:root_id])}") 367 end 368 347 369 def r_parent 348 370 return unless check_node_class(:Node) 349 out "<% if #{var} = #{node}.parent -%>" 350 out expand_with(:node=>var, :node_class=>:Node) 351 out "<% end -%>" 371 do_var("#{node}.parent") 372 end 373 374 def r_project 375 return unless check_node_class(:Node) 376 puts "#{node}.project" 377 do_var("#{node}.project") 378 end 379 380 def r_node 381 return unless check_node_class(:Node) 382 if @params[:node_id] 383 cond = "find_by_id(#{@params[:node_id].inspect})" 384 elsif @params[:path] 385 cond = "find_by_path(#{@params[:path].split('/').inspect})" 386 else 387 return "<span class='zafu_error'>Bad node parameters, should be (node_id or path)</span>" 388 end 389 do_var("secure(Node) { Node.#{cond}}") 352 390 end 353 391 … … 355 393 return unless check_node_class(:Node) 356 394 do_list("#{node}.children") 395 end 396 397 def r_pages 398 return unless check_node_class(:Node) 399 do_list("#{node}.pages") 357 400 end 358 401 … … 417 460 end 418 461 462 def r_set_attribute 463 if @zafu_tag 464 tag = @zafu_tag 465 params = @params.merge(@zafu_tag_params) 466 @zafu_tag_done = true 467 else 468 tag = 'div' 469 params = @params 470 end 471 res_params = {} 472 params.each do |k,v| 473 if k.to_s =~ /^set_(.+)$/ 474 key = $1 475 value = v.gsub(/\[([^\]]+)\]/) do 476 "<%= #{node}#{get_attribute($1)} %>" 477 end 478 res_params[key.to_sym] = value 479 else 480 res_params[k] = v unless res_params[k] 481 end 482 end 483 res = "<#{tag}#{params_to_html(res_params)}" 484 inner = expand_with 485 if inner == '' 486 res + "/>" 487 else 488 res + ">#{inner}</#{tag}>" 489 end 490 end 491 492 # use all other tags as relations 493 def r_unknown 494 "not a node (#{@method})" unless node_kind_of?(Node) 495 out "<% if #{var} = #{list_var} = #{node}.relation(#{@method.inspect}); if #{var}.kind_of?(Array) then #{var} = #{node} else #{list_var} = #{list} end %>" 496 497 klass = Module::const_get(node_class) 498 "not a role (#{@method})" unless role = klass.role[@method] 499 puts klass.role.inspect 500 puts role.inspect 501 if role[:unique] 502 do_var("#{node}.#{@method}") 503 else 504 do_list("#{node}.#{@method}") 505 end 506 end 419 507 # <z:relation role='hot,project'> = get relation if empty get project 420 508 # relation ? get ? role ? go ? … … 448 536 end 449 537 538 def node_kind_of?(klass) 539 klass = Module::const_get(node_class) 540 test_class = klass.kind_of?(Symbol) ? Module::const_get(klass) : klass 541 klass.ancestors.include?(test_class) 542 end 543 450 544 def list 451 545 @context[:list] … … 462 556 "#{param.inspect}=>nil" 463 557 end 558 end 559 560 def do_var(var_finder) 561 out "<% if #{var} = #{var_finder} -%>" 562 out expand_with(:node=>var) 563 out "<% end -%>" 464 564 end 465 565 trunk/lib/parser/test/parser_test.rb
r282 r283 22 22 testfile :zafu, :zafu_asset, :zafu_insight 23 23 def test_single 24 do_test('zafu', ' zafu_tag_with_ztags')24 do_test('zafu', 'html_zafu_comment') 25 25 end 26 26 make_tests trunk/lib/parser/test/zafu.yml
r282 r283 167 167 src: "<z:set_context no_test='true'>this is a <z:test>test</z:test>dog</z:set_context>" 168 168 res: "this is a dog" 169 170 html_comments: 171 src: "<z:test><z:hello/><!-- this is nothing > <z:hello/> --></z:test>" 172 res: "[test][hello/]<!-- this is nothing > <z:hello/> -->[/test]" 173 174 html_zafu_comment: 175 src: "<z:test><z:hello/><!--|this is not a comment <z:hello/> --></z:test>" 176 res: "[test][hello/]this is not a comment [hello/] [/test]" trunk/test/helpers/basic.yml
r282 r283 120 120 res: "<h1><span id='v_title11'>Clean Water project</span></h1>" 121 121 122 node_id: 123 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>" 124 res: "I (status) know: people with <span>ant</span>, <span>tiger</span>, <span>lion</span>" 125 126 node_path: 127 src: "<z:node path='projects/wiki'><z:link/></z:node>" 128 res: "<a href=\"/oo/project19.html\">a wiki with zena</a>" 129 122 130 show_bad_attr: 123 131 src: "my <z:show attr=':name'/>" … … 204 212 res: "Not a document" 205 213 214 case_ancestor: 215 src: "<z:root><z:pages><z:each join=', '><z:case><z:when node='ancestor'><b><z:show attr='name'/></b></z:when><z:else><z:show attr='name'/></z:else></z:case></z:each></z:pages></z:root>" 216 res: "collections, nature, people, <b>projects</b>" 217 206 218 simple_each: 207 219 src: "<z:children><z:each><z:show attr='name'/></z:each></z:children>" … … 234 246 src: "<z:children><z:each><li><z:show attr='name'>blah</z:show> <z:edit>edit</z:edit></li>\n</z:each><z:form><li><form>this is the form</form></li></z:form></z:children>" 235 247 res: "/<li id='_each_edit_with_root_Node20'>bird <a href=\"#\" onclick=\"new Ajax.Request\('\/z\/zafu\/ajax_edit\/20\?template_url=%2Feach%2Fedit%2Fwith%2Froot_Node'.*flower <a href=\"#\" onclick=\"new Ajax.Request\('\/z\/zafu\/ajax_edit\/21\?template_url=%2Feach%2Fedit%2Fwith%2Froot_Node.*edit</a></li>\n/" 248 249 set_attribute: 250 src: "<div class='machin' zafu='set_attribute' set_class='node[id]'/><z:set_attribute set_class='s[v_status]'/>" 251 tem: "<div class='node<%= @node[:id] %>'/><div class='s<%= @node.version[:status] %>'/>" 252 res: "<div class='node12'/><div class='s50'/>" trunk/test/helpers/test_all.rb
r282 r283 2 2 3 3 class HelperTest 4 testfile : basic4 testfile :relations #, :basic 5 5 def test_single 6 do_test('basic', 'each_traductions') 6 do_test('relations', 'tag_for') 7 #do_test('basic', 'node_path') 7 8 end 8 9 make_tests trunk/test/unit/node_test.rb
r226 r283 18 18 assert_nil node[:fullpath] 19 19 node = secure(Node) { Node.find_by_path(['projects', 'wiki']) } 20 assert_equal ['projects','wiki'], node.fullpath20 assert_equal 'projects/wiki', node.fullpath 21 21 node = secure(Node) { Node.find_by_path(['projects', 'wiki']) } 22 22 assert_equal 'projects/wiki', node[:fullpath] … … 29 29 assert_nil parent[:fullpath] 30 30 assert_nil node[:fullpath] 31 assert_equal ['projects', 'cleanWater', 'lake'], node.fullpath31 assert_equal 'projects/cleanWater/lake', node.fullpath 32 32 node.reload 33 assert_equal ['projects', 'cleanWater', 'lake'], node[:fullpath].split('/')33 assert_equal 'projects/cleanWater/lake', node[:fullpath] 34 34 parent.reload 35 assert_equal ['projects', 'cleanWater'], parent[:fullpath].split('/')35 assert_equal 'projects/cleanWater', parent[:fullpath] 36 36 end 37 37 … … 78 78 end 79 79 80 def test_root 81 test_visitor(:ant) 82 node = secure(Node) { nodes(:status) } 83 root = node.root 84 assert_equal 'zena', root[:name] 85 end 86 87 def test_relation 88 test_visitor(:ant) 89 node = secure(Node) { nodes(:status) } 90 assert_equal 'cleanWater', node.relation('parent')[:name] 91 assert_equal 'projects', node.relation('parent').relation('parent')[:name] 92 assert_equal 'zena', node.relation('root')[:name] 93 assert_equal 'art', node.relation('parent').relation('tags')[0][:name] 94 end 95 80 96 def test_ancestor_in_hidden_project 81 97 test_visitor(:ant) … … 90 106 assert ! test_page.new_record? , "Not a new record" 91 107 end 92 108 93 109 def test_new_bad_parent 94 110 test_visitor(:tiger)
