Changeset 304

Show
Ignore:
Timestamp:
2007-02-23 09:19:36 (2 years ago)
Author:
gaspard
Message:

Renamed zafu tags to 'do' tags. Do tags can be nested.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/controllers/main_controller.rb

    r251 r304  
    2424      @node = secure(Node) { Node.find_by_path(path) } 
    2525    end 
    26     if path == @node.basepath(true) 
     26    if path == @node.basepath(true).split('/') 
    2727      render_and_cache 
    2828    else 
  • trunk/app/models/project.rb

    r285 r304  
    2121  # This project's notes 
    2222  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)) } 
    2625  end 
    2726   
  • trunk/lib/parser/lib/parser.rb

    r281 r304  
    6363     
    6464    @options = {:mode=>:void, :method=>'void'}.merge(opts) 
    65     @params  = @options[:params] || {} 
     65    @params  = @options[:params] 
    6666    @method  = @options[:method] 
    6767    mode     = @options[:mode] 
     
    262262   
    263263  def parse_params(text) 
     264    return {} unless text 
    264265    params = {} 
    265266    rest = text.strip 
  • trunk/lib/parser/lib/rules/zafu.rb

    r303 r304  
    6969      if @zafu_tag = @options[:zafu_tag] 
    7070        @options.delete(:zafu_tag) 
    71         @zafu_tag_params = @options[:zafu_tag_params] || {} 
     71        @zafu_tag_params = parse_params(@options[:zafu_tag_params]) 
    7272        @options.delete(:zafu_tag_params) 
    7373        @zafu_tag_count = 1 
     
    8282      @options.delete(:end_ztag) 
    8383       
    84       if @method == 'include' 
    85         include_template 
    86       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
    8888         
    8989        # the matching zafu tag will be parsed by the last 'do', we must inform it to halt properly : 
     
    9393          opts[:end_ztag] = @method 
    9494        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] = $3 
    101           opts[:do_params] = $4 
    102           opts[:params] = parse_params($1) 
    103         else 
    104           @options.delete(:do_params) 
    105           @options.delete(:do) 
    106           opts[:params] = parse_params(all_params) 
    107         end 
    10895        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 
    111104          scan_tag 
    112105        else 
     
    196189        closed = ($3 != '') 
    197190        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) 
    235200      elsif @zafu_tag && @text =~ /\A<#{@zafu_tag}([^>]*?)(\/?)>/ 
    236201        # puts "SAME:[#{$&}]}" # simple html tag same as zafu_tag 
  • trunk/lib/parser/lib/rules/zena.rb

    r303 r304  
    522522          elsif value == 'current' 
    523523            conditions << "user_id = '\#{#{node}[:user_id]}'" 
     524          elsif value == 'visitor' 
     525            conditions << "user_id = '\#{visitor[:id]}'" 
    524526          elsif value =~ /\A\d+\Z/ 
    525527            conditions << "user_id = '#{value.to_i}'" 
  • trunk/lib/parser/test/zafu.yml

    r303 r304  
    4040 
    4141zafu_tag: 
    42   src: "I say <p zafu='hello'>blah blah</p>" 
     42  src: "I say <p do='hello'>blah blah</p>" 
    4343  res: "I say <p>hello world!</p>" 
    4444 
    4545zafu_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" 
    4747  res: "I say <p>hello world!</p> is good" 
    4848 
    4949zafu_tag_closed: 
    50   src: "I say <p zafu='hello'/> is good" 
     50  src: "I say <p do='hello'/> is good" 
    5151  res: "I say <p>hello world!</p> is good" 
    5252 
    5353zafu_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?" 
    5555  res: "I say [test]<div>this <div>test</div> is ok</div>[/test] right?" 
    5656 
    5757zafu_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>" 
    5959  res: "I say [test]<div>this <div>test</div> is ok</div>[/test]" 
    6060 
    6161zafu_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>" 
    6363  res: "I say [test]<div>this [hello/]</div>[/test]" 
    6464 
    6565zafu_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>" 
    6767  res: "I love [test {= :depth=>'3'}]<div class='truc' id='machin'>my wife</div>[/test]" 
    6868 
    6969zafu_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>" 
    7171  res: "Hey [test]this is [hello]<p>ok</p>[/hello][/test]" 
    7272 
    7373zafu_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>" 
    7575  res: "Hey [test]<p> is [hello]<p>hello <p>cool</p></p>[/hello]</p>[/test]"   
    7676expand_with: 
     
    122122    Some people say <z:hello/> 
    123123    Some say <z:include template='menu'/> 
    124       <ul class='list' zafu='set_context' life='ok'> 
     124      <ul class='list' do='set_context' life='ok'> 
    125125        <li>truc</li> 
    126126        <li>machin</li> 
    127         <li zafu='test'>sunny day</li> 
     127        <li do='test'>sunny day</li> 
    128128      </ul> 
    129129    <z:set_context var='complex'><z:include template='/default/menu'/></z:set_context> 
     
    158158    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    159159        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    160     <title zafu='test'>node title</title> 
     160    <title do='test'>node title</title> 
    161161  res: | 
    162162    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     
    181181   
    182182do_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>" 
    184184  res: "[test {= :param=>'yo'}]<p>[hello {= :param=>'hey'}]some thing[/hello]</p>[/test]" 
    185185   
  • trunk/lib/parser/test/zafu_insight.yml

    r282 r304  
    44 
    55with_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>" 
    77  res: "[inspect {< 'hello'=>['I say ', [hello]<h3>hello</h3>[/hello]]}/]" 
    88 
  • trunk/test/helpers/basic.yml

    r303 r304  
    7171 
    7272zafu_link: 
    73   src: "<li zafu='link'/>" 
     73  src: "<li do='link'/>" 
    7474  res: "<li><a href=\"/oo/projects/cleanWater/page12.html\">status title</a></li>" 
    7575 
     
    115115   
    116116title: 
    117   src: "<h2 zafu='title'>super titre</h2>" 
     117  src: "<h2 do='title'>super titre</h2>" 
    118118  tem: "<h2><%= show_title(:node=>@node, :link=>false, :project=>false)%></h2>" 
    119119  res: "<h2><span id='v_title12'>status title</span></h2>" 
    120120 
    121121show_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>" 
    123123  tem: "<% if var1 = @node.relation(\"parent\") -%><h1><%= show_title(:node=>var1, :link=>false, :project=>false)%></h1><% end -%>" 
    124124  res: "<h1><span id='v_title11'>Clean Water project</span></h1>" 
    125125 
    126126node_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>" 
    128128  res: "I (status) know: people with <span>ant</span>, <span>lion</span>, <span>tiger</span>" 
    129129 
     
    145145 
    146146show_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>" 
    148148  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>" 
    149149  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>/" 
     
    164164 
    165165lang_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>" 
    167167  tem: "<div id='lang'><%= lang_links(:node=>@node) %></div>" 
    168168  res: "/<div id='lang'><b>en.*test_render.*lang=es.*\|.*test_render.*=en.*fr/" 
    169169 
    170170path_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>" 
    172172  tem: "<div id='path'><%= path_links(:node=>@node) %></div>" 
    173173  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>/" 
     
    193193   
    194194show_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>" 
    196196  tem: "<div class='subtitle'><b><%= @node.version.author.initials %></b> - <%= format_date(@node.version.updated_at, \"%m.%d\") %></div>" 
    197197  res: "<div class='subtitle'><b>SI</b> - 04.11</div>" 
     
    203203 
    204204each_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>" 
    206206  tem: "<% if list1 = @node.traductions -%><ul><% list1.each do |var1| -%><li><%= var1[:title] %></li><% end -%></ul><% end -%>" 
    207207  res: "<ul><li>Etat des travaux</li></ul>" 
     
    242242  context: 
    243243    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>" 
    245245  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'/" 
    246246   
     
    252252 
    253253set_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]'/>" 
    255255  tem: "<div class='node<%= @node[:id] %>'/><div class='s<%= @node.version[:status] %>'/>" 
    256256  res: "<div class='node12'/><div class='s50'/>" 
     
    302302  context: 
    303303    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>" 
    305305  res: "<ul><li>bird</li><li>flower</li></ul>" 
    306306 
     
    308308  context: 
    309309    node: 'wiki' 
    310   src: "<ul zafu='children' do='each' tag='li' do='link'/>" 
     310  src: "<ul do='children' do='each' tag='li' do='link'/>" 
    311311  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  
    7171 
    7272author_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  
    44  testfile :relations, :basic 
    55  def test_single 
    6     do_test('basic', 'do_each_do') 
     6    do_test('relations', 'author_visitor') 
    77  end 
    88  make_tests 
  • trunk/test/unit/link_test.rb

    r299 r304  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22class LinkDummy < ActiveRecord::Base 
    3   class << self 
    4     def parent_class 
    5       LinkDummy 
    6     end 
    7   end 
    83  acts_as_secure 
    94  acts_as_multiversioned 
     
    8378    @node.add_link('tags', nodes_id(:status) ) 
    8479    assert !@node.save, "Cannot save" 
    85     assert_equal 'invalid target', @node.errors['tag'] 
     80    assert_equal 'invalid', @node.errors['tag'] 
    8681  end 
    8782   
     
    487482  end 
    488483   
    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 
    507485    test_visitor(:lion) 
    508486    @node1 = secure(LinkDummy) { LinkDummy.find(nodes_id(:cleanWater)) } #11 
     
    517495    @node1 = secure(LinkDummy) { LinkDummy.find(nodes_id(:cleanWater)) } 
    518496    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 
    521498  end 
    522499end