Changeset 340
- Timestamp:
- 2007-03-07 22:38:24 (2 years ago)
- Files:
-
- trunk/app/controllers/document_controller.rb (modified) (1 diff)
- trunk/app/controllers/main_controller.rb (modified) (1 diff)
- trunk/app/controllers/search_controller.rb (modified) (1 diff)
- trunk/app/helpers/application_helper.rb (modified) (1 diff)
- trunk/app/views/document/_crop.rhtml (modified) (1 diff)
- trunk/app/views/document/show.rhtml (moved) (moved from trunk/app/views/document/create.rhtml) (2 diffs)
- trunk/app/views/templates/edit_tabs/_any_image.rhtml (modified) (1 diff)
- trunk/config/routes.rb (modified) (1 diff)
- trunk/lib/parser/lib/parser.rb (modified) (1 diff)
- trunk/lib/parser/lib/rules/code_syntax.rb (modified) (2 diffs)
- trunk/lib/parser/lib/rules/zazen.rb (modified) (10 diffs)
- trunk/lib/parser/test/parser_test.rb (modified) (1 diff)
- trunk/lib/parser/test/testhelp.rb (modified) (1 diff)
- trunk/lib/parser/test/zazen.yml (modified) (1 diff)
- trunk/public/stylesheets/popup.css (modified) (1 diff)
- trunk/test/functional/document_controller_test.rb (modified) (2 diffs)
- trunk/test/functional/main_controller_test.rb (modified) (1 diff)
- trunk/test/zena_test_controller.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/app/controllers/document_controller.rb
r338 r340 13 13 pdoc.delete(:c_file) if pdoc[:c_file] == "" 14 14 @document = secure(Document) { Document.create(pdoc) } 15 16 15 if @document.new_record? 17 16 render :action=>"new" 17 else 18 flash[:notice] = trans "Upload succeeded." 19 redirect_to :action=>'show', :id=>@document[:id] 18 20 end 19 flash[:notice] = trans "upload succeeded"20 21 rescue ActiveRecord::RecordNotFound 21 22 # user does not have write access to parent. This error should never happen (parent list is filtered) 22 23 page_not_found 23 24 end 24 25 26 # Display the document after creation 27 def show 28 @document = secure(Document) { Document.find(params[:id])} 29 rescue ActiveRecord::RecordNotFound 30 page_not_found 31 end 32 25 33 # Get document data (inline if possible) 26 34 def data trunk/app/controllers/main_controller.rb
r338 r340 74 74 # do not accept a logged in user to browse as if he was anonymous 75 75 def check_url 76 if !params[:prefix] || (session[:user] && params[:prefix] != AUTHENTICATED_PREFIX) 76 if (params[:action] == 'show' && (!params[:path].kind_of?(Array) || params[:path] == [])) 77 redirect_to :action=>'index', :prefix=>prefix 78 elsif !params[:prefix] || (session[:user] && params[:prefix] != AUTHENTICATED_PREFIX) 77 79 redirect_with_prefix 78 elsif (params[:action] == 'show' && !params[:path].kind_of?(Array))79 redirect_to :action=>'index'80 80 end 81 81 end trunk/app/controllers/search_controller.rb
r321 r340 17 17 @results = nil 18 18 secure(Node) do 19 @result_pages, @results = paginate :nodes, :conditions=>conditions, :order => "name ASC", :per_page => 1 519 @result_pages, @results = paginate :nodes, :conditions=>conditions, :order => "name ASC", :per_page => 10 20 20 @results # important: this is the 'secure' yield return, it is used to secure found nodes 21 21 end trunk/app/helpers/application_helper.rb
r338 r340 320 320 images = @node.images 321 321 else 322 ids = ids.split(',').map{|i| i.to_i}.join(',') # sql injection security 323 images = secure(Document) { Document.find(:all, :conditions=>"id IN (#{ids})") } 324 end 322 ids = ids.split(',').map{|i| i.to_i} # sql injection security 323 images = secure(Document) { Document.find(:all, :conditions=>"id IN (#{ids.join(',')})") } 324 # order like ids : 325 images.sort! {|a,b| ids.index(a[:id].to_i) <=> ids.index(b[:id].to_i) } 326 end 327 325 328 render_to_string( :partial=>'main/gallery', :locals=>{:gallery=>images} ) 326 329 end trunk/app/views/document/_crop.rhtml
r338 r340 1 1 <%= tlink_to_function('cancel', "new Element.toggle('crop', 'crop_form');$('crop_form').innerHTML = '';")%> 2 2 x: <input type='text' id='posx' name='node[crop][x]' size='4'/> y: <input type='text' id='posy' name='node[crop][y]' size='4'/> // w: <input type='text' id='width' name='node[crop][w]' size='4'/> h: <input type='text' id='height' name='node[crop][h]' size='4'/> 3 <p class='edit_info'>original: <%= @node.c_width %>x<%= @node.c_height %>, <%= trans(' view')%>: <b><%= sprintf('%.2f', @node.c_width('edit') / @node.c_width.to_f) %>x</b> <%= @node.c_version_id == @node.v_id ? "<b class='caution'>#{trans('you are editing the original')}</b>" : "" %></p>3 <p class='edit_info'>original: <%= @node.c_width %>x<%= @node.c_height %>, <%= trans('original is #X this view').sub('#X', "<b>#{sprintf('%.1f', @node.c_width.to_f / @node.c_width('edit'))}x</b>")%> <%= @node.c_version_id == @node.v_id ? "<b class='caution'>#{trans('you are editing the original')}</b>" : "" %></p> 4 4 <%= @node.img_tag('edit', :id=>'edit_img') %> trunk/app/views/document/show.rhtml
r338 r340 1 <%= javascript " opener.Zena.update( 'documents', '#{ url_for(:controller=>"document", :action=>"list", :parent_id=>@document.parent_id, :rnd=>rnd) }');" %>1 <%= javascript "if (!(opener==undefined || opener.is_editor)) { opener.Zena.update( 'documents', '#{ url_for(:controller=>"document", :action=>"list", :parent_id=>@document.parent_id, :rnd=>rnd) }'); }" %> 2 2 <div id='form_errors' class='errors'><%= error_messages_for "node" %></div> 3 3 <div id='search'><%= search_box %></div> … … 9 9 <div class='tab'> 10 10 <div class="document"> 11 <p class="btn_x"><%= link_to_function transb('btn_x'), "if (! opener.is_editor) { opener.location.href=opener.location.href;}self.close();" %></p>11 <p class="btn_x"><%= link_to_function transb('btn_x'), "if (!(opener==undefined || opener.is_editor)) { opener.location.href=opener.location.href;}; self.close();" %></p> 12 12 <table cellspacing="0" borderspacing="0"> 13 13 <tr> trunk/app/views/templates/edit_tabs/_any_image.rhtml
r338 r340 5 5 <% if !ImageBuilder.dummy? %> 6 6 <label for="c_crop_x"><%= trans("image") %></label> 7 <div id="crop" class='toggle_div'><%= tlink_to_remote("crop", :url=>{:controller=>'document', :action=>'crop_form', :id=>@node[:id]}) %> 8 9 <%= @node.img_tag('pv')%> 7 <div id="crop" class='toggle_div'><%= tlink_to_remote("crop #{@node.img_tag('pv')}", :url=>{:controller=>'document', :action=>'crop_form', :id=>@node[:id]}) %> 10 8 </div> 11 9 <div id="crop_form" class='toggle_div' style='display:none;'></div> trunk/config/routes.rb
r338 r340 23 23 map.connect '*path', :controller=>'main', :action=>'show', :prefix=>'' 24 24 else 25 map.connect '', :controller => "main", :action=>'select_prefix'26 25 map.site_tree ':prefix/site_tree/:id', :controller=>'main', :action=>'site_tree', :prefix=>/^(#{AUTHENTICATED_PREFIX}|\w\w)$/ 27 26 map.connect ':prefix/*path', :controller=>'main', :action=>'show', :prefix=>/^(#{AUTHENTICATED_PREFIX}|\w\w)$/ 28 27 map.default 'z/:controller/:action/:id' 29 map.connect '*path', :controller=>'main', :action=>'s elect_prefix'28 map.connect '*path', :controller=>'main', :action=>'show' 30 29 end 31 30 ## trunk/lib/parser/lib/parser.rb
r317 r340 335 335 rest = text.strip 336 336 while (rest != '') 337 if rest =~ /(. *?)=/337 if rest =~ /(.+?)=/ 338 338 key = $1.strip.to_sym 339 339 rest = rest[$&.length..-1].strip trunk/lib/parser/lib/rules/code_syntax.rb
r279 r340 32 32 flush_chunk 33 33 @callback.call( Token.new( data, gr, :none, false ) ) 34 end 35 36 def parse_params(text) 37 return [] unless text 38 params = [] 39 rest = text.strip 40 while (rest != '') 41 if rest =~ /(.+?)=/ 42 key = $1.strip.to_sym 43 rest = rest[$&.length..-1].strip 44 if rest =~ /('|")([^\1]*?[^\\])\1/ 45 rest = rest[$&.length..-1].strip 46 if $1 == "'" 47 params << [key,$2.gsub("\\'", "'")] 48 else 49 params << [key,$2.gsub('\\"', '"')] 50 end 51 else 52 # error, bad format, return found params. 53 break 54 end 55 else 56 # error, bad format 57 break 58 end 59 end 60 params 34 61 end 35 62 end … … 74 101 class ZafuTokenizer < Syntax::Tokenizer 75 102 def step 76 if methods = scan(/<\/?z:[^>]+>/)77 methods=~ /<(\/?)z:([^> ]+)([^>]*)(\/?)>/78 start_group : punct, "<#{$1}z:"103 if ztag = scan(/\A<\/?z:[^>]+>/) 104 ztag =~ /<(\/?)z:([^> ]+)([^>]*)(\/?)>/ 105 start_group :tag, "<#{$1}z:" 79 106 start_group :ztag, $2 80 107 trailing = $4 81 params = $3.strip.split(/ +/) 82 params.each do |kv| 83 key, value = *(kv.split('=')) 108 params = parse_params($3) 109 params.each do |k,v| 84 110 append " " 85 start_group :param, key 86 append "=" 87 start_group :value, value 111 if v =~ /[^\\]'/ 112 v = "\"#{v}\"" 113 else 114 v = "'#{v}'" 115 end 116 start_group :param, k.to_s 117 append '=' 118 start_group :value, v 88 119 end 89 start_group :punct, "#{trailing}>" 90 elsif html = scan(/<\/?[^>]+>/) 120 start_group :tag, "#{trailing}>" 121 elsif dotag = scan(/<([^>]+)do\s*=([^>]+)>/) 122 if dotag =~ /\A<(\w+)([^>]*?)do\s*=('|")([^\3]*?[^\\])\3([^>]*?)(\/?)>/ 123 start_group :tag, "<#{$1}#{$2}" 124 start_group :tag, "do=" 125 start_group :ztag, "'#{$4}'" 126 trailing = $6 127 params = parse_params($5) 128 params.each do |k,v| 129 append " " 130 if v =~ /[^\\]'/ 131 v = "\"#{v}\"" 132 else 133 v = "'#{v}'" 134 end 135 if k == :do 136 start_group :tag, k.to_s 137 append '=' 138 start_group :ztag, v 139 else 140 start_group :param, k.to_s 141 append '=' 142 start_group :value, v 143 end 144 end 145 start_group :tag, "#{trailing}>" 146 else 147 start_group :normal, dotag 148 end 149 elsif html = scan(/\A<\/?[^>]+>/) 91 150 html =~/<\/?([^>]+)>/ 92 151 start_group :tag, html trunk/lib/parser/lib/rules/zazen.rb
r279 r340 39 39 def scan 40 40 #puts "SCAN:[#{@text}]" 41 if @text =~ /\A([^!"<]*)/ 41 if @text =~ /\A([^!"<]*)/m 42 42 flush $& 43 43 if @text[0..0] == '!' … … 47 47 elsif @text[0..4] == '<code' 48 48 scan_code 49 elsif @text =~ /\A([^>]*)>/ 49 elsif @text =~ /\A([^>]*)>/m 50 50 flush $& 51 51 else … … 61 61 def scan_exclam 62 62 #puts "EXCL:[#{@text}]" 63 if @text =~ /\ !\[([^\]]*)\]\!/63 if @text =~ /\A\!\[([^\]]*)\]\!/m 64 64 # create a gallery ![...]! 65 65 eat $& … … 69 69 store @helper.trans('[gallery]') 70 70 end 71 elsif @text =~ /\ !([^0-9]{0,2})\{([^\}]*)\}\!/71 elsif @text =~ /\A\!([^0-9]{0,2})\{([^\}]*)\}\!/m 72 72 # list of documents !<.{...}! 73 73 eat $& … … 77 77 store @helper.trans('[documents]') 78 78 end 79 elsif @text =~ /\ !([^0-9]{0,2})([0-9]+)(\.([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/79 elsif @text =~ /\A\!([^0-9]{0,2})([0-9]+)(\.([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/m 80 80 # image !<.12.pv/blah blah!:12 81 #puts "IMAGE:[#{$&}]" 81 82 eat $& 82 83 store @helper.make_image(:style=>$1, :id=>$2, :size=>$4, :title=>$6, :link=>$8, :images=>@context[:images]) … … 88 89 89 90 def scan_quote 90 if @text =~ / "([^"]*)":([0-9]+)/91 if @text =~ /\A"([^"]*)":([0-9]+)/m 91 92 eat $& 92 93 # link inside the cms "":34 … … 99 100 def scan_wiki 100 101 #puts "WIKI:[#{@text}]" 101 if @text =~ /\A([^\?])*/ 102 if @text =~ /\A([^\?])*/m 102 103 flush $& 103 104 scan_wiki_link … … 109 110 110 111 def scan_wiki_link 111 if @text =~ /\ ?(\w[^\?]+?\w)\?([^\w:]|:([^\s]+))/112 if @text =~ /\A\?(\w[^\?]+?\w)\?([^\w:]|:([^\s]+))/m 112 113 eat $& 113 114 title = $1 … … 134 135 @escaped_at = [] 135 136 block_counter = -1 136 text.gsub!( /(\A|[^\w])@(.*?)@(\Z|[^\w])/ ) do137 text.gsub!( /(\A|[^\w])@(.*?)@(\Z|[^\w])/m ) do 137 138 @escaped_at << $2 138 139 block_counter += 1 … … 145 146 params, text = $1, $2 146 147 divparams = [] 147 if params =~ / ^(.*)lang\s*=\s*("|')([^"']+)\2(.*)$/148 if params =~ /\A(.*)lang\s*=\s*("|')([^"']+)\2(.*)\Z/m 148 149 pre, lang, post = $1.strip, $3, $4.strip 149 150 divparams << pre if pre && pre != "" trunk/lib/parser/test/parser_test.rb
r315 r340 33 33 testfile :zafu, :zafu_asset, :zafu_insight, :zazen 34 34 def test_single 35 do_test('za fu', 'names')35 do_test('zazen', 'gallery_and_images') 36 36 end 37 37 def test_zazen_image_no_image 38 38 file = 'zazen' 39 39 test = 'image_no_image' 40 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=> DummyHelper.new(@@test_strings[file])).render(:images=>false)40 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>ParserModule::DummyHelper.new(@@test_strings[file])).render(:images=>false) 41 41 assert_equal @@test_strings[file][test]['res'], res 42 42 end trunk/lib/parser/test/testhelp.rb
r317 r340 52 52 53 53 def do_test(file, test) 54 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=> DummyHelper.new(@@test_strings[file])).render54 res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>ParserModule::DummyHelper.new(@@test_strings[file])).render 55 55 if @@test_strings[file][test]['res'] 56 56 if @@test_strings[file][test]['res'][0..0] == "/" trunk/lib/parser/test/zazen.yml
r279 r340 27 27 src: "this ![12,13]! gallery" 28 28 res: "<p>this [make_gallery |12,13|] gallery</p>" 29 30 gallery_and_images: 31 src: | 32 33 !23! 34 35 ![12]! 36 res: "<p>[make_image id:|23| images:true style:||]</p>\n\n\n\t<p>[make_gallery |12|]</p>" 29 37 30 38 gallery_children: trunk/public/stylesheets/popup.css
r338 r340 60 60 #image_tab .toggle_div, #document_tab .toggle_div { margin-top: 1em; margin-bottom:0.5em;} 61 61 #file, #file_form { height:2em;} 62 #image_tab img {border:1px solid #333; margin-top:4px;} 62 63 #image_tab, #document_tab { padding-left:3em; padding-top:3em; } 63 64 #image_tab a, #document_tab a { width:80px; display:block; float:left;} trunk/test/functional/document_controller_test.rb
r319 r340 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 require ' main_controller'2 require 'document_controller' 3 3 4 4 # Re-raise errors caught by the controller. … … 33 33 def test_create_pdf 34 34 login(:tiger) 35 post 'create', :document=>{:parent_id=>nodes_id(:zena), :c_file=>uploaded_pdf('water.pdf')} 35 preserving_files('/data/test/pdf') do 36 post 'create', :document=>{:parent_id=>nodes_id(:zena), :c_file=>uploaded_pdf('water.pdf')} 37 assert_response :redirect 38 assert_redirected_to :action=>'show', :id=>assigns(:document)[:id] 39 zena = secure(Node) { nodes(:zena) } 40 docs = zena.documents 41 assert_equal 'water', docs[0][:name] 42 end 43 end 44 45 def test_show 46 get 'show' 47 assert_redirected_to :controller=>'main', :action=>'not_found' 48 get 'show', :id=>nodes_id(:bird_jpg) 36 49 assert_response :success 37 assert_template 'document/create' 38 zena = secure(Node) { nodes(:zena) } 39 docs = zena.documents 40 assert_equal 'water', docs[0][:name] 50 assert_template 'document/show' 41 51 end 42 52 trunk/test/functional/main_controller_test.rb
r338 r340 49 49 def test_index 50 50 assert_routing '/en', {:controller=>'main', :action=>'index', :prefix=>'en'} 51 assert_routing '/', {:controller=>'main', :action=>' redirect'}51 assert_routing '/', {:controller=>'main', :action=>'show', :path=>[]} 52 52 get 'index' 53 53 assert_redirected_to :controller=>'main', :action=>'index', :prefix=>'en' 54 54 get 'index', :prefix=>'en' 55 assert_response :success56 55 assert_response :success 57 56 end trunk/test/zena_test_controller.rb
r338 r340 14 14 post 'login', :user=>{:login=>visitor.to_s, :password=>visitor.to_s} 15 15 @controller_bak.instance_variable_set(:@session, @controller.instance_variable_get(:@session) ) 16 puts @controller.instance_variable_get(:@session).inspect17 16 @controller_bak.instance_variable_set(:@visitor, nil ) # clear cached visitor 18 17 @controller = @controller_bak
