Changeset 1231
- Timestamp:
- 2008-10-20 12:35:06 (3 months ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (1 diff)
- trunk/app/controllers/links_controller.rb (modified) (1 diff)
- trunk/app/controllers/nodes_controller.rb (modified) (3 diffs)
- trunk/app/helpers/application_helper.rb (modified) (4 diffs)
- trunk/app/models/data_entry.rb (modified) (1 diff)
- trunk/app/models/link.rb (modified) (1 diff)
- trunk/app/models/node.rb (modified) (18 diffs)
- trunk/app/models/text_document.rb (modified) (1 diff)
- trunk/app/models/text_document_content.rb (modified) (1 diff)
- trunk/config/routes.rb (modified) (1 diff)
- trunk/lib/core_ext/string.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zazen.rb (modified) (18 diffs)
- trunk/lib/tasks/zena.rake (modified) (1 diff)
- trunk/test/fixtures/import/photos.en.zml (modified) (1 diff)
- trunk/test/helpers/node_query/filters.yml (modified) (1 diff)
- trunk/test/helpers/zazen_test.rb (modified) (1 diff)
- trunk/test/helpers/zena_parser/basic.yml (modified) (1 diff)
- trunk/test/sites/zena/nodes.yml (modified) (2 diffs)
- trunk/test/sites/zena/template_contents.yml (modified) (3 diffs)
- trunk/test/unit/core_ext_test.rb (modified) (1 diff)
- trunk/test/unit/node_test.rb (modified) (5 diffs)
- trunk/test/unit/skin_test.rb (modified) (1 diff)
- trunk/test/unit/template_test.rb (modified) (1 diff)
- trunk/test/unit/text_document_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r1217 r1231 256 256 def template_url(opts={}) 257 257 @skin_name = opts[:skin] || (@node ? @node[:skin] : nil) || 'default' 258 @skin_name = @skin_name. gsub(/[^a-zA-Z_]/,'')# security258 @skin_name = @skin_name.url_name # security 259 259 mode = opts[:mode] 260 260 format = opts[:format] || 'html' trunk/app/controllers/links_controller.rb
r1103 r1231 86 86 attrs[k.to_sym] = attributes[k].blank? ? nil : attributes[k] 87 87 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) } 89 89 attrs 90 90 end trunk/app/controllers/nodes_controller.rb
r1217 r1231 20 20 class NodesController < ApplicationController 21 21 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] 23 23 before_filter :check_path, :only => [:index, :show] 24 24 after_filter :change_lang, :only => [:create, :update, :save_text] … … 208 208 def import 209 209 @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 files213 @nodes.each do |n|214 if n.c_ext == 'css'215 v_status = n.v_status216 text = n.parse_assets(n.v_text, self)217 errors = n.errors.dup218 n.errors.clear219 n.update_attributes(:v_status => v_status, :v_text => text)220 end221 end222 end223 @nodes224 210 end 225 211 … … 259 245 # '+' are not escaped as they should in ajax query 260 246 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)} 262 248 @node = secure!(Node) { Node.find(node_id) } 263 249 trunk/app/helpers/application_helper.rb
r1220 r1231 325 325 end 326 326 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) 328 329 end 329 330 … … 334 335 335 336 # 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) } 339 339 end 340 340 … … 1306 1306 if obj == 'link' 1307 1307 if link = instance_variable_get("@#{obj}") 1308 node = link.this 1308 1309 current_obj = link.other 1309 1310 end … … 1338 1339 input_id = opt[:input_id] ? " id='#{params[:input_id]}'" : '' 1339 1340 # 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});" 1341 1342 "<div class='select_id'><input type='text' size='8'#{input_id} name='#{obj}[#{sym}]' value='#{zip}' onChange=\"#{update}\" onKeyup=\"#{update}\"/>"+ 1342 1343 "<span class='select_id_name' id='#{name_ref}'>#{current}</span></div>" trunk/app/models/data_entry.rb
r1069 r1231 44 44 value = attributes[key] 45 45 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) 47 47 end 48 48 end trunk/app/models/link.rb
r1103 r1231 28 28 29 29 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) } 31 31 rel.other_id = other_id 32 32 if @side == :source trunk/app/models/node.rb
r1219 r1231 260 260 261 261 # 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) 263 263 if id.to_s =~ /\A\d+\Z/ 264 264 # zip … … 266 266 res = Node.connection.execute( "SELECT #{sym} FROM nodes WHERE site_id = #{current_site[:id]} AND zip = '#{id}'" ).fetch_row 267 267 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) 269 269 node[sym] 270 270 else … … 274 274 275 275 # 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) 277 277 raise Zena::AccessViolation if self.scoped_methods == [] 278 278 str = id.to_s … … 283 283 offset = $2.to_s.size 284 284 find(:first, Node.match_query($1.gsub('-',' '), :offset => offset)) 285 elsif path = str[/\A\(([^\)] +)\)\Z/,1]285 elsif path = str[/\A\(([^\)]*)\)\Z/,1] 286 286 if path[0..0] == '/' 287 287 find_by_path(path[1..-1]) 288 elsif base_ path289 find_by_path( "#{base_path}/#{path}")288 elsif base_node 289 find_by_path(path.abs_path(base_node.fullpath)) 290 290 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 292 294 end 293 295 end … … 435 437 name = "#{$1}#{$4}" 436 438 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] 438 440 attrs['name'] = name 439 441 attrs['v_lang'] = lang || attrs['v_lang'] || visitor.lang … … 454 456 455 457 # 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] 457 459 attrs['name'] = name 458 460 attrs['v_lang'] ||= lang … … 529 531 res[current_obj[:id].to_i] = current_obj 530 532 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 532 555 end 533 556 res … … 651 674 # Translate attributes from the visitor's reference to the application. 652 675 # 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) 654 677 res = {} 655 678 res['parent_id'] = new_attributes[:_parent_id] if new_attributes[:_parent_id] # real id set inside zena. … … 664 687 665 688 if !res['parent_id'] && p = attributes['parent_id'] 666 res['parent_id'] = Node.translate_pseudo_id(p, :id, start_path) || p689 res['parent_id'] = Node.translate_pseudo_id(p, :id, base_node) || p 667 690 end 668 691 … … 685 708 elsif key =~ /^(\w+)_id$/ 686 709 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] 688 711 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] 690 713 end 691 714 elsif key =~ /^(\w+)_ids$/ … … 693 716 values = attributes[key].kind_of?(Array) ? attributes[key] : attributes[key].split(',') 694 717 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) } 696 719 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) } 698 721 end 699 722 res[key] = values.compact … … 706 729 value = attributes[key] 707 730 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) 709 732 else 710 733 res[key] = value … … 716 739 end 717 740 718 def get_attributes_from_yaml(filepath, start_path= nil)741 def get_attributes_from_yaml(filepath, base_node = nil) 719 742 attributes = YAML::load( File.read( filepath ) ) 720 743 attributes.delete(:_parent_id) 721 transform_attributes(attributes, start_path)744 transform_attributes(attributes, base_node) 722 745 end 723 746 … … 826 849 # Update a node's attributes, transforming the attributes first from the visitor's context to Node context. 827 850 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)}) 829 852 end 830 853 … … 848 871 end 849 872 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) 850 885 end 851 886 … … 918 953 end 919 954 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 920 965 921 966 # Return save path for an asset (element produced by text like a png file from LateX) … … 1318 1363 def to_yaml 1319 1364 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) 1326 1367 end 1327 1368 … … 1331 1372 1332 1373 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) } 1334 1380 end 1335 1381 trunk/app/models/text_document.rb
r1096 r1231 74 74 75 75 # 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) 77 77 res = text.dup 78 78 ctype = version.content.content_type trunk/app/models/text_document_content.rb
r1096 r1231 9 9 node = version.node 10 10 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) 17 12 end 18 13 trunk/config/routes.rb
r1220 r1231 17 17 18 18 map.resources :nodes, 19 :collection => { :asearch => :get, :search => :get , :attribute => :get},19 :collection => { :asearch => :get, :search => :get }, 20 20 :member => { :import => :post, :export => :get, :save_text => :put, 21 21 :order => :any, :clear_order => :any, 22 :zafu => :get, :drop => :put } do |nodes|22 :zafu => :get, :drop => :put, :attribute => :get } do |nodes| 23 23 nodes.resources :versions, 24 24 :name_prefix => nil, trunk/lib/core_ext/string.rb
r1217 r1231 102 102 res 103 103 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 104 137 105 138 end trunk/lib/parser/lib/rules/zazen.rb
r1219 r1231 11 11 def r_void 12 12 @context = {:images => true, :pretty_code=>true, :output => 'html'}.merge(@context) 13 @ parse_shortcuts = @context[:parse_shortcuts]13 @translate_ids = @context[:translate_ids] 14 14 @text = @text.gsub("\r\n","\n") # this also creates our own 'working' copy of the text 15 15 @blocks = "" # same reason as why we rewrite 'store' … … 22 22 enter(:void) # <== parse here 23 23 24 unless @ parse_shortcuts24 unless @translate_ids 25 25 store '</pre>' if @in_space_pre 26 26 … … 47 47 module Zazen 48 48 module Rules 49 PSEUDO_ID_REGEXP = ":[0-9a-zA-Z-]+\\+*|\\([^\\)] +\\)"49 PSEUDO_ID_REGEXP = ":[0-9a-zA-Z-]+\\+*|\\([^\\)]*\\)" 50 50 51 51 def start(mode) … … 80 80 elsif @text[0..0] == '<' 81 81 flush '<' 82 elsif !@in_space_pre && @text[0..2] == "\n\n " && !@ parse_shortcuts82 elsif !@in_space_pre && @text[0..2] == "\n\n " && !@translate_ids 83 83 # space preserving paragraphe 84 84 @in_space_pre = true 85 85 store "\n\n<pre>" 86 86 eat 3 87 elsif @in_space_pre && @text[0..1] == "\n\n" && !@ parse_shortcuts87 elsif @in_space_pre && @text[0..1] == "\n\n" && !@translate_ids 88 88 store "</pre>" 89 89 while @text[0..0] == "\n" … … 95 95 flush "\n" 96 96 end 97 elsif @text[0..1] == "\n " && @in_space_pre && !@ parse_shortcuts97 elsif @text[0..1] == "\n " && @in_space_pre && !@translate_ids 98 98 store "\n" 99 99 eat 2 100 100 elsif @text[0..1] == "\n|" 101 101 flush "\n|" 102 elsif @text[0..0] == "\n" && !@ parse_shortcuts102 elsif @text[0..0] == "\n" && !@translate_ids 103 103 if @in_space_pre || @text == "\n" || @text[1..1] == '*' || @text[1..1] == '#' 104 104 flush "\n" … … 128 128 if @context[:images] 129 129 ids = parse_document_ids($1) 130 if @ parse_shortcuts130 if @translate_ids 131 131 store "![#{ids.join(',')}]!" 132 132 else … … 143 143 if @context[:images] 144 144 ids = parse_document_ids(ids) 145 if @ parse_shortcuts145 if @translate_ids 146 146 store "!#{style}{#{ids.join(',')}}!" 147 147 else … … 156 156 eat $& 157 157 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]) 159 159 if link && link =~ /^(#{PSEUDO_ID_REGEXP})(.*)$/ 160 160 rest = $2 161 if link_node = @helper.find_node_by_pseudo($1 )162 link = link_node [:zip].to_s + rest161 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 163 163 end 164 164 end 165 165 166 if @ parse_shortcuts166 if @translate_ids 167 167 if node.kind_of?(Document) 168 168 # 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 : ''}" 170 170 else 171 171 store $& … … 178 178 end 179 179 end 180 elsif @ parse_shortcuts180 elsif @translate_ids 181 181 store $& 182 182 else … … 190 190 if link && link =~ /^(#{PSEUDO_ID_REGEXP})(.*)$/ 191 191 rest = $2 192 if link_node = @helper.find_node_by_pseudo($1 )192 if link_node = @helper.find_node_by_pseudo($1, @context[:node]) 193 193 link = link_node[:zip].to_s + rest 194 194 end 195 195 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 197 201 store "!#{style}#{id}#{other_opts}#{title_opts}!#{link ? ':' + link : ''}" 198 202 else … … 209 213 if @text =~ /\A"([^"]*)":([0-9]+(_[a-z]+|)(\.[a-z]+|)(#[a-z_\/\[\]]*|))/m 210 214 #puts "LINK:[#{$&}]" 211 if @ parse_shortcuts215 if @translate_ids == :zip 212 216 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}" 213 223 else 214 224 eat $& … … 225 235 eat $& 226 236 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 i d = "#{node.zip}#{mode_format}"229 if @parse_shortcuts237 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}" 230 240 # replace shortcut 231 241 store "\"#{title}\":#{id}" 232 242 else 243 id = "#{node.zip}#{mode_format}" 233 244 if format == '.data' 234 245 title = "#{node.fullpath}#{mode}.#{node.c_ext}#{dash}" … … 242 253 store @helper.make_link(:title=>title,:id=>id,:sharp=>sharp,:node=>node) 243 254 end 244 elsif @ parse_shortcuts255 elsif @translate_ids 245 256 store $& 246 257 else … … 257 268 # puts "BRACKET:[#{@text}]" 258 269 if @text =~ /\A\[(\w+)\](.*?)\[\/\1\]/m 259 if @ parse_shortcuts270 if @translate_ids 260 271 flush $& 261 272 else … … 309 320 block_counter = -1 310 321 fulltext.gsub!( /<code([^>]*)>(.*?)<\/code>/m ) do 311 if @ parse_shortcuts322 if @translate_ids 312 323 @escaped_code << $& 313 324 block_counter += 1 … … 343 354 def render_code(text) 344 355 text.gsub!( /\\ZAZENBLOCKCODE(\d+)ZAZENBLOCKCODE\\/ ) do 345 if @ parse_shortcuts356 if @translate_ids 346 357 @escaped_code[$1.to_i] 347 358 else … … 364 375 text.gsub!( /\\ZAZENBLOCKAT(\d+)ZAZENBLOCKAT\\/ ) do 365 376 code = @escaped_at[$1.to_i] 366 if @ parse_shortcuts377 if @translate_ids 367 378 '@'+code+'@' 368 379 else … … 385 396 386 397 def parse_document_ids(str) 398 meth = :zip || @translate_ids 387 399 str.split(',').map do |id| 388 400 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]) 390 402 if node.kind_of?(Document) 391 403 # replace shortcut 392 node. zip393 elsif @ parse_shortcuts404 node.send(meth) 405 elsif @translate_ids 394 406 id # not a document but do not remove 395 407 else 396 408 nil # not a document 397 409 end 398 elsif @ parse_shortcuts399 id 410 elsif @translate_ids 411 id # keep 400 412 else 401 413 nil # document not found trunk/lib/tasks/zena.rake
r1197 r1231 369 369 end 370 370 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}'.") 372 372 else 373 373 # top node trunk/test/fixtures/import/photos.en.zml
r1031 r1231 1 1 class: Section 2 2 v_title: Photos ! 3 d_foo: A simple "test":(../simple) 3 4 v_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'. 5 10 6 11 ![]! trunk/test/helpers/node_query/filters.yml
r1169 r1231 72 72 src: "nodes where name like 'w%' in site" 73 73 sql: "/name LIKE 'w%'/" 74 res: "water, wiki, wiki _skin"74 res: "water, wiki, wikiSkin" 75 75 76 76 param_filter_tag: trunk/test/helpers/zazen_test.rb
r1219 r1231 159 159 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)') 160 160 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 161 178 162 179 end trunk/test/helpers/zena_parser/basic.yml
r1211 r1231 486 486 node: 'collections' 487 487 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>" 489 489 490 490 each_alternate_class_ajax: trunk/test/sites/zena/nodes.yml
r1217 r1231 163 163 wgroup: public 164 164 pgroup: public 165 skin: wiki _skin165 skin: wikiSkin 166 166 167 167 bird_jpg: … … 257 257 zip: 43 258 258 class: Skin 259 name: wiki _skin259 name: wikiSkin 260 260 # yes it's not good to have this here but changing it would mess up many tests. 261 261 parent: collections trunk/test/sites/zena/template_contents.yml
r1217 r1231 65 65 wiki_Node_zafu: 66 66 node: wiki_Node_zafu 67 skin_name: wiki _skin67 skin_name: wikiSkin 68 68 format: html 69 69 tkpath: N … … 73 73 wiki_Project_changes_xml_zafu: 74 74 node: wiki_Project_changes_xml_zafu 75 skin_name: wiki _skin75 skin_name: wikiSkin 76 76 format: xml 77 77 tkpath: NPP … … 81 81 wiki_Page_changes_zafu: 82 82 node: wiki_Page_changes_zafu 83 skin_name: wiki _skin83 skin_name: wikiSkin 84 84 format: html 85 85 tkpath: NP trunk/test/unit/core_ext_test.rb
r977 r1231 97 97 end 98 98 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 99 126 end 100 127 trunk/test/unit/node_test.rb
r1219 r1231 888 888 doc = n if n[:name] == 'document' 889 889 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]) } 891 891 photos = secure!(Node) { Node.find_by_name_and_parent_id('photos', parent[:id]) } 892 892 … … 903 903 assert_equal 'Photos !', photos.v_title 904 904 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 905 908 in_photos = photos.find(:all, 'children') 906 909 assert_equal 2, in_photos.size … … 1010 1013 assert_kind_of Image, bird 1011 1014 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 1012 1024 end 1013 1025 … … 1335 1347 def test_translate_pseudo_id_path 1336 1348 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) } 1338 1352 assert lion.update_attributes(:name => 'status') 1339 # path base_ path1353 # path base_node 1340 1354 { ['(/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), 1344 1358 }.each do |k,v| 1345 1359 assert_equal v, secure(Node) { Node.translate_pseudo_id(k[0],:id,k[1]) }, "'#{k.inspect}' should translate to '#{v}'" 1346 1360 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) 1347 1375 end 1348 1376 … … 1424 1452 # render math ? 1425 1453 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 1426 1458 end trunk/test/unit/skin_test.rb
r1098 r1231 8 8 tmpt = secure!(Node) { nodes(:wiki_Node_zafu) } 9 9 assert_kind_of Template, tmpt 10 assert_equal 'wiki _skin', skin.name11 assert_equal 'wiki _skin', tmpt.c_skin_name10 assert_equal 'wikiSkin', skin.name 11 assert_equal 'wikiSkin', tmpt.c_skin_name 12 12 skin.name = 'fun' 13 13 assert skin.save, "Can save skin." trunk/test/unit/template_test.rb
r1180 r1231 284 284 doc = secure!(Template) { nodes(:wiki_Project_changes_xml_zafu) } 285 285 tmpt_content = doc.v_content 286 assert_equal 'wiki _skin', tmpt_content.skin_name286 assert_equal 'wikiSkin', tmpt_content.skin_name 287 287 assert doc.update_attributes(:parent_id => nodes_id(:default)) 288 288 trunk/test/unit/text_document_test.rb
