Changeset 283

Show
Ignore:
Timestamp:
2007-02-20 14:45:52 (2 years ago)
Author:
gaspard
Message:

Added a lot of zafu tags.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/helpers/application_helper.rb

    r281 r283  
    242242    title = (opts[:title] && opts[:title] != '') ? opts[:title] : node.v_title 
    243243    if opts[:id][0..0] == '0' 
    244       link_to title, {:prefix => prefix, :controller => 'main', :action=>'show', :path=>node.fullpath}, :popup=>true 
    245     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('/') 
    247247    end 
    248248  rescue ActiveRecord::RecordNotFound 
  • trunk/app/models/node.rb

    r280 r283  
    131131  def fullpath 
    132132    if self[:fullpath] 
    133       self[:fullpath].split('/') 
     133      self[:fullpath] 
    134134    else 
    135135      if parent 
    136         path = parent.fullpath + [name] 
     136        path = parent.fullpath.split('/') + [name] 
    137137      else 
    138138        path = [] 
    139139      end 
    140140      self.connection.execute "UPDATE #{self.class.table_name} SET fullpath='#{path.join('/')}' WHERE id='#{self[:id]}'" 
    141       path 
     141      path.join('/') 
    142142    end 
    143143  end 
     
    222222  end 
    223223   
     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 
    224235  # Find all children 
    225236  def children 
     
    387398    [self, self.project, self.parent].compact.uniq.each do |obj| 
    388399      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
    390401        filepath = "#{filepath}.html" 
    391402        if File.exist?(filepath) 
  • trunk/app/views/comment/_li_simple.rhtml

    r132 r283  
    11<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> 
    33</li>  
  • trunk/app/views/layouts/popup.rhtml

    r199 r283  
    44<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
    55<head> 
    6   <title><%= @node ? @node.fullpath.join("/") : 'Zena' %></title> 
     6  <title><%= @node ? @node.fullpath : 'Zena' %></title> 
    77  <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
    88  <meta http-equiv="Content-Language" content="fr-fr" /> 
  • trunk/app/views/search/_results.rhtml

    r199 r283  
    2222    <% end %>   
    2323      <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> 
    2525      <p class='result_path'><%= node.rootpath.join('/ ')  %></p> 
    2626      <div class='clear'></div> 
  • trunk/lib/linkable.rb

    r217 r283  
    152152        end 
    153153        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) 
    154160      end 
    155161       
  • trunk/lib/parser/lib/rules/zafu.rb

    r282 r283  
    101101        if @text[1..1] == '/' 
    102102          scan_close_tag 
     103        elsif @text[0..3] == '<!--' 
     104          scan_html_comment 
    103105        else 
    104106          scan_tag 
     
    144146      end 
    145147    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 
    146162   
    147163    def scan_tag 
  • trunk/lib/parser/lib/rules/zena.rb

    r282 r283  
    323323      elsif lang = @params[:lang] 
    324324        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 
    325342      else 
    326343        cond = nil 
     
    345362    end 
    346363     
     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     
    347369    def r_parent 
    348370      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}}") 
    352390    end 
    353391     
     
    355393      return unless check_node_class(:Node) 
    356394      do_list("#{node}.children") 
     395    end 
     396     
     397    def r_pages 
     398      return unless check_node_class(:Node) 
     399      do_list("#{node}.pages") 
    357400    end 
    358401     
     
    417460    end 
    418461     
     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 
    419507    # <z:relation role='hot,project'> = get relation if empty get project 
    420508    # relation ? get ? role ? go ? 
     
    448536    end 
    449537     
     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     
    450544    def list 
    451545      @context[:list] 
     
    462556        "#{param.inspect}=>nil" 
    463557      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 -%>" 
    464564    end 
    465565     
  • trunk/lib/parser/test/parser_test.rb

    r282 r283  
    2222  testfile :zafu, :zafu_asset, :zafu_insight 
    2323  def test_single 
    24     do_test('zafu', 'zafu_tag_with_ztags') 
     24    do_test('zafu', 'html_zafu_comment') 
    2525  end 
    2626  make_tests 
  • trunk/lib/parser/test/zafu.yml

    r282 r283  
    167167  src: "<z:set_context no_test='true'>this is a <z:test>test</z:test>dog</z:set_context>" 
    168168  res: "this is a dog" 
     169   
     170html_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 
     174html_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  
    120120  res: "<h1><span id='v_title11'>Clean Water project</span></h1>" 
    121121 
     122node_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 
     126node_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 
    122130show_bad_attr: 
    123131  src: "my <z:show attr=':name'/>" 
     
    204212  res: "Not a document" 
    205213 
     214case_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 
    206218simple_each: 
    207219  src: "<z:children><z:each><z:show attr='name'/></z:each></z:children>" 
     
    234246  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>" 
    235247  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 
     249set_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  
    22 
    33class HelperTest 
    4   testfile :basic 
     4  testfile :relations #, :basic 
    55  def test_single 
    6     do_test('basic', 'each_traductions') 
     6    do_test('relations', 'tag_for') 
     7    #do_test('basic', 'node_path') 
    78  end 
    89  make_tests 
  • trunk/test/unit/node_test.rb

    r226 r283  
    1818    assert_nil node[:fullpath] 
    1919    node = secure(Node) { Node.find_by_path(['projects', 'wiki']) } 
    20     assert_equal ['projects','wiki'], node.fullpath 
     20    assert_equal 'projects/wiki', node.fullpath 
    2121    node = secure(Node) { Node.find_by_path(['projects', 'wiki']) } 
    2222    assert_equal 'projects/wiki', node[:fullpath] 
     
    2929    assert_nil parent[:fullpath] 
    3030    assert_nil node[:fullpath] 
    31     assert_equal ['projects', 'cleanWater', 'lake'], node.fullpath 
     31    assert_equal 'projects/cleanWater/lake', node.fullpath 
    3232    node.reload 
    33     assert_equal ['projects', 'cleanWater', 'lake'], node[:fullpath].split('/') 
     33    assert_equal 'projects/cleanWater/lake', node[:fullpath] 
    3434    parent.reload 
    35     assert_equal ['projects', 'cleanWater'], parent[:fullpath].split('/') 
     35    assert_equal 'projects/cleanWater', parent[:fullpath] 
    3636  end 
    3737   
     
    7878  end 
    7979   
     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   
    8096  def test_ancestor_in_hidden_project 
    8197    test_visitor(:ant) 
     
    90106    assert ! test_page.new_record? , "Not a new record" 
    91107  end 
    92  
     108   
    93109  def test_new_bad_parent 
    94110    test_visitor(:tiger)