Changeset 216

Show
Ignore:
Timestamp:
04/27/07 13:42:20 (2 years ago)
Author:
e.@brainspl.at
Message:

updating readme and added stream_file for streaming

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r209 r216  
    189189*Controllers have powerful before and after filters* 
    190190 
    191 Use the before method in your controllers. before accepts either a symbol  
    192 or a Proc/lambda object. If you give it a symbol it will call a method with 
    193 the same name as the symbol. If you give it a proc that takes one argument  
    194 it will call the proc with the current controller as that argument. You can  
    195 use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam] 
    196 array of symbols. 
     191Use the before method in your controllers. before accepts either a symbol, string or a Proc/lambda object. If you give it a symbol it will call a method with the same name as the symbol. If you give it a proc that takes one argument it will call the proc with the current controller as that argument. You can use :only and :exclude as options to your filters to exclude or include actionsfrom certain filters. :only and :exclude take :symbols or [:sym, :sam] array of symbols. 
    197192 
    198193class Foo < Merb::Controller 
     
    232227# halts the chain and returns whatever is in the string 
    233228 
    234 throw :halt, "<h1>You don't have permissions IDIOT!</h1>" 
     229throw :halt, "<h1>You don't have permissions dude!</h1>" 
    235230 
    236231or even render templates: 
     
    247242 
    248243Helpers: dist/app/helpers/global_helper.rb will be available to all of your views. 
    249  Helpers named afdter your controller plus _helper.rb will be included in the views 
     244 Helpers named after your controller plus _helper.rb will be included in the views 
    250245 for that controller only. 
    251246 
     
    274269This is one of the things that Merb was written for. Rails doesn't allow  
    275270multiple concurrent file uploads at once without blocking an entire rails backend for each file upload. Merb allows multiple file uploads at once. 
    276 progress bar. When a file is uploaded with Merb, it gets put in a Tempfile. So  
     271 When a file is uploaded with Merb, it gets put in a Tempfile. So  
    277272you just want to copy it to the right place on the filesystem. 
    278273 
     
    289284:filename => File.basename(filename),   
    290285:content_type => content_type,   
    291 :tempfile => body,  
     286:tempfile => <Tempfile>,  
    292287:size => File.size(body)  
    293288} 
  • trunk/lib/merb/merb_controller.rb

    r200 r216  
    8282      call_filters(after_filters)  
    8383      finalize_session if respond_to?:finalize_session 
    84       MERB_LOGGER.info("Time spent in #{action} action: #{Time.now - start} seconds") 
     84      MERB_LOGGER.info("Time spent in #{self.class}##{action} action: #{Time.now - start} seconds") 
    8585    end 
    8686     
  • trunk/lib/merb/merb_handler.rb

    r198 r216  
    6363    else 
    6464      begin 
    65         # dLet Merb:Dispatcher find the route and call the filter chain and action 
     65        # Let Merb:Dispatcher find the route and call the filter chain and action 
    6666        controller = nil 
    6767        controller, action = Merb::Dispatcher.handle(request, response) 
  • trunk/lib/merb/merb_router.rb

    r207 r216  
    7575    # of the route def that start with : and turns them 
    7676    # into placeholders for whatever urls match against 
    77     # the route in question. Special case for the default 
    78     # /:controller/:action/:id route. 
     77    # the route in question. 
    7978    def self.compile(route) 
    8079      raise ArgumentError unless String === route[0] 
     
    159158    def self.generate_resources_routes(res,opt) 
    160159      with_options :controller => res.to_s, :rest => true do |r| 
    161         r.add "#{opt[:prefix]}/#{res}/:id[;/]edit", :allowed => {:get => 'edit'} 
    162         r.add "#{opt[:prefix]}/#{res}/new[;/]:action", :allowed => {:get => 'new', :post => 'new', :put => 'new', :delete => 'new'} 
     160        r.add "#{opt[:prefix]}/#{res}/:id[;/]+edit", :allowed => {:get => 'edit'} 
     161        r.add "#{opt[:prefix]}/#{res}/new[;/]+:action", :allowed => {:get => 'new', :post => 'new', :put => 'new', :delete => 'new'} 
    163162        r.add "#{opt[:prefix]}/#{res}/new" , :allowed => {:get => 'new'} 
    164163        if mem = opt[:member] 
    165164          mem.keys.sort_by{|x| "#{x}"}.each {|action| 
    166165            allowed = mem[action].injecting({}) {|h, verb| h[verb] = "#{action}"} 
    167             r.add "#{opt[:prefix]}/#{res}/:id[;/]#{action}", :allowed => allowed 
     166            r.add "#{opt[:prefix]}/#{res}/:id[;/]+#{action}", :allowed => allowed 
    168167          } 
    169168        end 
     
    171170          coll.keys.sort_by{|x| "#{x}"}.each {|action| 
    172171            allowed = coll[action].injecting({}) {|h, verb| h[verb] = "#{action}"} 
    173             r.add "#{opt[:prefix]}/#{res}[;/]#{action}", :allowed => allowed 
     172            r.add "#{opt[:prefix]}/#{res}[;/]+#{action}", :allowed => allowed 
    174173          } 
    175174        end   
     
    183182    def self.generate_singleton_routes(res,opt) 
    184183      with_options :controller => res.to_s, :rest => true do |r| 
    185         r.add "#{opt[:prefix]}/#{res}[;/]edit", :allowed => {:get => 'edit'} 
     184        r.add "#{opt[:prefix]}/#{res}[;/]+edit", :allowed => {:get => 'edit'} 
    186185        r.add "#{opt[:prefix]}/#{res}\\.:format", :allowed => {:get => 'show'} 
    187186        r.add "#{opt[:prefix]}/#{res}/new" , :allowed => {:get => 'new'} 
  • trunk/lib/merb/mixins/controller_mixin.rb

    r209 r216  
    168168    end 
    169169     
     170    # stream_file( { :filename => file_name,  
     171    #                :type => content_type, 
     172    #                :content_length => content_length }) do 
     173    #   @response.send_status(opts[:content_length]) 
     174    #   @response.send_header 
     175    #   AWS::S3::S3Object.stream(user.folder_name + "-" + user_file.unique_id, bucket_name) do |chunk| 
     176    #       @response.write chunk 
     177    #   end 
     178    # end 
     179    def stream_file(opts={}, &stream) 
     180      opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts)) 
     181      disposition = opts[:disposition].dup || 'attachment' 
     182      disposition << %(; filename="#{opts[:filename]}") 
     183      @response.headers.update( 
     184        'Content-Type'              => opts[:type].strip,  # fixes a problem with extra '\r' with some browsers 
     185        'Content-Disposition'       => disposition, 
     186        'Content-Transfer-Encoding' => 'binary', 
     187        'CONTENT-LENGTH'            => opts[:content_length] 
     188      ) 
     189      stream 
     190    end 
     191     
     192 
    170193    # This uses nginx X-Accel-Redirect header to send 
    171194    # a file directly from nginx. See the nginx wiki: