Changeset 340

Show
Ignore:
Timestamp:
2007-03-07 22:38:24 (2 years ago)
Author:
gaspard
Message:

Fixed zafu code_syntax. Added do-params recognition.
Fixed zazen bug (images mixed with gallery)
Fixed document controller: using redirect after create
Removed 'redirect' action in main controller

Files:

Legend:

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

    r338 r340  
    1313    pdoc.delete(:c_file) if pdoc[:c_file] == "" 
    1414    @document = secure(Document) { Document.create(pdoc) } 
    15      
    1615    if @document.new_record? 
    1716      render :action=>"new" 
     17    else 
     18      flash[:notice] = trans "Upload succeeded." 
     19      redirect_to :action=>'show', :id=>@document[:id] 
    1820    end 
    19     flash[:notice] = trans "upload succeeded" 
    2021  rescue ActiveRecord::RecordNotFound 
    2122    # user does not have write access to parent. This error should never happen (parent list is filtered) 
    2223    page_not_found 
    2324  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   
    2533  # Get document data (inline if possible) 
    2634  def data 
  • trunk/app/controllers/main_controller.rb

    r338 r340  
    7474  # do not accept a logged in user to browse as if he was anonymous 
    7575  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) 
    7779      redirect_with_prefix 
    78     elsif (params[:action] == 'show' && !params[:path].kind_of?(Array)) 
    79       redirect_to :action=>'index' 
    8080    end 
    8181  end 
  • trunk/app/controllers/search_controller.rb

    r321 r340  
    1717    @results = nil 
    1818    secure(Node) do 
    19       @result_pages, @results = paginate :nodes, :conditions=>conditions, :order => "name ASC", :per_page => 15 
     19      @result_pages, @results = paginate :nodes, :conditions=>conditions, :order => "name ASC", :per_page => 10 
    2020      @results # important: this is the 'secure' yield return, it is used to secure found nodes 
    2121    end 
  • trunk/app/helpers/application_helper.rb

    r338 r340  
    320320      images = @node.images 
    321321    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     
    325328    render_to_string( :partial=>'main/gallery', :locals=>{:gallery=>images} ) 
    326329  end 
  • trunk/app/views/document/_crop.rhtml

    r338 r340  
    11<%= tlink_to_function('cancel', "new Element.toggle('crop', 'crop_form');$('crop_form').innerHTML = '';")%> 
    22x: <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> 
    44<%= @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) }'); }" %> 
    22<div id='form_errors' class='errors'><%= error_messages_for "node" %></div> 
    33<div id='search'><%= search_box %></div> 
     
    99<div class='tab'> 
    1010  <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> 
    1212    <table cellspacing="0" borderspacing="0"> 
    1313      <tr> 
  • trunk/app/views/templates/edit_tabs/_any_image.rhtml

    r338 r340  
    55<% if !ImageBuilder.dummy? %> 
    66<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]}) %> 
    108</div> 
    119<div id="crop_form" class='toggle_div' style='display:none;'></div> 
  • trunk/config/routes.rb

    r338 r340  
    2323    map.connect '*path', :controller=>'main', :action=>'show', :prefix=>''   
    2424  else 
    25     map.connect '', :controller => "main", :action=>'select_prefix' 
    2625    map.site_tree ':prefix/site_tree/:id', :controller=>'main', :action=>'site_tree', :prefix=>/^(#{AUTHENTICATED_PREFIX}|\w\w)$/ 
    2726    map.connect ':prefix/*path', :controller=>'main', :action=>'show', :prefix=>/^(#{AUTHENTICATED_PREFIX}|\w\w)$/ 
    2827    map.default 'z/:controller/:action/:id' 
    29     map.connect '*path', :controller=>'main', :action=>'select_prefix
     28    map.connect '*path', :controller=>'main', :action=>'show
    3029  end 
    3130  ##  
  • trunk/lib/parser/lib/parser.rb

    r317 r340  
    335335    rest = text.strip 
    336336    while (rest != '') 
    337       if rest =~ /(.*?)=/ 
     337      if rest =~ /(.+?)=/ 
    338338        key = $1.strip.to_sym 
    339339        rest = rest[$&.length..-1].strip 
  • trunk/lib/parser/lib/rules/code_syntax.rb

    r279 r340  
    3232      flush_chunk 
    3333      @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 
    3461    end 
    3562  end 
     
    74101class ZafuTokenizer < Syntax::Tokenizer 
    75102  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:" 
    79106      start_group :ztag, $2 
    80107      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| 
    84110        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 
    88119      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<\/?[^>]+>/) 
    91150      html =~/<\/?([^>]+)>/ 
    92151      start_group :tag, html 
  • trunk/lib/parser/lib/rules/zazen.rb

    r279 r340  
    3939    def scan 
    4040      #puts "SCAN:[#{@text}]" 
    41       if @text =~ /\A([^!"<]*)/ 
     41      if @text =~ /\A([^!"<]*)/m 
    4242        flush $& 
    4343        if @text[0..0] == '!' 
     
    4747        elsif @text[0..4] == '<code' 
    4848          scan_code 
    49         elsif @text =~ /\A([^>]*)>/ 
     49        elsif @text =~ /\A([^>]*)>/m 
    5050          flush $& 
    5151        else 
     
    6161    def scan_exclam 
    6262      #puts "EXCL:[#{@text}]" 
    63       if @text =~ /\!\[([^\]]*)\]\!/ 
     63      if @text =~ /\A\!\[([^\]]*)\]\!/m 
    6464        # create a gallery ![...]! 
    6565        eat $& 
     
    6969          store @helper.trans('[gallery]') 
    7070        end 
    71       elsif @text =~ /\!([^0-9]{0,2})\{([^\}]*)\}\!/ 
     71      elsif @text =~ /\A\!([^0-9]{0,2})\{([^\}]*)\}\!/m 
    7272        # list of documents !<.{...}! 
    7373        eat $& 
     
    7777          store @helper.trans('[documents]') 
    7878        end 
    79       elsif @text =~ /\!([^0-9]{0,2})([0-9]+)(\.([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/ 
     79      elsif @text =~ /\A\!([^0-9]{0,2})([0-9]+)(\.([^\/\!]+)|)(\/([^\!]*)|)\!(:([^\s]+)|)/m 
    8080        # image !<.12.pv/blah blah!:12 
     81        #puts "IMAGE:[#{$&}]" 
    8182        eat $& 
    8283        store @helper.make_image(:style=>$1, :id=>$2, :size=>$4, :title=>$6, :link=>$8, :images=>@context[:images]) 
     
    8889     
    8990    def scan_quote 
    90       if @text =~ /"([^"]*)":([0-9]+)/ 
     91      if @text =~ /\A"([^"]*)":([0-9]+)/m 
    9192        eat $& 
    9293        # link inside the cms "":34 
     
    99100    def scan_wiki 
    100101      #puts "WIKI:[#{@text}]" 
    101       if @text =~ /\A([^\?])*/ 
     102      if @text =~ /\A([^\?])*/m 
    102103        flush $& 
    103104        scan_wiki_link 
     
    109110     
    110111    def scan_wiki_link 
    111       if @text =~ /\?(\w[^\?]+?\w)\?([^\w:]|:([^\s]+))/ 
     112      if @text =~ /\A\?(\w[^\?]+?\w)\?([^\w:]|:([^\s]+))/m 
    112113        eat $& 
    113114        title = $1 
     
    134135      @escaped_at = [] 
    135136      block_counter = -1 
    136       text.gsub!( /(\A|[^\w])@(.*?)@(\Z|[^\w])/ ) do 
     137      text.gsub!( /(\A|[^\w])@(.*?)@(\Z|[^\w])/m ) do 
    137138        @escaped_at << $2 
    138139        block_counter += 1 
     
    145146        params, text = $1, $2 
    146147        divparams = [] 
    147         if params =~ /^(.*)lang\s*=\s*("|')([^"']+)\2(.*)$/ 
     148        if params =~ /\A(.*)lang\s*=\s*("|')([^"']+)\2(.*)\Z/m 
    148149          pre, lang, post = $1.strip, $3, $4.strip 
    149150          divparams << pre if pre && pre != "" 
  • trunk/lib/parser/test/parser_test.rb

    r315 r340  
    3333  testfile :zafu, :zafu_asset, :zafu_insight, :zazen 
    3434  def test_single 
    35     do_test('zafu', 'names') 
     35    do_test('zazen', 'gallery_and_images') 
    3636  end 
    3737  def test_zazen_image_no_image 
    3838    file = 'zazen' 
    3939    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) 
    4141    assert_equal @@test_strings[file][test]['res'], res 
    4242  end 
  • trunk/lib/parser/test/testhelp.rb

    r317 r340  
    5252   
    5353  def do_test(file, test) 
    54     res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>DummyHelper.new(@@test_strings[file])).render 
     54    res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>ParserModule::DummyHelper.new(@@test_strings[file])).render 
    5555    if @@test_strings[file][test]['res'] 
    5656      if @@test_strings[file][test]['res'][0..0] == "/" 
  • trunk/lib/parser/test/zazen.yml

    r279 r340  
    2727  src: "this ![12,13]! gallery" 
    2828  res: "<p>this [make_gallery |12,13|] gallery</p>" 
     29 
     30gallery_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>" 
    2937 
    3038gallery_children: 
  • trunk/public/stylesheets/popup.css

    r338 r340  
    6060#image_tab .toggle_div, #document_tab .toggle_div { margin-top: 1em; margin-bottom:0.5em;} 
    6161#file, #file_form { height:2em;} 
     62#image_tab img {border:1px solid #333; margin-top:4px;} 
    6263#image_tab, #document_tab { padding-left:3em; padding-top:3em; } 
    6364#image_tab a, #document_tab a { width:80px; display:block; float:left;} 
  • trunk/test/functional/document_controller_test.rb

    r319 r340  
    11require File.dirname(__FILE__) + '/../test_helper' 
    2 require 'main_controller' 
     2require 'document_controller' 
    33 
    44# Re-raise errors caught by the controller. 
     
    3333  def test_create_pdf 
    3434    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) 
    3649    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' 
    4151  end 
    4252   
  • trunk/test/functional/main_controller_test.rb

    r338 r340  
    4949  def test_index 
    5050    assert_routing '/en', {:controller=>'main', :action=>'index', :prefix=>'en'} 
    51     assert_routing '/', {:controller=>'main', :action=>'redirect'
     51    assert_routing '/', {:controller=>'main', :action=>'show', :path=>[]
    5252    get 'index' 
    5353    assert_redirected_to :controller=>'main', :action=>'index', :prefix=>'en' 
    5454    get 'index', :prefix=>'en' 
    55     assert_response :success 
    5655    assert_response :success 
    5756  end 
  • trunk/test/zena_test_controller.rb

    r338 r340  
    1414    post 'login', :user=>{:login=>visitor.to_s, :password=>visitor.to_s} 
    1515    @controller_bak.instance_variable_set(:@session, @controller.instance_variable_get(:@session) ) 
    16     puts @controller.instance_variable_get(:@session).inspect 
    1716    @controller_bak.instance_variable_set(:@visitor, nil ) # clear cached visitor 
    1817    @controller = @controller_bak