Changeset 1231

Show
Ignore:
Timestamp:
2008-10-20 12:35:06 (3 months ago)
Author:
gaspard
Message:

commit 28e1c8b7f86eac54b947ec8273b6be619e6a8a5a
Author: Gaspard Bucher <gaspard@teti.ch>

Finished implementing pseudo ids for export (path pseudo ids). The path pseudo ids now also work in "select_id" fields (define a link, set parent, etc). state:resolved.

Files:

Legend:

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

    r1217 r1231  
    256256    def template_url(opts={}) 
    257257      @skin_name = opts[:skin]   || (@node ? @node[:skin] : nil) || 'default' 
    258       @skin_name = @skin_name.gsub(/[^a-zA-Z_]/,'') # security 
     258      @skin_name = @skin_name.url_name # security 
    259259      mode      = opts[:mode] 
    260260      format    = opts[:format] || 'html' 
  • trunk/app/controllers/links_controller.rb

    r1103 r1231  
    8686        attrs[k.to_sym] = attributes[k].blank? ? nil : attributes[k] 
    8787      end 
    88       attrs[:id] = secure(Node) { Node.translate_pseudo_id(attributes['other_zip']) } 
     88      attrs[:id] = secure(Node) { Node.translate_pseudo_id(attributes['other_zip'], :id, @node) } 
    8989      attrs 
    9090    end 
  • trunk/app/controllers/nodes_controller.rb

    r1217 r1231  
    2020class NodesController < ApplicationController 
    2121  before_filter :check_is_admin, :only => [:export] 
    22   before_filter :find_node, :except => [:index, :create, :not_found, :catch_all, :search, :attribute
     22  before_filter :find_node, :except => [:index, :create, :not_found, :catch_all, :search
    2323  before_filter :check_path, :only  => [:index, :show] 
    2424  after_filter  :change_lang, :only => [:create, :update, :save_text] 
     
    208208  def import 
    209209    @nodes = secure!(Node) { Node.create_nodes_from_folder(:klass => params[:node][:klass], :archive => params[:node][:archive], :parent => @node) }.values 
    210      
    211     if params[:node][:klass] == 'Skin' 
    212       # update CSS files 
    213       @nodes.each do |n| 
    214         if n.c_ext == 'css' 
    215           v_status = n.v_status 
    216           text     = n.parse_assets(n.v_text, self) 
    217           errors   = n.errors.dup 
    218           n.errors.clear 
    219           n.update_attributes(:v_status => v_status, :v_text => text) 
    220         end 
    221       end 
    222     end 
    223     @nodes 
    224210  end 
    225211   
     
    259245      # '+' are not escaped as they should in ajax query 
    260246      params[:node].sub!(/ +$/) {|spaces| '+' * spaces.length} if params[:node] 
    261       node_id = secure!(Node) { Node.translate_pseudo_id(params[:node])} 
     247      node_id = secure!(Node) { Node.translate_pseudo_id(params[:node], :id, @node)} 
    262248      @node = secure!(Node) { Node.find(node_id) } 
    263249       
  • trunk/app/helpers/application_helper.rb

    r1220 r1231  
    325325      end 
    326326    end 
    327     ZazenParser.new(text,:helper=>self, :node=>(opt[:node] || @node)).render(opt) 
     327    opt[:node] ||= @node 
     328    ZazenParser.new(text,:helper=>self).render(opt) 
    328329  end 
    329330   
     
    334335   
    335336  # Find a node's zip based on a query shortcut. Used by zazen to create a link for ""::art for example. 
    336   def find_node_by_pseudo(string, start_path = nil) 
    337     start_path ||= @node ? @node.fullpath : nil 
    338     secure(Node) { Node.find_node_by_pseudo(string, start_path) } 
     337  def find_node_by_pseudo(string, base_node = nil) 
     338    secure(Node) { Node.find_node_by_pseudo(string, base_node || @node) } 
    339339  end 
    340340   
     
    13061306    if obj == 'link' 
    13071307      if link = instance_variable_get("@#{obj}") 
     1308        node        = link.this 
    13081309        current_obj = link.other 
    13091310      end 
     
    13381339    input_id = opt[:input_id] ? " id='#{params[:input_id]}'" : '' 
    13391340    # we use both 'onChange' and 'onKeyup' for old javascript compatibility 
    1340     update = "new Ajax.Updater('#{name_ref}', '/nodes/attribute?node=' + this.value + '&attr=#{attribute}', {method:'get', asynchronous:true, evalScripts:true});" 
     1341    update = "new Ajax.Updater('#{name_ref}', '/nodes/#{(node || @node).zip}/attribute?node=' + this.value + '&attr=#{attribute}', {method:'get', asynchronous:true, evalScripts:true});" 
    13411342    "<div class='select_id'><input type='text' size='8'#{input_id} name='#{obj}[#{sym}]' value='#{zip}' onChange=\"#{update}\" onKeyup=\"#{update}\"/>"+ 
    13421343    "<span class='select_id_name' id='#{name_ref}'>#{current}</span></div>" 
  • trunk/app/models/data_entry.rb

    r1069 r1231  
    4444        value = attributes[key] 
    4545        if value.kind_of?(String) 
    46           attributes[key] = ZazenParser.new(value,:helper=>self, :node=>self).render(:parse_shortcuts=>true
     46          attributes[key] = ZazenParser.new(value,:helper=>self, :node=>self).render(:translate_ids=>:zip
    4747        end 
    4848      end 
  • trunk/app/models/link.rb

    r1103 r1231  
    2828     
    2929    if attrs['other_zip'] 
    30       other_id = secure(Node) { Node.translate_pseudo_id(attrs['other_zip']) } 
     30      other_id = secure(Node) { Node.translate_pseudo_id(attrs['other_zip'], :id, @node) } 
    3131      rel.other_id = other_id 
    3232      if @side == :source 
  • trunk/app/models/node.rb

    r1219 r1231  
    260260     
    261261    # Find a node's attribute based on a pseudo (id or path). Used by zazen to create a link for ""::art or "":(people/ant) for example. 
    262     def translate_pseudo_id(id, sym = :id, base_path = nil) 
     262    def translate_pseudo_id(id, sym = :id, base_node = nil) 
    263263      if id.to_s =~ /\A\d+\Z/ 
    264264        # zip 
     
    266266        res = Node.connection.execute( "SELECT #{sym} FROM nodes WHERE site_id = #{current_site[:id]} AND zip = '#{id}'" ).fetch_row 
    267267        res ? res[0].to_i : nil 
    268       elsif node = find_node_by_pseudo(id,base_path
     268      elsif node = find_node_by_pseudo(id,base_node
    269269        node[sym] 
    270270      else 
     
    274274     
    275275    # Find a node based on a query shortcut. Used by zazen to create a link for ""::art for example. 
    276     def find_node_by_pseudo(id, base_path = nil) 
     276    def find_node_by_pseudo(id, base_node = nil) 
    277277      raise Zena::AccessViolation if self.scoped_methods == [] 
    278278      str = id.to_s 
     
    283283        offset = $2.to_s.size 
    284284        find(:first, Node.match_query($1.gsub('-',' '), :offset => offset)) 
    285       elsif path = str[/\A\(([^\)]+)\)\Z/,1] 
     285      elsif path = str[/\A\(([^\)]*)\)\Z/,1] 
    286286        if path[0..0] == '/' 
    287287          find_by_path(path[1..-1]) 
    288         elsif base_path 
    289           find_by_path("#{base_path}/#{path}"
     288        elsif base_node 
     289          find_by_path(path.abs_path(base_node.fullpath)
    290290        else 
    291           find_by_path(path) 
     291          # do not use (path) pseudo when there is no base_node (during create_or_update_node for example). 
     292          # FIXME: path pseudo is needed for links... and it should be done here (egg and hen problem) 
     293          nil 
    292294        end 
    293295      end 
     
    435437          name   = "#{$1}#{$4}" 
    436438          lang   = $2.blank? ? nil : $2[1..-1] 
    437           attrs  = defaults.merge(get_attributes_from_yaml(path)) # FIXME: this should be done with proper 'start_path' [#226] 
     439          attrs  = defaults.merge(get_attributes_from_yaml(path)) # FIXME: this should be done with proper 'base_node' [#226] 
    438440          attrs['name']     = name 
    439441          attrs['v_lang']   = lang || attrs['v_lang'] || visitor.lang 
     
    454456           
    455457          # we have a zml file. Create a version with this file 
    456           attrs = defaults.merge(get_attributes_from_yaml(path)) # FIXME: this should be done with proper 'start_path' (= parent.path) [#226] 
     458          attrs = defaults.merge(get_attributes_from_yaml(path)) # FIXME: this should be done with proper 'base_node' (= self) [#226] 
    457459          attrs['name']     = name 
    458460          attrs['v_lang'] ||= lang 
     
    529531        res[current_obj[:id].to_i] = current_obj 
    530532 
    531         res.merge!(create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults, :parent_class => opts[:klass])) if sub_folder && !current_obj.new_record? 
     533        res.merge!(create_nodes_from_folder(:folder => sub_folder, :parent_id => current_obj[:id], :defaults => defaults, :parent_class => opts[:klass], :is_sub => true)) if sub_folder && !current_obj.new_record? 
     534      end 
     535      unless opts[:is_sub] 
     536        res.each do |id,n| 
     537          next unless n.errors.empty? 
     538 
     539          # parse pseudo_ids 
     540          attrs = {} 
     541 
     542          n.export_keys.each do |k| 
     543            orig  = n.send(k) 
     544            trans = n.parse_assets(orig, self) 
     545            if trans != orig 
     546              attrs[k] = trans 
     547            end 
     548          end 
     549 
     550          if attrs != {} 
     551            attrs['v_status'] = n.v_status 
     552            n.update_attributes(attrs) 
     553          end 
     554        end 
    532555      end 
    533556      res 
     
    651674    # Translate attributes from the visitor's reference to the application. 
    652675    # This method translates dates, zazen shortcuts and zips and returns a stringified hash. 
    653     def transform_attributes(new_attributes, start_path = nil) 
     676    def transform_attributes(new_attributes, base_node = nil) 
    654677      res = {} 
    655678      res['parent_id'] = new_attributes[:_parent_id] if new_attributes[:_parent_id] # real id set inside zena. 
     
    664687       
    665688      if !res['parent_id'] && p = attributes['parent_id'] 
    666         res['parent_id'] = Node.translate_pseudo_id(p, :id, start_path) || p 
     689        res['parent_id'] = Node.translate_pseudo_id(p, :id, base_node) || p 
    667690      end 
    668691       
     
    685708        elsif key =~ /^(\w+)_id$/ 
    686709          if key[0..1] == 'd_' 
    687             res[key] = Node.translate_pseudo_id(attributes[key], :zip, start_path) || attributes[key] 
     710            res[key] = Node.translate_pseudo_id(attributes[key], :zip, base_node) || attributes[key] 
    688711          else 
    689             res[key] = Node.translate_pseudo_id(attributes[key],  :id, start_path) || attributes[key] 
     712            res[key] = Node.translate_pseudo_id(attributes[key],  :id, base_node) || attributes[key] 
    690713          end 
    691714        elsif key =~ /^(\w+)_ids$/ 
     
    693716          values = attributes[key].kind_of?(Array) ? attributes[key] : attributes[key].split(',') 
    694717          if key[0..1] == 'd_' 
    695             values.map! {|v| Node.translate_pseudo_id(v, :zip, start_path) } 
     718            values.map! {|v| Node.translate_pseudo_id(v, :zip, base_node) } 
    696719          else 
    697             values.map! {|v| Node.translate_pseudo_id(v,  :id, start_path) } 
     720            values.map! {|v| Node.translate_pseudo_id(v,  :id, base_node) } 
    698721          end 
    699722          res[key] = values.compact 
     
    706729          value = attributes[key] 
    707730          if value.kind_of?(String) 
    708             res[key] = ZazenParser.new(value,:helper=>self, :node=>self).render(:parse_shortcuts=>true) 
     731            res[key] = ZazenParser.new(value,:helper=>self).render(:translate_ids=>:zip, :node=>base_node) 
    709732          else 
    710733            res[key] = value 
     
    716739    end 
    717740 
    718     def get_attributes_from_yaml(filepath, start_path = nil) 
     741    def get_attributes_from_yaml(filepath, base_node = nil) 
    719742      attributes = YAML::load( File.read( filepath ) ) 
    720743      attributes.delete(:_parent_id) 
    721       transform_attributes(attributes, start_path
     744      transform_attributes(attributes, base_node
    722745    end 
    723746     
     
    826849  # Update a node's attributes, transforming the attributes first from the visitor's context to Node context. 
    827850  def update_attributes_with_transformation(new_attributes) 
    828     update_attributes(secure(Node) {Node.transform_attributes(new_attributes)}) 
     851    update_attributes(secure(Node) {Node.transform_attributes(new_attributes, self)}) 
    829852  end 
    830853   
     
    848871      end 
    849872    end 
     873  end 
     874   
     875   
     876  # Parse text content and replace all relative urls ('../projects/art') by ids ('34') 
     877  def parse_assets(text, helper) 
     878    # helper is used in textdocuments 
     879    ZazenParser.new(text,:helper=>helper).render(:translate_ids => :zip, :node=>self) 
     880  end 
     881   
     882  # Parse text and replace ids '!30!' by their pseudo path '!(img/bird)!' 
     883  def unparse_assets(text, helper) 
     884    ZazenParser.new(text,:helper=>helper).render(:translate_ids => :relative_path, :node=>self) 
    850885  end 
    851886   
     
    918953  end 
    919954   
     955  def pseudo_id(root_node, sym) 
     956    case sym 
     957    when :zip 
     958      self.zip 
     959    when :relative_path 
     960      full = self.fullpath 
     961      root = root_node ? root_node.fullpath : '' 
     962      "(#{full.rel_path(root)})" 
     963    end 
     964  end 
    920965   
    921966  # Return save path for an asset (element produced by text like a png file from LateX) 
     
    13181363  def to_yaml 
    13191364    hash = {} 
    1320     export_keys.each do |sym| 
    1321       hash[sym.to_s] = self.send(sym) 
    1322     end 
    1323      
    1324     version.dyn.keys.each do |k| 
    1325       hash["d_#{k}"] = version.dyn[k] 
     1365    export_keys.each do |k| 
     1366      hash[k] = unparse_assets(self.send(k), self) 
    13261367    end 
    13271368     
     
    13311372   
    13321373  def export_keys 
    1333     [:v_title, :v_text] 
     1374    ['v_title', 'v_text'] + version.dyn.keys.map{|k| "d_#{k}"} 
     1375  end 
     1376   
     1377  # This is needed during 'unparse_assets' when the node is it's own helper 
     1378  def find_node_by_pseudo(string, base_node = nil) 
     1379    secure(Node) { Node.find_node_by_pseudo(string, base_node || self) } 
    13341380  end 
    13351381   
  • trunk/app/models/text_document.rb

    r1096 r1231  
    7474   
    7575  # Parse text and replace absolute urls ('/en/image30.jpg') by their relative value in the current skin ('img/bird.jpg') 
    76   def unparse_assets(text
     76  def unparse_assets(text, helper
    7777    res = text.dup 
    7878    ctype = version.content.content_type 
  • trunk/app/models/text_document_content.rb

    r1096 r1231  
    99    node = version.node 
    1010     
    11     # unparse needed in 'export' 
    12     if node.can_parse_assets? 
    13       StringIO.new(node.unparse_assets(version.text)) 
    14     else 
    15       StringIO.new(version.text) 
    16     end 
     11    StringIO.new(version.text) 
    1712  end 
    1813   
  • trunk/config/routes.rb

    r1220 r1231  
    1717   
    1818  map.resources :nodes, 
    19     :collection => { :asearch => :get, :search => :get, :attribute => :get }, 
     19    :collection => { :asearch => :get, :search => :get }, 
    2020    :member =>     { :import => :post, :export => :get, :save_text => :put, 
    2121                     :order => :any, :clear_order => :any, 
    22                      :zafu => :get, :drop => :put } do |nodes| 
     22                     :zafu => :get, :drop => :put, :attribute => :get } do |nodes| 
    2323    nodes.resources :versions,  
    2424                    :name_prefix => nil, 
  • trunk/lib/core_ext/string.rb

    r1217 r1231  
    102102    res 
    103103  end 
     104   
     105  # return a relative path from an absolute path and a root 
     106  def rel_path(root) 
     107    root = root.split('/') 
     108    path = split('/') 
     109    i = 0 
     110    ref  = [] 
     111    while true 
     112      if root == [] 
     113        ref = path 
     114        break 
     115      elsif root[0] == path[0] 
     116        root.shift 
     117        path.shift 
     118      else 
     119        # for each root element left: '..' 
     120        ref = root.map{'..'} + path 
     121        break 
     122      end 
     123    end 
     124    ref.join('/') 
     125  end 
     126   
     127  # return an absolute path from a relative path and a root 
     128  def abs_path(root) 
     129    root = root.split('/') 
     130    path = split('/') 
     131    while path[0] == '..' 
     132      root.pop 
     133      path.shift 
     134    end 
     135    (root + path).join('/') 
     136  end 
    104137 
    105138end 
  • trunk/lib/parser/lib/rules/zazen.rb

    r1219 r1231  
    1111    def r_void 
    1212      @context = {:images => true, :pretty_code=>true, :output => 'html'}.merge(@context) 
    13       @parse_shortcuts = @context[:parse_shortcuts] 
     13      @translate_ids = @context[:translate_ids] 
    1414      @text = @text.gsub("\r\n","\n") # this also creates our own 'working' copy of the text 
    1515      @blocks = "" # same reason as why we rewrite 'store' 
     
    2222      enter(:void) # <== parse here 
    2323       
    24       unless @parse_shortcut
     24      unless @translate_id
    2525        store '</pre>' if @in_space_pre 
    2626         
     
    4747module Zazen 
    4848  module Rules 
    49     PSEUDO_ID_REGEXP = ":[0-9a-zA-Z-]+\\+*|\\([^\\)]+\\)" 
     49    PSEUDO_ID_REGEXP = ":[0-9a-zA-Z-]+\\+*|\\([^\\)]*\\)" 
    5050     
    5151    def start(mode) 
     
    8080        elsif @text[0..0] == '<' 
    8181          flush '<' 
    82         elsif !@in_space_pre && @text[0..2] == "\n\n " && !@parse_shortcut
     82        elsif !@in_space_pre && @text[0..2] == "\n\n " && !@translate_id
    8383          # space preserving paragraphe 
    8484          @in_space_pre = true 
    8585          store "\n\n<pre>" 
    8686          eat 3 
    87         elsif @in_space_pre && @text[0..1] == "\n\n" && !@parse_shortcut
     87        elsif @in_space_pre && @text[0..1] == "\n\n" && !@translate_id
    8888          store "</pre>" 
    8989          while @text[0..0] == "\n" 
     
    9595            flush "\n" 
    9696          end 
    97         elsif @text[0..1] == "\n " && @in_space_pre && !@parse_shortcut
     97        elsif @text[0..1] == "\n " && @in_space_pre && !@translate_id
    9898          store "\n" 
    9999          eat 2 
    100100        elsif @text[0..1] == "\n|" 
    101101          flush "\n|" 
    102         elsif @text[0..0] == "\n" && !@parse_shortcut
     102        elsif @text[0..0] == "\n" && !@translate_id
    103103          if @in_space_pre || @text == "\n" || @text[1..1] == '*' || @text[1..1] == '#' 
    104104            flush "\n" 
     
    128128        if @context[:images] 
    129129          ids = parse_document_ids($1) 
    130           if @parse_shortcut
     130          if @translate_id
    131131            store "![#{ids.join(',')}]!" 
    132132          else 
     
    143143        if @context[:images] 
    144144          ids = parse_document_ids(ids) 
    145           if @parse_shortcut
     145          if @translate_id
    146146            store "!#{style}{#{ids.join(',')}}!" 
    147147          else 
     
    156156        eat $& 
    157157        style, id, other_opts, mode, title_opts, title, link = $1, $2, $3, $4, $5, $6, $8 
    158         if node = @helper.find_node_by_pseudo(id
     158        if node = @helper.find_node_by_pseudo(id, @context[:node]
    159159          if link && link =~ /^(#{PSEUDO_ID_REGEXP})(.*)$/ 
    160160            rest = $2 
    161             if link_node = @helper.find_node_by_pseudo($1
    162               link = link_node[:zip].to_s + rest 
     161            if link_node = @helper.find_node_by_pseudo($1, @context[:node]
     162              link = link_node.pseudo_id(@context[:node], @translate_ids || :zip).to_s + rest 
    163163            end 
    164164          end 
    165165           
    166           if @parse_shortcut
     166          if @translate_id
    167167            if node.kind_of?(Document) 
    168168              # replace shortcut 
    169               store "!#{style}#{node.zip}#{other_opts}#{title_opts}!#{link ? ':' + link : ''}" 
     169              store "!#{style}#{node.pseudo_id(@context[:node], @translate_ids || :zip)}#{other_opts}#{title_opts}!#{link ? ':' + link : ''}" 
    170170            else 
    171171              store $& 
     
    178178            end 
    179179          end 
    180         elsif @parse_shortcut
     180        elsif @translate_id
    181181          store $& 
    182182        else 
     
    190190        if link && link =~ /^(#{PSEUDO_ID_REGEXP})(.*)$/ 
    191191          rest = $2 
    192           if link_node = @helper.find_node_by_pseudo($1
     192          if link_node = @helper.find_node_by_pseudo($1, @context[:node]
    193193            link = link_node[:zip].to_s + rest 
    194194          end 
    195195        end 
    196         if @parse_shortcuts 
     196        if @translate_ids 
     197          if @translate_ids != :zip 
     198            node = @helper.find_node_by_pseudo(id, @context[:node]) 
     199            id = node.pseudo_id(@context[:node], @translate_ids) if node 
     200          end 
    197201          store "!#{style}#{id}#{other_opts}#{title_opts}!#{link ? ':' + link : ''}" 
    198202        else 
     
    209213      if @text =~ /\A"([^"]*)":([0-9]+(_[a-z]+|)(\.[a-z]+|)(#[a-z_\/\[\]]*|))/m 
    210214        #puts "LINK:[#{$&}]" 
    211         if @parse_shortcuts 
     215        if @translate_ids == :zip 
    212216          flush $& 
     217        elsif @translate_ids 
     218          eat $& 
     219          title, id = $1, $2 
     220          node = @helper.find_node_by_pseudo(id, @context[:node]) 
     221          id = node.pseudo_id(@context[:node], @translate_ids) if node 
     222          store "\"#{title}\":#{id}" 
    213223        else 
    214224          eat $& 
     
    225235        eat $& 
    226236        title, pseudo_id, mode_format, mode, format, dash = $1, $2, $3, $4, $5, $6 
    227         if node = @helper.find_node_by_pseudo(pseudo_id
    228           id = "#{node.zip}#{mode_format}" 
    229           if @parse_shortcuts 
     237        if node = @helper.find_node_by_pseudo(pseudo_id, @context[:node]
     238          if @translate_ids 
     239            id = "#{node.pseudo_id(@context[:node], @translate_ids)}#{mode_format}" 
    230240            # replace shortcut 
    231241            store "\"#{title}\":#{id}" 
    232242          else 
     243            id = "#{node.zip}#{mode_format}" 
    233244            if format == '.data' 
    234245              title = "#{node.fullpath}#{mode}.#{node.c_ext}#{dash}" 
     
    242253            store @helper.make_link(:title=>title,:id=>id,:sharp=>sharp,:node=>node) 
    243254          end 
    244         elsif @parse_shortcut
     255        elsif @translate_id
    245256          store $& 
    246257        else 
     
    257268      # puts "BRACKET:[#{@text}]" 
    258269      if @text =~ /\A\[(\w+)\](.*?)\[\/\1\]/m 
    259         if @parse_shortcut
     270        if @translate_id
    260271          flush $& 
    261272        else 
     
    309320      block_counter = -1 
    310321      fulltext.gsub!( /<code([^>]*)>(.*?)<\/code>/m ) do 
    311         if @parse_shortcut
     322        if @translate_id
    312323          @escaped_code << $& 
    313324          block_counter += 1 
     
    343354    def render_code(text) 
    344355      text.gsub!( /\\ZAZENBLOCKCODE(\d+)ZAZENBLOCKCODE\\/ ) do 
    345         if @parse_shortcut
     356        if @translate_id
    346357          @escaped_code[$1.to_i] 
    347358        else 
     
    364375      text.gsub!( /\\ZAZENBLOCKAT(\d+)ZAZENBLOCKAT\\/ ) do 
    365376        code = @escaped_at[$1.to_i] 
    366         if @parse_shortcut
     377        if @translate_id
    367378          '@'+code+'@' 
    368379        else 
     
    385396     
    386397    def parse_document_ids(str) 
     398      meth = :zip || @translate_ids 
    387399      str.split(',').map do |id| 
    388400        if id =~ /\A(#{PSEUDO_ID_REGEXP})/ 
    389           if node = @helper.find_node_by_pseudo($1
     401          if node = @helper.find_node_by_pseudo($1, @context[:node]
    390402            if node.kind_of?(Document) 
    391403              # replace shortcut 
    392               node.zip 
    393             elsif @parse_shortcut
     404              node.send(meth) 
     405            elsif @translate_id
    394406              id  # not a document but do not remove 
    395407            else 
    396408              nil # not a document 
    397409            end 
    398           elsif @parse_shortcut
    399             id 
     410          elsif @translate_id
     411            id  # keep 
    400412          else 
    401413            nil # document not found 
  • trunk/lib/tasks/zena.rake

    r1197 r1231  
    369369                end 
    370370              elsif current['parent'] 
    371                 raise NameError "[#{site} #{k}] Bad parent name '#{current['parent']}' for node '#{name}'." 
     371                raise NameError.new("[#{site} #{k}] Bad parent name '#{current['parent']}' for node '#{name}'.") 
    372372              else 
    373373                # top node 
  • trunk/test/fixtures/import/photos.en.zml

    r1031 r1231  
    11class: Section 
    22v_title: Photos ! 
     3d_foo: A simple "test":(../simple) 
    34v_text: | 
    4   Here are some photos I took during my last vacations, while Zena was running, bug less on thousands of machines without any problem, thanks to all the unit test I took... 
     5  Here are some photos I took during my last vacations, while Zena was running, bug-less on thousands of machines without any problem, thanks to all the unit test I took... 
     6   
     7  !(bird)_med! 
     8   
     9  Testing "links":(../simple) to 'simple'. 
    510   
    611  ![]! 
  • trunk/test/helpers/node_query/filters.yml

    r1169 r1231  
    7272  src: "nodes where name like 'w%' in site" 
    7373  sql: "/name LIKE 'w%'/" 
    74   res: "water, wiki, wiki_skin" 
     74  res: "water, wiki, wikiSkin" 
    7575 
    7676param_filter_tag: 
  • trunk/test/helpers/zazen_test.rb

    r1219 r1231  
    159159    assert_equal "<p>See <a href=\"/oo/projects/cleanWater\"><img src='/en/image30_med.jpg' width='220' height='200' alt='bird' class='med'/></a></p>", zazen('See !:(bird)_med!:(/projects/cleanWater)') 
    160160  end 
     161   
     162  def test_translate_ids 
     163    login(:anon) 
     164    projects = secure!(Node) { nodes(:projects) } 
     165    zena     = secure!(Node) { nodes(:zena) } 
     166    assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.",  
     167           zazen('This "is":33 "a":(projects/wiki) !(projects/wiki/bird)! "link"::lio.', :translate_ids => :zip, :node => zena) 
     168            
     169    assert_equal 'This "is":(../collections/art) "a":(wiki) !(wiki/bird)! "link":(../people/lion).',  
     170           zazen('This "is":33 "a":(/projects/wiki) !30! "link"::lio.', :translate_ids => :relative_path, :node => projects) 
     171            
     172    assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.",  
     173           zazen('This "is":(../collections/art) "a":(wiki) !(wiki/bird)! "link":(../people/lion).', :translate_ids => :zip, :node => projects) 
     174     
     175    assert_equal "This \"is\":33 \"a\":#{nodes_zip(:wiki)} !#{nodes_zip(:bird_jpg)}! \"link\":#{nodes_zip(:lion)}.", 
     176           zazen('This "is":(collections/art) "a":(/projects/wiki) !(/projects/wiki/bird)! "link":(people/lion).', :translate_ids => :zip, :node => zena) 
     177  end 
    161178 
    162179end 
  • trunk/test/helpers/zena_parser/basic.yml

    r1211 r1231  
    486486    node: 'collections' 
    487487  src: "<ol do='pages'><li class='post' alt_class='stripe' do='each' do='[name]'/></ol>" 
    488   res: "<ol><li class='post'>art</li><li class='post stripe'>menu</li><li class='post'>news</li><li class='post stripe'>wiki_skin</li></ol>" 
     488  res: "<ol><li class='post'>art</li><li class='post stripe'>menu</li><li class='post'>news</li><li class='post stripe'>wikiSkin</li></ol>" 
    489489 
    490490each_alternate_class_ajax: 
  • trunk/test/sites/zena/nodes.yml

    r1217 r1231  
    163163  wgroup:          public 
    164164  pgroup:          public 
    165   skin:            wiki_skin 
     165  skin:            wikiSkin 
    166166   
    167167bird_jpg: 
     
    257257  zip:             43 
    258258  class:           Skin 
    259   name:            wiki_skin 
     259  name:            wikiSkin 
    260260  # yes it's not good to have this here but changing it would mess up many tests. 
    261261  parent:          collections 
  • trunk/test/sites/zena/template_contents.yml

    r1217 r1231  
    6565wiki_Node_zafu: 
    6666  node:            wiki_Node_zafu 
    67   skin_name:       wiki_skin 
     67  skin_name:       wikiSkin 
    6868  format:          html 
    6969  tkpath:          N 
     
    7373wiki_Project_changes_xml_zafu: 
    7474  node:            wiki_Project_changes_xml_zafu 
    75   skin_name:       wiki_skin 
     75  skin_name:       wikiSkin 
    7676  format:          xml 
    7777  tkpath:          NPP 
     
    8181wiki_Page_changes_zafu: 
    8282  node:            wiki_Page_changes_zafu 
    83   skin_name:       wiki_skin 
     83  skin_name:       wikiSkin 
    8484  format:          html 
    8585  tkpath:          NP 
  • trunk/test/unit/core_ext_test.rb

    r977 r1231  
    9797    end 
    9898  end 
     99   
     100  def test_abs_rel_path 
     101    { 
     102      'a/b/c/d' => 'd',  
     103      'a/x'     => '../../x', 
     104      'y/z'     => '../../../y/z', 
     105      'a/b/d'   => '../d', 
     106      'a/b/c'   => '', 
     107      }.each do |orig, test_rel| 
     108        rel = orig.rel_path('a/b/c') 
     109        assert_equal rel, test_rel, "'#{orig}' should become the relative path '#{test_rel}'" 
     110        abs = rel.abs_path('a/b/c') 
     111        assert_equal rel, test_rel, "'#{rel}' should become the absolute path '#{orig}'" 
     112    end 
     113     
     114    { 
     115      'a/b/c/d' => 'a/b/c/d',  
     116      'a/x'     => 'a/x', 
     117      }.each do |orig, test_rel| 
     118        rel = orig.rel_path('') 
     119        assert_equal rel, test_rel, "'#{orig}' should become the relative path '#{test_rel}'" 
     120        abs = rel.abs_path('') 
     121        assert_equal rel, test_rel, "'#{rel}' should become the absolute path '#{orig}'" 
     122    end 
     123     
     124    assert_equal "/a/b/c", ''.abs_path('/a/b/c') 
     125  end 
    99126end 
    100127 
  • trunk/test/unit/node_test.rb

    r1219 r1231  
    888888      doc  = n if n[:name] == 'document'     
    889889    end 
    890     simple = secure!(Node) { Node.find_by_name_and_parent_id('simple', parent[:id]) } 
     890    simple = secure!(Node) { Node.find_by_name_and_parent_id('simple', parent[:id]) } 
    891891    photos = secure!(Node) { Node.find_by_name_and_parent_id('photos', parent[:id]) } 
    892892     
     
    903903    assert_equal 'Photos !', photos.v_title 
    904904    assert_match %r{Here are some photos.*!\[\]!}m, photos.v_text 
     905    assert_match %r{!#{bird.zip}_med!}m,     photos.v_text 
     906    assert_match %r{"links":#{simple.zip}}m, photos.v_text 
     907    assert_equal "A simple \"test\":#{simple.zip}", photos.d_foo 
    905908    in_photos = photos.find(:all, 'children') 
    906909    assert_equal 2, in_photos.size 
     
    10101013      assert_kind_of Image, bird 
    10111014    end 
     1015  end 
     1016   
     1017  def test_to_yaml 
     1018    login(:tiger) 
     1019    status = secure!(Node) { nodes(:status) } 
     1020    assert status.update_attributes(:v_status => Zena::Status[:pub], :v_text => "This is a \"link\":#{nodes_zip(:projects)}.", :d_foo => "A picture: !#{nodes_zip(:bird_jpg)}!") 
     1021    yaml = status.to_yaml 
     1022    assert_match %r{v_text:\s+\"?This is a "link":\(\.\./\.\.\)\.}, yaml 
     1023    assert_match %r{d_foo:\s+\"?A picture: !\(\.\./\.\./wiki/bird\)!}, yaml 
    10121024  end 
    10131025   
     
    13351347  def test_translate_pseudo_id_path 
    13361348    login(:lion) 
    1337     lion = secure!(Node) { nodes(:lion) } 
     1349    lion       = secure!(Node) { nodes(:lion) } 
     1350    people     = secure!(Node) { nodes(:people) } 
     1351    cleanWater = secure!(Node) { nodes(:cleanWater) } 
    13381352    assert lion.update_attributes(:name => 'status') 
    1339        # path                           base_path 
     1353       # path                           base_node 
    13401354    { ['(/projects/cleanWater/status)', nil]  => nodes_id(:status),  
    1341       ['(/projects/cleanWater/status)', 'people']  => nodes_id(:status), 
    1342       ['(status)', 'people']  => nodes_id(:lion), 
    1343       ['(status)', 'projects/cleanWater']  => nodes_id(:status), 
     1355      ['(/projects/cleanWater/status)', people]  => nodes_id(:status), 
     1356      ['(status)', people]      => nodes_id(:lion), 
     1357      ['(status)', cleanWater]  => nodes_id(:status), 
    13441358    }.each do |k,v| 
    13451359      assert_equal v, secure(Node) { Node.translate_pseudo_id(k[0],:id,k[1]) }, "'#{k.inspect}' should translate to '#{v}'" 
    13461360    end 
     1361  end 
     1362   
     1363  def test_unparse_assets 
     1364    login(:lion) 
     1365    @node = secure!(Node) { nodes(:status) } 
     1366    assert @node.update_attributes(:v_text => "Hello this is \"art\":#{nodes_zip(:art)}. !#{nodes_zip(:bird_jpg)}!") 
     1367    assert_equal "Hello this is \"art\":(../../../collections/art). !(../../wiki/bird)!", @node.unparse_assets(@node.v_text, self) 
     1368  end 
     1369   
     1370  def test_parse_assets 
     1371    login(:lion) 
     1372    @node = secure!(Node) { nodes(:status) } 
     1373    assert @node.update_attributes(:v_text => "Hello this is \"art\":(../../../collections/art).") 
     1374    assert_equal "Hello this is \"art\":#{nodes_zip(:art)}.", @node.parse_assets(@node.v_text, self) 
    13471375  end 
    13481376   
     
    14241452    # render math ? 
    14251453  end 
     1454   
     1455  def find_node_by_pseudo(string, base_node = nil) 
     1456    secure(Node) { Node.find_node_by_pseudo(string, base_node || @node) } 
     1457  end 
    14261458end 
  • trunk/test/unit/skin_test.rb

    r1098 r1231  
    88    tmpt = secure!(Node) { nodes(:wiki_Node_zafu) } 
    99    assert_kind_of Template, tmpt 
    10     assert_equal 'wiki_skin', skin.name 
    11     assert_equal 'wiki_skin', tmpt.c_skin_name 
     10    assert_equal 'wikiSkin', skin.name 
     11    assert_equal 'wikiSkin', tmpt.c_skin_name 
    1212    skin.name = 'fun' 
    1313    assert skin.save, "Can save skin." 
  • trunk/test/unit/template_test.rb

    r1180 r1231  
    284284    doc = secure!(Template) { nodes(:wiki_Project_changes_xml_zafu) } 
    285285    tmpt_content = doc.v_content 
    286     assert_equal 'wiki_skin', tmpt_content.skin_name 
     286    assert_equal 'wikiSkin', tmpt_content.skin_name 
    287287    assert doc.update_attributes(:parent_id => nodes_id(:default)) 
    288288     
  • trunk/test/unit/text_document_test.rb