Changeset 1147
- Timestamp:
- 2008-09-15 13:51:17 (4 months ago)
- Files:
-
- trunk/app/controllers/nodes_controller.rb (modified) (2 diffs)
- trunk/app/models/node.rb (modified) (3 diffs)
- trunk/lib/has_relations.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/zena.rb (modified) (12 diffs)
- trunk/test/fixtures/files/Node-test.zafu (modified) (2 diffs)
- trunk/test/helpers/zena_parser/ajax.yml (modified) (2 diffs)
- trunk/test/helpers/zena_parser/basic.yml (modified) (2 diffs)
- trunk/test/helpers/zena_parser_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/nodes_controller.rb
r1127 r1147 77 77 # swap (a way to preview content by drag & drop) 78 78 @node = other 79 elsif params[:change] == 'dropped' 79 elsif params[:change] == 'receiver' 80 attributes[:copy] = other 81 @node.update_attributes_with_transformation(attributes) 82 if !@node.errors.empty? 83 @errors = @node.errors 84 end 85 else 80 86 attributes[:copy] = @node 81 87 other.update_attributes_with_transformation(attributes) … … 83 89 @errors = other.errors 84 90 end 85 else 86 attributes[:copy] = other 87 @node.update_attributes_with_transformation(attributes) 88 if !@node.errors.empty? 89 @errors = @node.errors 90 end 91 end 91 end 92 elsif p = params[:params] 93 params.merge!(other.replace_attributes_in_values(p)) 92 94 end 93 95 trunk/app/models/node.rb
r1131 r1147 132 132 :section_zip, :skin, :ref_lang, :fullpath, :rootpath, :position, :publish_from, :max_status, :rgroup_id, 133 133 :wgroup_id, :pgroup_id, :basepath, :custom_base, :klass, :zip, :score, :comments_count, :l_status, :l_comment, 134 :custom_a, :custom_b, :title, :text 135 safe_attribute:m_text, :m_title, :m_author134 :custom_a, :custom_b, :title, :text, 135 :m_text, :m_title, :m_author 136 136 zafu_context :author => "Contact", :parent => "Node", 137 137 :project => "Project", :section => "Section", … … 673 673 end 674 674 end 675 675 676 676 res 677 677 end … … 731 731 end 732 732 733 # Return true if the attribute can be read (is zafu_readable) 733 # Return true if the attribute can be read. This is not the same as zafu_readable? as some 734 # attributes can be read but should not be shown ('id' or 'file' for example). 734 735 def safe_attribute?(att) 735 736 # FIXME: SECURITY: is there any risk here ? (k can be anything) trunk/lib/has_relations.rb
r1128 r1147 224 224 # invalid relation 225 225 if mode == '=' 226 errors.add(role, "invalid relation") unless args[0]. empty?226 errors.add(role, "invalid relation") unless args[0].blank? 227 227 return args[0] 228 228 else trunk/lib/parser/lib/rules/zena.rb
r1138 r1147 278 278 elsif @params[:attr] 279 279 attribute_method = node_attribute(@params[:attr], :else=>@params[:else], :default=>@params[:default]) 280 elsif p = @params[:param] 281 return "<%= params[#{p.to_sym.inspect}] %>" 280 282 elsif @params[:date] 281 283 # date can be any attribute v_created_at or updated_at etc. … … 482 484 483 485 context_bak = @context.dup # avoid side effects when rendering the same block 484 template = expand_block(self, :block=>self, :list=>false, :saved_template=>true, :ignore =>['form']) 486 ignore_list = @method == 'block' ? ['form'] : [] # do not show the form in the normal template of a block 487 template = expand_block(self, :block=>self, :list=>false, :saved_template=>true, :ignore => ignore_list) 485 488 @context = context_bak 486 489 @result = '' … … 523 526 end 524 527 return parser_error("cannot use 's' as key (used by start_node)") if @params[:key] == 's' 525 out "<%= form_remote_tag(:url => zafu_node_path(#{node_id}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %><div class='hidden'><input type='hidden' name='t_url' value='#{block.template_url}'/><input type='hidden' name='dom_id' value='#{block.erb_dom_id}'/>#{start_node_ input}</div><div class='wrapper'>"528 out "<%= form_remote_tag(:url => zafu_node_path(#{node_id}), :method => :get, :html => {:id => \"#{dom_id}_f\"}) %><div class='hidden'><input type='hidden' name='t_url' value='#{block.template_url}'/><input type='hidden' name='dom_id' value='#{block.erb_dom_id}'/>#{start_node_s_param(:input)}</div><div class='wrapper'>" 526 529 if @blocks == [] 527 530 out "<input type='text' name='#{@params[:key] || 'f'}' value='<%= params[#{(@params[:key] || 'f').to_sym.inspect}] %>'/>" … … 1237 1240 next if [:hover, :change, :done].include?(k) 1238 1241 value, static = parse_attributes_in_value(v, :erb => false, :skip_node_attributes => true) 1239 url_params << "node[#{k}]=#{CGI.escape(value)}" 1242 key = change == 'params' ? "params[#{k}]" : "node[#{k}]" 1243 url_params << "#{key}=#{CGI.escape(value)}" 1240 1244 end 1241 1245 return parser_error("missing parameters to set values") if url_params == [] 1242 1246 end 1243 1247 1244 url_params << "change= dropped" if change == 'dropped'1248 url_params << "change=#{change}" if change == 'receiver' 1245 1249 url_params << "t_url=#{CGI.escape(template_url)}" 1246 1250 url_params << "dom_id=#{erb_dom_id}" 1251 url_params << start_node_s_param(:erb) 1247 1252 url_params << "done=#{CGI.escape(@params[:done])}" if @params[:done] 1248 1253 … … 2174 2179 def node(klass = self.node_class) 2175 2180 if klass == self.node_class 2176 @context[:saved_template]? "@#{base_class.to_s.underscore}" : (@context[:node] || '@node')2181 (@context[:saved_template] && @context[:main_node]) ? "@#{base_class.to_s.underscore}" : (@context[:node] || '@node') 2177 2182 elsif klass == Node 2178 2183 @context[:previous_node] || '@node' … … 2370 2375 # DOM id for the current context 2371 2376 def dom_id(suffix='') 2372 return "\#{dom_id(#{node})}" if @context && @context[:saved_template]2377 return "\#{dom_id(#{node})}" if @context && (@context[:saved_template] && @context[:main_node]) 2373 2378 if @context && scope_node = @context[:scope_node] 2374 2379 res = "#{dom_prefix}_\#{#{scope_node}.zip}" … … 2395 2400 2396 2401 def erb_dom_id(suffix='') 2397 return "<%= dom_id(#{node}) %>" if @context && @context[:saved_template]2402 return "<%= dom_id(#{node}) %>" if @context && (@context[:saved_template] && @context[:main_node]) 2398 2403 if @context && scope_node = @context[:scope_node] 2399 2404 res = "#{dom_prefix}_<%= #{scope_node}.zip %>" … … 2444 2449 # use our own scope 2445 2450 def clear_dom_scope 2446 @context.delete(:dom_prefix) # should not propagate2447 2451 @context.delete(:make_form) # should not propagate 2448 @context.delete(: saved_template)# should not propagate2452 @context.delete(:main_node) # should not propagate 2449 2453 end 2450 2454 … … 2452 2456 def new_dom_scope 2453 2457 clear_dom_scope 2458 @context.delete(:saved_template) # should not propagate on fresh template 2459 @context.delete(:dom_prefix) # should not propagate on fresh template 2460 @context[:main_node] = true # the current context will be rendered with a fresh '@node' 2454 2461 @context[:dom_prefix] = self.dom_prefix 2455 2462 end … … 2847 2854 url_params << "link_id=\#{#{node}.link_id}" if @context[:need_link_id] && node_kind_of?(Node) 2848 2855 url_params << "node[v_status]=#{Zena::Status[:pub]}" if @params[:publish] 2849 url_params << start_node_ input(false)2856 url_params << start_node_s_param(:string) 2850 2857 2851 2858 res = '' … … 3083 3090 return '' if attribute == 'parent_id' # set with 'r_form' 3084 3091 3085 if @context[:in_add] 3086 value = '' 3087 else 3088 value = attribute ? "<%= #{node_attribute(attribute)} %>" : "" 3092 if @blocks == [] || @blocks == [''] 3093 if @context[:in_add] 3094 value = '' 3095 else 3096 value = attribute ? "<%= #{node_attribute(attribute)} %>" : "" 3097 end 3098 else 3099 value = expand_with 3089 3100 end 3090 3101 html_id = @context[:dom_prefix] ? " id='#{erb_dom_id}_#{attribute}'" : '' … … 3118 3129 end 3119 3130 3120 def start_node_ input(erb = true)3121 if erb3131 def start_node_s_param(type = :input) 3132 if type == :input 3122 3133 "<input type='hidden' name='s' value='<%= params[:s] || @node[:zip] %>'/>" 3134 elsif type == :erb 3135 "s=<%= params[:s] || @node[:zip] %>" 3123 3136 else 3124 3137 "s=\#{params[:s] || @node[:zip]}" trunk/test/fixtures/files/Node-test.zafu
r1098 r1147 101 101 <r:images in='site' do='each' draggable='true' do='img' mode='tiny'/> 102 102 103 <h3>drop set relation</h3> 104 103 105 <ul do='tags in site'> 104 106 <li style='border:1px solid #400; min_width:100px; min_height:100px;' do='each' do='drop' set='set_tag'> … … 108 110 </ul> 109 111 112 <h3>drop set attributes</h3> 113 110 114 <ul do='projects in site'> 111 115 <li style='border:1px solid #400; min_width:100px; min_height:100px;' do='each'><r:drop d_foo='I am an icon for [v_title]' icon_for_id='[id]'><b do='title' actions='all'/><r:icon where='1'><r:unlink do='img' mode='pv'/> <r:show attr='d_foo'/> </r:icon></r:drop> 112 116 </li> 113 117 </ul> 118 119 <h3>drop reload with param</h3> 120 121 <div style='border:1px solid #400; min_width:100px; min_height:100px;' do='drop' change='params' d='[id]' do='if' test='param:d'> 122 <r:node where='id eq param:d' in='site'> 123 Change icon to <r:img mode='tiny'/> ? 124 <r:main store='icon' do='form'> 125 <r:input type='hidden' name='icon_id' set_value='[icon.id]'/> 126 <r:input type='hidden' name='m_title' set_value='icon changed to [icon.name]'/> 127 <r:textarea name='m_text'/> 128 <input type='submit'/> 129 </r:main> 130 </r:node> 131 <r:else> 132 <r:icon do='img' mode='pv'/> 133 please drop a node to change the icon 134 <ul do='comments'> 135 <li do='each'><b do='[title]'/> <b do='[author_name]'/> 136 <div do='{text}'/> 137 </li> 138 </ul></r:else> 139 </div> 114 140 115 141 <hr/> trunk/test/helpers/zena_parser/ajax.yml
r1137 r1147 182 182 </li> 183 183 </ul> 184 'each/in/en/each/dom/id/list1.erb': "/list 2_..@node.zip._..var1.zip./"184 'each/in/en/each/dom/id/list1.erb': "/list1_..@node.zip._..var1.zip./" 185 185 186 186 start_id: … … 188 188 res: "/<input name='s' type='hidden' value='22'/>/" 189 189 190 drop_param: 191 src: "<r:drop change='params' d='[id]'><r:show param='d'/></r:drop>" 192 tem: "/<div class='drop' id='list1'><%= params\[:d\] %>.*drop\?params\[d\]=%5Bid%5D/" 193 190 194 swap_in_each: 191 195 src: "<r:pages><li do='each'><span do='swap' attr='d_status' states='todo,done,alert'/></li></r:pages>" trunk/test/helpers/zena_parser/basic.yml
r1138 r1147 81 81 src: "<b do='[d_assigned]' edit_preview='true'/>" 82 82 res: "<b id='d_assigned22'>gaspard</b>" 83 84 show_param: 85 context: 86 d: 'hello ladies' 87 src: "<i do='show' param='d'/>" 88 tem: "<i><%= params[:d] %></i>" 89 res: "<i>hello ladies</i>" 83 90 84 91 title_in_version_context: … … 909 916 res: "<input name='node[c_first_name]' type='text' value='Solenopsis'/>" 910 917 918 textarea: 919 context: 920 node: 'ant' 921 src: "<r:textarea name='c_first_name'/>" 922 tem: "<textarea name='node[c_first_name]'><%= @node.c_zafu_read(\"first_name\") %></textarea>" 923 res: "<textarea name='node[c_first_name]'>Solenopsis</textarea>" 924 925 textarea_with_blocks: 926 context: 927 node: 'ant' 928 src: "<r:textarea name='c_first_name'>Sir <r:show attr='c_first_name'/></textarea>" 929 tem: "<textarea name='node[c_first_name]'>Sir <%= @node.c_zafu_read(\"first_name\") %></textarea></textarea>" 930 res: "<textarea name='node[c_first_name]'>Sir Solenopsis</textarea></textarea>" 931 911 932 input_new: 912 933 context: trunk/test/helpers/zena_parser_test.rb
r1061 r1147 34 34 $_test_site = context.delete('site') || 'zena' 35 35 @request.host = sites_host($_test_site) 36 params[:user_id] = users_id(context ['visitor'].to_sym)37 params[:node_id] = nodes_id(context ['node'].to_sym)38 params[:prefix] = context ['lang']39 params[:date] = context['ref_date'] ? context ['ref_date'].to_s : nil36 params[:user_id] = users_id(context.delete('visitor').to_sym) 37 params[:node_id] = nodes_id(context.delete('node').to_sym) 38 params[:prefix] = context.delete('lang') 39 params[:date] = context['ref_date'] ? context.delete('ref_date').to_s : nil 40 40 params[:url] = "/#{test.to_s.gsub('_', '/')}" 41 params.merge!(context) # merge the rest of the context as query parameters 41 42 TestController.templates = @@test_strings[file] 42 43 if src
