Changeset 1096
- Timestamp:
- 2008-07-07 09:30:23 (6 months ago)
- Files:
-
- trunk/app/controllers/application.rb (modified) (3 diffs)
- trunk/app/controllers/versions_controller.rb (modified) (1 diff)
- trunk/app/helpers/application_helper.rb (modified) (1 diff)
- trunk/app/models/node.rb (modified) (3 diffs)
- trunk/app/models/text_document.rb (modified) (6 diffs)
- trunk/app/models/text_document_content.rb (modified) (1 diff)
- trunk/app/models/version.rb (modified) (1 diff)
- trunk/app/views/comments/create.rjs (modified) (2 diffs)
- trunk/app/views/nodes/create.rjs (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zena.rb (modified) (9 diffs)
- trunk/lib/query_builder/lib/query_builder.rb (modified) (2 diffs)
- trunk/public/stylesheets/zena.css (modified) (2 diffs)
- trunk/test/unit/text_document_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/application.rb
r1094 r1096 346 346 347 347 dev_box << " <li><a class='group' onclick='$(\"_dev_tools\").toggle();' href='#'>tools</a>\n" 348 dev_box << " <ul id='_dev_tools' >\n"348 dev_box << " <ul id='_dev_tools' style='display:none;'>\n" 349 349 dev_box << " <li><a href='?rebuild=true'>#{_('rebuild')}</a></li>\n" 350 350 dev_box << "<% if @node.kind_of?(Skin) -%> <li><a href='<%= export_node_path(@node[:zip]) %>'>#{_('export')}</a></li>\n<% end -%>" … … 380 380 381 381 # Return the zen_path ('/en/image34.png') for an asset given its name ('img/footer.png'). 382 # The rule is not the same whether we are rendering a template and find <img/> <link rel='stylesheet'/> tags 383 # or if we are parsing assets in a CSS file. 382 384 def template_url_for_asset(opts) 383 return nil unless res = find_document_for_template(opts) 384 asset, url = *res 385 @renamed_assets[url] = asset unless opts[:parse_assets] 385 if opts[:parse_assets] 386 src = opts[:src] 387 current_folder = opts[:current_folder] || '' 388 current_folder = current_folder[1..-1] if current_folder[0..0] == '/' 389 390 if src =~ /\A(.*)\.(\w+)\Z/ 391 src, format = $1, $2 392 end 393 394 if src[0..0] == '/' 395 path = src[1..-1] 396 else 397 path = current_folder + '/' + src 398 end 399 400 return nil unless asset = secure(Document) { Document.find_by_path(path) } 401 else 402 return nil unless res = find_document_for_template(opts) 403 asset, url = *res 404 @renamed_assets[url] = asset 405 end 406 386 407 data_path(asset) 387 408 end … … 390 411 # ('skin/template/path'). If the path starts with a slash, the skin_name in the path is searched first. Otherwise, 391 412 # the current skin is searched first. 413 # <r:include template='Node'/> 414 # find: #{skin_path(main_skin)}/Node 415 # 416 # <r:include template='/default/Node'/> 417 # find: #{skin_path('default')}/Node 418 # 392 419 def find_document_for_template(opts) 393 420 src = opts[:src] trunk/app/controllers/versions_controller.rb
r1094 r1096 63 63 if @node.kind_of?(TextDocument) 64 64 if params['parse_assets'] 65 @node. parse_assets!(self)65 @node.version.text = @node.parse_assets(@node.version.text, self) 66 66 elsif @node.kind_of?(TextDocument) && params['unparse_assets'] 67 @node. unparse_assets67 @node.version.text = @node.unparse_assets(@node.version.text) 68 68 end 69 69 end trunk/app/helpers/application_helper.rb
r1090 r1096 71 71 ref = params[:reference] || "#{params[:dom_id]}_add" 72 72 page.insert_html pos.to_sym, ref, :file => fullpath_from_template_url + ".erb" 73 instance_variable_set("@#{base_class.to_s.underscore}", obj.clone) 73 if obj.kind_of?(Node) 74 @node = @node.parent.new_child(:class => @node.class) 75 else 76 instance_variable_set("@#{base_class.to_s.underscore}", obj.clone) 77 end 74 78 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" 75 79 if params[:done] trunk/app/models/node.rb
r1094 r1096 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 134 :custom_a, :custom_b, :title, :text 135 135 zafu_context :author => "Contact", :parent => "Node", 136 136 :project => "Project", :section => "Section", … … 268 268 return node 269 269 end 270 node = Node.with_exclusive_scope do 271 Node.find(:first, :conditions => ['site_id = ? AND name = ? AND parent_id = ?', 270 begin 271 klass = Node.get_class(attributes['klass'] || 'Node') 272 klass = klass.real_class if klass.kind_of?(VirtualClass) 273 rescue NameError 274 klass = Node 275 end 276 node = klass.with_exclusive_scope do 277 klass.find(:first, :conditions => ['site_id = ? AND name = ? AND parent_id = ?', 272 278 current_site[:id], attributes['name'].url_name, attributes['parent_id']]) 273 279 end … … 935 941 def author 936 942 user.contact 943 end 944 945 def title 946 version.title 947 end 948 949 def text 950 version.text 951 end 952 953 def title=(t) 954 redaction.title = t 955 end 956 957 def text=(t) 958 redaction.text = t 937 959 end 938 960 trunk/app/models/text_document.rb
r1094 r1096 28 28 29 29 # Parse text content and replace all reference to relative urls ('img/footer.png') by their zen_path ('/en/image34.png') 30 def parse_assets!(helper) 30 def parse_assets(text, helper) 31 res = text.dup 31 32 ctype = version.content.content_type 32 33 case ctype … … 42 43 end 43 44 44 current_folder = skin.name + parent.fullpath[(skin.fullpath.size)..-1]45 current_folder = parent.fullpath 45 46 46 # create/use redaction 47 edit! 48 49 version.text.gsub!(/url\(\s*(.*?)\s*\)/) do 47 res.gsub!(/url\(\s*(.*?)\s*\)/) do 50 48 match, src = $&, $1 51 49 if src =~ /('|")(.*?)\1/ … … 56 54 if src[0..6] == 'http://' 57 55 match 56 elsif src =~ %r{/\w\w/.*\d+\.} 57 # already parsed, ignore 58 "url(#{quote}#{src}#{quote})" 58 59 else 59 if src =~ /\A\// 60 # absolute path: do not touch 60 if new_src = helper.send(:template_url_for_asset, :src => src, :current_folder=>current_folder, :parse_assets => true) 61 "url(#{quote}#{new_src}#{quote})" 62 else 63 errors.add('base', "could not find asset #{src.inspect}") 61 64 "url(#{quote}#{src}#{quote})" 62 else63 new_src = helper.send(:template_url_for_asset, :current_folder=>current_folder, :src => src, :parse_assets => true) || src64 "url(#{quote}#{new_src}#{quote})"65 65 end 66 66 end … … 70 70 errors.add('base', "Invalid content-type #{ctype.inspect} to parse assets.") 71 71 end 72 res 72 73 end 73 74 74 75 # Parse text and replace absolute urls ('/en/image30.jpg') by their relative value in the current skin ('img/bird.jpg') 75 def unparse_assets 76 def unparse_assets(text) 77 res = text.dup 76 78 ctype = version.content.content_type 77 79 case ctype 78 80 when 'text/css' 79 # use skin asroot80 skin = section81 # use parent as relative root 82 current_folder = parent.fullpath 81 83 82 # not in a Skin. Cannot replace assets in CSS. 83 # error 84 unless skin.kind_of?(Skin) 85 errors.add('base', 'Cannot parse assets if not in a Skin.') 86 return 87 end 88 89 version.text.gsub!(/url\(('|")(.*?)\1\)/) do 84 res.gsub!(/url\(('|")(.*?)\1\)/) do 90 85 if $2[0..6] == 'http://' 91 86 $& … … 93 88 quote, url = $1, $2 94 89 if url =~ /\A\/\w\w.*?(\d+)\./ 95 unless asset = secure(Node) { Node.find_by_zip($1) } 96 errors.add('base', "could not find asset node #{url.inspect}") 90 zip = $1 91 unless asset = secure(Node) { Node.find_by_zip(zip) } 92 errors.add('base', "could not find asset node #{zip}") 97 93 "url(#{quote}#{url}#{quote})" 98 94 end 99 if asset.fullpath =~ /\A#{ skin.fullpath}\/(.+)/95 if asset.fullpath =~ /\A#{current_folder}\/(.+)/ 100 96 "url(#{quote}#{$1}.#{asset.c_ext}#{quote})" 101 97 else 102 errors.add('base', "could not find asset node #{url.inspect}") 103 "url(#{quote}#{url}#{quote})" 98 "url(#{quote}/#{asset.fullpath}.#{asset.c_ext}#{quote})" 104 99 end 105 100 else … … 114 109 errors.add('base', "invalid content-type #{ctype.inspect} to unparse assets.") 115 110 end 111 res 116 112 end 117 113 trunk/app/models/text_document_content.rb
r1094 r1096 11 11 # unparse needed in 'export' 12 12 if node.can_parse_assets? 13 node.unparse_assets 13 StringIO.new(node.unparse_assets(version.text)) 14 else 15 StringIO.new(version.text) 14 16 end 15 16 t = StringIO.new(version.text)17 t18 17 end 19 18 trunk/app/models/version.rb
r1094 r1096 114 114 def redaction_content 115 115 return @redaction_content if @redaction_content 116 return unless content_class116 return nil unless content_class 117 117 @content = content 118 118 if @content && @content[:version_id] == self[:id] trunk/app/views/comments/create.rjs
r1062 r1096 14 14 # page.visual_effect :highlight, "comment#{@comment[:id]}", :duration => 0.3 15 15 #end 16 16 update_page_content(page, @comment) 17 =begin 17 18 if @comment.new_record? 18 19 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" … … 29 30 end 30 31 end 32 =end trunk/app/views/nodes/create.rjs
r1067 r1096 1 update_page_content(page, @node) 2 =begin 1 3 if @node.new_record? 2 4 page.replace "#{params[:dom_id]}_form", :file => fullpath_from_template_url + "_form.erb" … … 13 15 end 14 16 end 17 =end trunk/lib/parser/lib/rules/zena.rb
r1091 r1096 691 691 def r_summary 692 692 limit = @params[:limit] ? ", :limit=>#{@params[:limit].to_i}" : "" 693 @html_tag ||= 'div' 694 @html_tag_params[:id] = "v_summary#{erb_node_id}" 695 if c = @html_tag_params[:class] || @params[:class] 696 @html_tag_params[:class] = "#{c} zazen" 697 else 698 @html_tag_params[:class] = 'zazen' 699 end 693 700 unless @params[:or] 694 701 text = @params[:text] ? @params[:text].inspect : node_attribute('v_summary') 695 "<div id='v_summary#{erb_node_id}' class='zazen'><%= zazen(#{text}#{limit}, :node=>#{node}) %></div>"702 out "<%= zazen(#{text}#{limit}, :node=>#{node}) %>" 696 703 else 697 704 limit ||= ', :limit => 2' … … 701 708 second_name = @params[:or].gsub(/[^a-z_]/,'') # FIXME: ist this still needed ? (ERB injection) 702 709 second = node_attribute(second_name) 703 "<div id='#{first_name}#{erb_node_id}' class='zazen'><% if #{first} != '' %>" +704 "<%= zazen(#{first}, :node=>#{node}) %>" +705 "<% else %>" +706 "<%= zazen(#{second}#{limit}, :node=>#{node}) %>" +707 "<% end %></div>"710 out "<% if #{first} != '' %>" 711 out "<%= zazen(#{first}, :node=>#{node}) %>" 712 out "<% else %>" 713 out "<%= zazen(#{second}#{limit}, :node=>#{node}) %>" 714 out "<% end %>" 708 715 end 709 716 end … … 849 856 hidden_fields = {} 850 857 set_fields = [] 858 id_hash = {:class => @html_tag_params[:class] || @params[:class] || 'form'} 851 859 var_name = base_class.to_s.underscore 852 860 (descendants('input') + descendants('select')).each do |tag| … … 857 865 if @context[:in_add] 858 866 # inline form used to create new elements: set values to '' and 'parent_id' from context 859 id_hash = {:id => "#{erb_dom_id}_form", :style => "display:none;"} 867 id_hash[:id] = "#{erb_dom_id}_form" 868 id_hash[:style] = "display:none;" 860 869 861 cancel = "< p class='btn_x'><a href='#' onclick='[\"#{erb_dom_id}_add\", \"#{erb_dom_id}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>\n"870 cancel = "<span class='btn_x'><a href='#' onclick='[\"#{erb_dom_id}_add\", \"#{erb_dom_id}_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></span>\n" 862 871 form = "<%= form_remote_tag(:url => #{base_class.to_s.underscore.pluralize}_path, :html => {:id => \"#{dom_id}_form_t\"}) %>\n" 863 872 else 864 873 # saved form 865 874 866 id_hash = {:id => "#{erb_dom_id}"}875 id_hash[:id] = erb_dom_id 867 876 868 877 cancel = <<-END_TXT 869 878 <% if #{node}.new_record? -%> 870 < p class='btn_x'><a href='#' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></p>879 <span class='btn_x'><a href='#' onclick='[\"<%= params[:dom_id] %>_add\", \"<%= params[:dom_id] %>_form\"].each(Element.toggle);return false;'>#{_('btn_x')}</a></span> 871 880 <% else -%> 872 < p class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{base_class.to_s.underscore}_path(#{node_id}) + \"/zafu?t_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:need_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %></p>881 <span class='btn_x'><%= link_to_remote(#{_('btn_x').inspect}, :url => #{base_class.to_s.underscore}_path(#{node_id}) + \"/zafu?t_url=#{CGI.escape(template_url)}&dom_id=\#{params[:dom_id]}#{@context[:need_link_id] ? "&link_id=\#{#{node}.link_id}" : ''}\", :method => :get) %></span> 873 882 <% end -%> 874 883 END_TXT … … 887 896 hidden_fields['link_id'] = "<%= #{node}.link_id %>" if @context[:need_link_id] 888 897 889 if block = ancestor('block') 890 # set update template url 898 if @params[:update] || (@context[:add] && @context[:add].params[:update]) 899 upd = @params[:update] || @context[:add].params[:update] 900 if target = find_target(upd) 901 hidden_fields['u_url'] = target.template_url 902 hidden_fields['udom_id'] = target.erb_dom_id 903 end 904 elsif block = ancestor('block') && node_kind_of?(DataEntry) 905 # updates template url 891 906 hidden_fields['u_url'] = block.template_url 892 907 hidden_fields['udom_id'] = block.erb_dom_id … … 941 956 else 942 957 # no ajax 943 id_hash = {}944 958 # FIXME 945 959 cancel = "" # link to normal node ? … … 1164 1178 revert_effect = 'Element.move' 1165 1179 end 1166 out expand_with 1167 out "</div>" 1180 out render_html_tag(expand_with) 1168 1181 out "<script type='text/javascript'> 1169 1182 //<![CDATA[ … … 2283 2296 if method == 'each' && !@context[:make_form] 2284 2297 "#{res}_<%= #{var}.zip %>" 2298 elsif method == 'draggable' 2299 "#{res}_<%= #{node}.zip %>" 2285 2300 elsif method == 'unlink' 2286 2301 target = nil … … 2499 2514 elsif node_name == 'main' 2500 2515 return [node_attr, '@node', Node] 2516 elsif node_name == 'visitor' 2517 return [node_attr, 'visitor.contact', Contact] 2501 2518 else 2502 2519 out parser_error("invalid node name #{node_name.inspect} in attribute #{str.inspect}") trunk/lib/query_builder/lib/query_builder.rb
r1084 r1096 310 310 311 311 order.split(',').each do |clause| 312 if clause =~ /^\s*([^\s]+) (ASC|asc|DESC|desc)/ 313 fld_name, direction = $1, $2 312 if clause == 'random' 313 res << "RAND()" 314 else 315 if clause =~ /^\s*([^\s]+) (ASC|asc|DESC|desc)/ 316 fld_name, direction = $1, $2 317 else 318 fld_name = clause 319 direction = 'ASC' 320 end 314 321 if fld = field_or_param(fld_name, table, :order) 315 322 res << "#{fld} #{direction.upcase}" … … 317 324 @errors << "invalid field '#{fld_name}'" 318 325 end 319 elsif clause == 'random'320 res << "RAND()"321 else322 @errors << "invalid order clause '#{clause}'"323 326 end 324 327 end trunk/public/stylesheets/zena.css
r1082 r1096 36 36 37 37 /* ========================= Ajax css ========================= */ 38 .drop_hover { background:#ace; } 38 .drop_hover { background:#ace; border:2px dashed #99f;} 39 .drop { min-height:1em;} 39 40 40 41 /* ========================= Zazen css ======================== */ … … 60 61 #dev li img { border:0; } 61 62 #dev li li { clear:both;} 63 #dev li table { display:none;} 64 #dev:hover table { display:block;} trunk/test/unit/text_document_test.rb
r1094 r1096 50 50 node = secure!(Node) { nodes(:style_css) } 51 51 bird = secure!(Node) { nodes(:bird_jpg)} 52 assert bird.update_attributes(:parent_id => node s_id(:default))52 assert bird.update_attributes(:parent_id => node[:parent_id]) 53 53 start =<<-END_CSS 54 54 body { font-size:10px; } 55 #footer { background:url('bird.jpg') } 55 #header { background:url('bird.jpg') } 56 #footer { background:url('/projects/wiki/flower.jpg') } 56 57 END_CSS 57 58 node.v_text = start.dup … … 59 60 helper = ApplicationController.new 60 61 helper.instance_variable_set(:@visitor, visitor) 61 node.parse_assets!(helper)62 text = node.parse_assets(start, helper) 62 63 assert node.errors.empty? 63 64 res =<<-END_CSS 64 65 body { font-size:10px; } 65 #footer { background:url('/en/image30.jpg') } 66 #header { background:url('/en/image30.jpg') } 67 #footer { background:url('/en/image31.jpg') } 66 68 END_CSS 67 assert_equal res, node.v_text68 node.parse_assets!(helper)69 assert_equal res, node.v_text70 node.unparse_assets71 assert_equal start, node.v_text72 node.unparse_assets73 assert_equal start, node.v_text69 assert_equal res, text 70 text = node.parse_assets(text, helper) 71 assert_equal res, text 72 text = node.unparse_assets(text) 73 assert_equal start, text 74 text = node.unparse_assets(text) 75 assert_equal start, text 74 76 end 75 77 … … 78 80 node = secure!(Node) { nodes(:style_css) } 79 81 bird = secure!(Node) { nodes(:bird_jpg)} 80 assert bird.update_attributes(:parent_id => node s_id(:default))82 assert bird.update_attributes(:parent_id => node[:parent_id]) 81 83 text =<<-END_CSS 82 84 body { font-size:10px; } 83 #footer { background:url('/en/image30.jpg') } 85 #header { background:url('/en/image30.jpg') } 86 #footer { background:url('/en/image31.jpg') } 84 87 END_CSS 85 88 assert_equal 'text/css', node.c_content_type
