Changeset 366
- Timestamp:
- 08/01/07 00:04:00 (1 year ago)
- Files:
-
- trunk/examples/skeleton/dist/conf/merb.yml (modified) (3 diffs)
- trunk/examples/skeleton/dist/conf/router.rb (modified) (1 diff)
- trunk/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb (modified) (1 diff)
- trunk/lib/merb/merb_abstract_controller.rb (modified) (3 diffs)
- trunk/lib/merb/merb_controller.rb (modified) (5 diffs)
- trunk/lib/merb/merb_dispatcher.rb (modified) (2 diffs)
- trunk/lib/merb/merb_drb_server.rb (modified) (1 diff)
- trunk/lib/merb/merb_exceptions.rb (modified) (2 diffs)
- trunk/lib/merb/merb_handler.rb (modified) (6 diffs)
- trunk/lib/merb/merb_mail_controller.rb (modified) (7 diffs)
- trunk/lib/merb/merb_plugins.rb (modified) (1 diff)
- trunk/lib/merb/merb_router.rb (modified) (3 diffs)
- trunk/lib/merb/merb_server.rb (modified) (4 diffs)
- trunk/lib/merb/merb_view_context.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/skeleton/dist/conf/merb.yml
r323 r366 1 1 --- 2 # hostname or IPto bind to.2 # Hostname or IP address to bind to. 3 3 :host: 127.0.0.1 4 4 5 # port merb runs on or starting port for merb cluster.5 # Port merb runs on or starting port for merb cluster. 6 6 :port: "4000" 7 7 8 # in development mode your controler classes get reloaded every request9 # and templates are parsed each time and not cached 10 # in production modetemplates are cached, as well as all your classes8 # In development mode your controller classes get reloaded on every request, 9 # and templates are parsed each time and not cached. In production mode 10 # templates are cached, as well as all your classes 11 11 :environment: development 12 12 13 # uncomment for memory sessions. This only works when 14 # you are running 1 merb at a time. ANd sessions do not persist 15 # between restarts. 13 # Uncomment for memory sessions. This only works when you are running 1 merb 14 # at a time. And sessions do not persist between restarts. 16 15 # :memory_session: true 17 16 … … 22 21 # :mem_cache_session: true 23 22 24 # This turns on the ActiveRecord sessions with rails parasite 25 # mode if active_support gem is installed. Skeleton app comes with a 26 # migration to create the sessions table. Or you can point merb to 27 # the same sessions table that your rails app uses to share sessions 28 # between merb and rails. 23 # This turns on the ActiveRecord sessions with rails parasite mode if 24 # active_support gem is installed. Skeleton app comes with a migration to 25 # create the sessions table. Or you can point merb to the same sessions 26 # table that your rails app uses to share sessions between merb and rails. 29 27 :sql_session: true 30 28 :log_level: debug 31 # uncomment to use the merb upload progress 29 30 # Uncomment to use the merb upload progress 32 31 #:config: dist/conf/upload.conf 33 32 34 # uncomment to cache templates in dev mode.35 # templates are cachedautomatically in production mode.33 # Uncomment to cache templates in dev mode. Templates are cached 34 # automatically in production mode. 36 35 #:cache_templates: true 37 36 38 # uncomment and set this is you want to run a drb39 # server for upload progressor other drb services.37 # Uncomment and set this if you want to run a drb server for upload progress 38 # or other drb services. 40 39 #:drb_server_port: 32323 41 40 42 # If you want to protect some or all of your app with 43 # HTTP basic auth then uncomment the folowing and fill 44 # in your credentials you want it to use. Then you need 45 # to set a before filter in a controller: 46 # before :basic_authentication 41 # If you want to protect some or all of your app with HTTP basic auth then 42 # uncomment the following and fill in your credentials you want it to use. 43 # You will then need to set a 'before' filter in a controller. For example: 44 # before :basic_authentication 47 45 #:basic_auth: 48 46 # :username: ezra … … 50 48 # :domain: localhost 51 49 52 # uncomment this if you want merb to daemonize when you start it53 # you can also just use merb -d for the same effect. Don't uncomment54 # this if you use the cluster option50 # Uncomment this if you want merb to daemonize when you start it. You can also 51 # just use merb -d for the same effect. Don't uncomment this if you use the 52 # cluster option. 55 53 #:daemonize: true 56 54 57 # uncomment this to set the number of members in your merb cluster58 # don't setthis and :daemonize: at the same time.55 # Uncomment this to set the number of members in your merb cluster. Don't set 56 # this and :daemonize: at the same time. 59 57 #:cluster: 3 trunk/examples/skeleton/dist/conf/router.rb
r258 r366 1 1 # Merb::RouteMatcher is the request routing mapper for the merb framework. 2 # You can define placeholder parts of the url with the :s mbol notation.3 # so r.add '/foo/:bar/baz/:id', :class => 'Bar', :method => 'foo'4 # will match against a request to /foo/123/baz/456. It will then5 # use the class Bar as your merb controller and call the foo method on it.6 # the foo method will recieve a hash with {:bar => '123', :id => '456'}7 # as the content. So the :placeholders sections of your routes become8 # a hash of arguments to your controller methods.9 # The default route is installed10 2 # You can define placeholder parts of the url with the :symbol notation. For 3 # example: 4 # 5 # r.add '/admin/:email/users/:id', :controller => 'admin_users', :action => 'foo' 6 # 7 # will match against a request to /admin/me@gmail.com/users/456. It will then 8 # use the class AdminUsers as your merb controller and call the 'foo' method 9 # on it. The 'foo' method will be able to access the :email and :id values via 10 # the 'params' hash, e.g. 'params[:email]' will return 'me@gmail.com'. 11 11 12 12 puts "Compiling routes.." trunk/examples/skeleton/dist/schema/migrations/001_add_sessions_table.rb
r258 r366 2 2 def self.up 3 3 create_table :sessions, :force => true do |t| 4 t.column :session_id, :string, :limit => 325 t.column :created_at, :datetime4 t.column :session_id, :string, :limit => 32 5 t.column :created_at, :datetime 6 6 t.column :data, :text 7 7 end trunk/lib/merb/merb_abstract_controller.rb
r348 r366 91 91 92 92 93 # #before is a class method that allows you to specify before 94 # filters in your controllers. Filters can either be a symbol 95 # or string that corresponds to a method name to call, or a 96 # proc object. if it is a method name that method will be 97 # called and if it is a proc it will be called with an argument 98 # of self where self is the current controller object. When 99 # you use a proc as a filter it needs to take one parameter. 93 # #before is a class method that allows you to specify before filters in 94 # your controllers. Filters can either be a symbol or string that 95 # corresponds to a method name to call, or a proc object. if it is a method 96 # name that method will be called and if it is a proc it will be called 97 # with an argument of self where self is the current controller object. 98 # When you use a proc as a filter it needs to take one parameter. 100 99 # 101 100 # examples: 102 # before :some_filter103 # before :authenticate, :exclude => [:login, :signup]104 # before Proc.new {|c| c.some_method }, :only => :foo101 # before :some_filter 102 # before :authenticate, :exclude => [:login, :signup] 103 # before Proc.new {|c| c.some_method }, :only => :foo 105 104 # 106 105 # You can use either :only => :actionname or :exclude => [:this, :that] … … 108 107 # and :exclude will run for every action that is not listed. 109 108 # 110 # Merb's before filter chain is very flixible. To halt the 111 # filter chain you use throw :halt . If throw is called with 112 # only one argument of :halt the return of the method filters_halted 113 # will be what is rendered to the view. You can overide filters_halted 114 # in your own controllers to control what it outputs. But the throw 115 # construct is much more powerful then just that. throw :halt can 116 # also take a second argument. Here is what that second arg can be 117 # and the behavior each type can have: 109 # Merb's before filter chain is very flexible. To halt the filter chain you 110 # use throw :halt. If throw is called with only one argument of :halt the 111 # return of the method filters_halted will be what is rendered to the view. 112 # You can overide filters_halted in your own controllers to control what it 113 # outputs. But the throw construct is much more powerful then just that. 114 # throw :halt can also take a second argument. Here is what that second arg 115 # can be and the behavior each type can have: 118 116 # 119 # when the second arg is a string then that string will be what 120 # is rendered to the browser. Since merb's render method returns 121 # a string you can render a template or just use a plain string: 117 # * String: 118 # when the second arg is a string then that string will be what 119 # is rendered to the browser. Since merb's render method returns 120 # a string you can render a template or just use a plain string: 122 121 # 123 # String: 124 # throw :halt, "You don't have permissions to do that!" 125 # throw :halt, render(:action => :access_denied) 122 # throw :halt, "You don't have permissions to do that!" 123 # throw :halt, render(:action => :access_denied) 126 124 # 127 # if the second arg is a symbol then the method named after that 128 # symbol will be called 129 # Symbol: 130 # throw :halt, :must_click_disclaimer 125 # * Symbol: 126 # If the second arg is a symbol then the method named after that 127 # symbol will be called 131 128 # 132 # If the second arg is a Proc, it will be called and its return 133 # value will be what is rendered to the browser: 134 # Proc: 135 # throw :halt, Proc.new {|c| c.access_denied } 136 # throw :halt, Proc.new {|c| Tidy.new(c.index) } 129 # throw :halt, :must_click_disclaimer 130 # 131 # * Proc: 132 # 133 # If the second arg is a Proc, it will be called and its return 134 # value will be what is rendered to the browser: 135 # 136 # throw :halt, Proc.new {|c| c.access_denied } 137 # throw :halt, Proc.new {|c| Tidy.new(c.index) } 137 138 # 138 139 def self.before(filter, opts={}) … … 154 155 end 155 156 156 # #after is a class method that allows you to specify after 157 # filters in your controllers. Filters can either be a symbol 158 # or string that corresponds to a method name or a proc object. 159 # if it is a method name that method will be called and if it 160 # is a proc it will be called with an argument of self. When 161 # you use a proc as a filter it needs to take one parameter. 162 # you can gain access to the response body like so: 163 # after Proc.new {|c| Tidy.new(c.body) }, :only => :index 164 # 157 # #after is a class method that allows you to specify after filters in your 158 # controllers. Filters can either be a symbol or string that corresponds to 159 # a method name or a proc object. If it is a method name that method will 160 # be called and if it is a proc it will be called with an argument of self. 161 # When you use a proc as a filter it needs to take one parameter. You can 162 # gain access to the response body like so: after Proc.new {|c| 163 # Tidy.new(c.body) }, :only => :index 165 164 def self.after(filter, opts={}) 166 165 raise(ArgumentError, trunk/lib/merb/merb_controller.rb
r348 r366 44 44 end 45 45 46 # parses the http request into params, headers and cookies 47 # that you can use in your controller classes. Also handles 48 # file uploads by writing a tempfile and passing a reference 49 # in params. 46 # Parses the http request into params, headers and cookies that you can use 47 # in your controller classes. Also handles file uploads by writing a 48 # tempfile and passing a reference in params. 50 49 def parse_request(req, env, args, resp) 51 50 env = env.to_hash … … 74 73 @_cookies[_session_id_key] = @_params[_session_id_key] 75 74 elsif @_params.key?(_session_id_key) && Merb::Server.config[:session_id_cookie_only] 76 #This conditions allows for certain controller/action paths to allow a session ID to be passed in a 77 #query string. This is needed for Flash Uploads to work since flash will not pass a Session Cookie 78 #Recommend running session.regenerate after any controller taking advantage of this in case someone 79 #is attempting a session fixation attack 75 # This condition allows for certain controller/action paths to allow a 76 # session ID to be passed in a query string. This is needed for Flash 77 # Uploads to work since flash will not pass a Session Cookie Recommend 78 # running session.regenerate after any controller taking advantage of 79 # this in case someone is attempting a session fixation attack 80 80 @_cookies[_session_id_key] = @_params[_session_id_key] if Merb::Server.config[:query_string_whitelist].include?("#{params[:controller]}/#{params[:action]}") 81 81 end 82 82 83 # Handle alternate HTTP method passed as _method parameter. 84 # Doesn't allow method to be overridden for :get 85 # unless Merb is in development mode. 86 # 87 # i.e. You can pass _method=put on the querystring if you are in 83 # Handle alternate HTTP method passed as _method parameter. Doesn't allow 84 # method to be overridden for :get unless Merb is in development mode. 85 # 86 # i.e. You can pass _method=put on the querystring if you are in 88 87 # development mode. 89 88 allow = [:post, :put, :delete] … … 113 112 end 114 113 115 # accessor for @_body. Please use status and 116 # never @status directly. 114 # Accessor for @_body. Please use status and never @status directly. 117 115 def body 118 116 @_body 119 117 end 120 118 121 # accessor for @_status. Please use status and 122 # never @_status directly. 119 # Accessor for @_status. Please use status and never @_status directly. 123 120 def status 124 @_status 121 @_status 125 122 end 126 127 # accessor for @_request. Please use request and 128 # never @_request directly. 123 124 # Accessor for @_request. Please use request and never @_request directly. 129 125 def request 130 @_request 126 @_request 131 127 end 132 133 # accessor for @_params. Please use params and 134 # never @_params directly. 128 129 # Accessor for @_params. Please use params and never @_params directly. 135 130 def params 136 131 @_params 137 end 132 end 138 133 139 # accessor for @_cookies. Please use cookies and 140 # never @_cookies directly. 134 # Accessor for @_cookies. Please use cookies and never @_cookies directly. 141 135 def cookies 142 136 @_cookies 143 end 144 145 # accessor for @_headers. Please use headers and 146 # never @_headers directly. 137 end 138 139 # Accessor for @_headers. Please use headers and never @_headers directly. 147 140 def headers 148 141 @_headers 149 142 end 150 143 151 # accessor for @_session. Please use session and 152 # never @_session directly. 144 # Accessor for @_session. Please use session and never @_session directly. 153 145 def session 154 146 @_session 155 147 end 156 148 157 # accessor for @_response. Please use response and 158 # never @_response directly. 149 # Accessor for @_response. Please use response and never @_response directly. 159 150 def response 160 151 @_response … … 162 153 163 154 # Sends a mail from a MailController 164 # 165 # send_mail FooMailer, :bar, :from => "foo@bar.com", :to => "baz@bat.com"155 # 156 # send_mail FooMailer, :bar, :from => "foo@bar.com", :to => "baz@bat.com" 166 157 # 167 158 # would send an email via the FooMailer's bar method. 168 # 169 # mail_params, a hash, would be sent to the mailer, and includes items like from, to 170 # subject, and cc. See Merb::MailController#dispatch_and_deliver for more details. 171 # 172 # send_params, a hash, would be sent to the MailController, and is available to methods 173 # in the MailController as <tt>params</tt>. If you do not send any send_params, this 174 # controller's params will be available to the MailController as <tt>params</tt> 159 # 160 # The mail_params hash would be sent to the mailer, and includes items 161 # like from, to subject, and cc. See 162 # Merb::MailController#dispatch_and_deliver for more details. 163 # 164 # The send_params hash would be sent to the MailController, and is 165 # available to methods in the MailController as <tt>params</tt>. If you do 166 # not send any send_params, this controller's params will be available to 167 # the MailController as <tt>params</tt> 175 168 def send_mail(klass, method, mail_params, send_params = nil) 176 169 klass.new(send_params || params, self).dispatch_and_deliver(method, mail_params) … … 190 183 # 191 184 # class Foo < Application 192 # def some action185 # def some_action 193 186 # wrap_layout(part(TodoPart => :new) + part(TodoPart => :list)) 194 187 # end trunk/lib/merb/merb_dispatcher.rb
r355 r366 12 12 @@mutex = Mutex.new 13 13 @@use_mutex = ::Merb::Server.use_mutex 14 # This is where we grab the incoming request REQUEST_URI 15 # and use that in the merb routematcher to determine 16 # which controller and method to run. 17 # returns a 2 element tuple of: 18 # [controller, action] 14 # This is where we grab the incoming request REQUEST_URI and use that in 15 # the merb RouteMatcher to determine which controller and method to run. 16 # Returns a 2 element tuple of: [controller, action] 19 17 def handle(request, response) 20 18 start = Time.now … … 57 55 end 58 56 59 # take a controller class name string and reload or require 60 # the right controller file then CamelCase it and return the 61 # class object 57 # Take a controller class name string and reload or require the right 58 # controller file then CamelCase it and return the class object. 62 59 def resolve_controller(controller_name) 63 60 segments = controller_name.split('/').map{|s| s.snake_case} trunk/lib/merb/merb_drb_server.rb
r150 r366 15 15 end 16 16 17 end 17 end 18 18 19 20 end 19 end trunk/lib/merb/merb_exceptions.rb
r309 r366 15 15 16 16 end 17 # format exception message for browser display 17 18 # Format exception message for browser display. 18 19 def self.html_exception(e) 19 20 if ::Merb::Server.show_error … … 60 61 end 61 62 62 # this method offers highlighting for the sourcecode-chunks from the63 # traceback , just gem install coderay63 # This method offers highlighting for the sourcecode-chunks from the 64 # traceback. Just 'gem install coderay'. 64 65 def error_page(colors, title, *backtrace) 65 66 @backtrace = backtrace trunk/lib/merb/merb_handler.rb
r325 r366 13 13 @@file_only_methods = ["GET","HEAD"] 14 14 15 # take the name of a directory and use that as the doc root or public15 # Take the name of a directory and use that as the doc root or public 16 16 # directory of your site. This is set to the root of your merb app + '/public' 17 17 # by default. … … 21 21 22 22 # process incoming http requests and do a number of things 23 # 1. check for rails style cached pages. add .html to the 24 # url and see if there is a static file in public that matches. 25 # serve that file directly without invoking Merb and be done with it. 26 # 2. Serve static asset and html files directly from public/ if 27 # they exist. 28 # 3. If none of the above apply, we take apart the request url 29 # and feed it into Merb::RouteMatcher to let it decide which 30 # controller and method will serve the request. 31 # 4. after the controller has done its thing, we check for the 32 # X-SENDFILE header. if you set this header to the path to a file 33 # in your controller then mongrel will serve the file directly 34 # and your controller can go on processing other requests. 23 # 1. Check for rails style cached pages. add .html to the url and see if 24 # there is a static file in public that matches. serve that file directly 25 # without invoking Merb and be done with it. 26 # 2. Serve static asset and html files directly from public/ if they exist. 27 # 3. If none of the above apply, we take apart the request url and feed it 28 # into Merb::RouteMatcher to let it decide which controller and method will 29 # serve the request. 30 # 4. After the controller has done its thing, we check for the X-SENDFILE 31 # header. if you set this header to the path to a file in your controller 32 # then mongrel will serve the file directly and your controller can go on 33 # processing other requests. 35 34 def process(request, response) 36 35 … … 44 43 MERB_LOGGER.info("\nRequest: REQUEST_URI: #{request.params[Mongrel::Const::REQUEST_URI]} (#{Time.now.strftime("%Y-%m-%d %H:%M:%S")})") 45 44 46 # Rails style page caching. Check the public dir first for 47 # .html pages and serve directly. Otherwise fall back to Merb48 # routing and request dispatching.45 # Rails style page caching. Check the public dir first for .html pages and 46 # serve directly. Otherwise fall back to Merb routing and request 47 # dispatching. 49 48 path_info = request.params[Mongrel::Const::PATH_INFO] 50 49 page_cached = path_info + ".html" … … 82 81 sendfile, clength = nil 83 82 response.status = controller.status 84 # check for the X-SENDFILE header from your Merb::Controller85 # and servethe file directly instead of buffering.83 # Check for the X-SENDFILE header from your Merb::Controller and serve 84 # the file directly instead of buffering. 86 85 controller.headers.each do |k, v| 87 86 if k =~ /^X-SENDFILE$/i … … 105 104 # Calculated the same as apache, not sure how well the works on win32 106 105 response.header[Mongrel::Const::ETAG] = Mongrel::Const::ETAG_FORMAT % [file_status.mtime.to_i, file_status.size, file_status.ino] 107 # send a status with out content length106 # Send a status with out content length 108 107 response.send_status(file_status.size) 109 108 response.send_header … … 121 120 controller.body.call 122 121 else 123 # render response from successful controller122 # Render response from successful controller 124 123 body = (controller.body.to_s rescue '') 125 124 response.send_status(body.length) trunk/lib/merb/merb_mail_controller.rb
r289 r366 11 11 attr_reader :session, :base_controller 12 12 13 # You can initialize a MailController with a series of parameters that can be used 14 # by methods in the class. You can also pass in a controller object, which will be 15 # available to the MailController methods as base_controller. 13 # You can initialize a MailController with a series of parameters that can 14 # be used by methods in the class. You can also pass in a controller 15 # object, which will be available to the MailController methods as 16 # base_controller. 16 17 def initialize(params = {}, controller = nil) 17 18 @params = params … … 23 24 end 24 25 25 # Allows you to render various types of things into the text and HTML parts of an email 26 # If you include just text, the email will be sent as plain-text. If you include HTML, 27 # the email will be sent as a multi-part email. 28 # 29 # There are a lot of ways to use render_mail, but it works similarly to the default 30 # Merb render method. 31 # 32 # First of all, you'll need to store email files in your dist/app/mailers/views directory. 33 # They should be under a directory that matches the name of your mailer (e.g. TestMailer's 34 # views would be stored under test_mailer). 35 # 36 # The files themselves should be named action_name.mime_type.extension. For example, a 37 # herb template that should be the HTML part of the email, and rendered from the "foo" 38 # action would be named foo.html.herb. 39 # 40 # The only mime-types currently supported are "html" and "text", which correspond to 41 # text/html and text/plain respectively. All template systems supported by your app are 42 # available to MailController, and the extensions are the same as they are throughout the 43 # rest of Merb. 26 # Allows you to render various types of things into the text and HTML parts 27 # of an email If you include just text, the email will be sent as 28 # plain-text. If you include HTML, the email will be sent as a multi-part 29 # email. 30 # 31 # There are a lot of ways to use render_mail, but it works similarly to the 32 # default Merb render method. 33 # 34 # First of all, you'll need to store email files in your 35 # dist/app/mailers/views directory. They should be under a directory that 36 # matches the name of your mailer (e.g. TestMailer's views would be stored 37 # under test_mailer). 38 # 39 # The files themselves should be named action_name.mime_type.extension. For 40 # example, a herb template that should be the HTML part of the email, and 41 # rendered from the "foo" action would be named foo.html.herb. 42 # 43 # The only mime-types currently supported are "html" and "text", which 44 # correspond to text/html and text/plain respectively. All template systems 45 # supported by your app are available to MailController, and the extensions 46 # are the same as they are throughout the rest of Merb. 44 47 # 45 48 # render_mail can take any of the following option patterns: … … 47 50 # render_mail 48 51 # 49 # will attempt to render the current action. If the current action is "foo", this50 # is identical to render_mail :foo52 # will attempt to render the current action. If the current action is 53 # "foo", this is identical to render_mail :foo. 51 54 # 52 55 # render_mail :foo … … 56 59 # render_mail :action => {:html => :foo, :text => :bar} 57 60 # 58 # checks for foo.html.ext and bar.text.ext in the view directory of the current59 # c ontroller and adds them to the mail object if found61 # checks for foo.html.ext and bar.text.ext in the view directory of the 62 # current controller and adds them to the mail object if found 60 63 # 61 64 # render_mail :template => {:html => "foo/bar", :text => "foo/baz"} 62 65 # 63 # checks for bar.html.ext and baz.text.ext in the foo directory and adds them64 # t o the mail object if found.66 # checks for bar.html.ext and baz.text.ext in the foo directory and adds 67 # them to the mail object if found. 65 68 # 66 69 # render_mail :html => :foo, :text => :bar … … 70 73 # render_mail :html => "FOO", :text => "BAR" 71 74 # 72 # adds the text "FOO" as the html part of the email and the text "BAR" as the73 # t ext part of the email. The difference between the last two examples is that74 # symbols represent actions to render, while string represent the literal text75 # to render. Note that you can use regular render methods instead76 # of literal strings here, like:75 # adds the text "FOO" as the html part of the email and the text "BAR" as 76 # the text part of the email. The difference between the last two examples 77 # is that symbols represent actions to render, while string represent the 78 # literal text to render. Note that you can use regular render methods 79 # instead of literal strings here, like: 77 80 # 78 81 # render_mail :html => render(:action => :foo) 79 82 # 80 # but you're probably better off just using render_mail :action at that point. 83 # but you're probably better off just using render_mail :action at that 84 # point. 81 85 # 82 86 # You can also mix and match: … … 121 125 end 122 126 123 # Attaches a file or multiple files to an email. You call this from a method in your MailController124 # (including a before filter).125 # 127 # Attaches a file or multiple files to an email. You call this from a 128 # method in your MailController (including a before filter). 129 # 126 130 # attach File.open("foo") 127 131 # attach [File.open("foo"), File.open("bar")] 128 # 129 # You can also include the filename, mime-type, or headers in the subsequent parameters. 130 # 131 # If you are passing an array of files, you should use an array of the allowed parameters: 132 # 133 # attach [[File.open("foo"), "bar", "text/html"], [File.open("baz"), "bat", "text/css"] 134 # 135 # which would attach two files ("foo" and "baz" in the filesystem) as "bar" and "bat" respectively. 136 # It would also set the mime-type as "text/html" and "text/css" respectively. 132 # 133 # You can also include the filename, mime-type, or headers in the 134 # subsequent parameters. 135 # 136 # If you are passing an array of files, you should use an array of the 137 # allowed parameters: 138 # 139 # attach [[File.open("foo"), "bar", "text/html"], [File.open("baz"), 140 # "bat", "text/css"] 141 # 142 # which would attach two files ("foo" and "baz" in the filesystem) as 143 # "bar" and "bat" respectively. It would also set the mime-type as 144 # "text/html" and "text/css" respectively. 137 145 def attach( file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil, 138 146 type = nil, headers = nil) … … 148 156 # subject 149 157 # body 150 # replyto151 158 # cc 152 159 # 153 # other parameters passed in will be interpreted as email headers, with _'s converted160 # Other parameters passed in will be interpreted as email headers, with _'s converted 154 161 # to -'s. 155 162 def dispatch_and_deliver(method, mail_params) trunk/lib/merb/merb_plugins.rb
r286 r366 276 276 277 277 module Gem 278 # Fixes a bug in RubyGems where the SilentProgressReporter class 279 # i s inaccurately named SilentReporter280 # Maybe one day we'll monkeypatch this forour own purposes.278 # Fixes a bug in RubyGems where the SilentProgressReporter class is 279 # inaccurately named SilentReporter. Maybe one day we'll monkeypatch this for 280 # our own purposes. 281 281 class SilentProgressReporter 282 282 attr_reader :count trunk/lib/merb/merb_router.rb
r286 r366 88 88 end 89 89 90 # the final compiled lambda that gets used91 # as the body of theroute_request method.90 # The final compiled lambda that gets used as the body of the 91 # route_request method. 92 92 def compiled_statement 93 93 @compiled_statement … … 98 98 end 99 99 100 # add a route to be compiled100 # Add a route to be compiled. 101 101 def add(*route) 102 102 @routes << [route[0], (route[1] || {})] 103 103 end 104 104 105 # build up a string that defines a lambda 106 # that does a case statement on the PATH_INFO 107 # against each of the compiled routes in turn. 108 # first route that matches wins. 105 # Build up a string that defines a lambda that does a case statement on 106 # the PATH_INFO against each of the compiled routes in turn. First route 107 # that matches wins. 109 108 def compile_router 110 109 router_lambda = @routes.inject("lambda{|path| \n sections={}\n case path\n") { |m,r| … … 115 114 end 116 115 117 # compile each individual route into a when /.../ 118 # component of the case statement. Takes /:sections 119 # of the route def that start with : and turns them 120 # into placeholders for whatever urls match against 121 # the route in question. 116 # Compile each individual route into a when /.../ component of the case 117 # statement. Takes /:sections of the route def that start with : and 118 # turns them into placeholders for whatever urls match against the route 119 # in question. 122 120 def compile(route) 123 121 raise ArgumentError unless String === route[0] trunk/lib/merb/merb_server.rb
r353 r366 39 39 opts = OptionParser.new do |opts| 40 40 opts.banner = "Usage: merb [fdcepghmisluMG] [argument]" 41 opts.define_head "Merb Mongrel+ Erb. Lightweight replacement for ActionPack "41 opts.define_head "Merb Mongrel+ Erb. Lightweight replacement for ActionPack." 42 42 opts.separator '*'*80 43 opts.separator 'If no flags are given, Merb starts in the foreground on port 4000 '43 opts.separator 'If no flags are given, Merb starts in the foreground on port 4000.' 44 44 opts.separator '*'*80 45 45 … … 52 52 end 53 53 54 opts.on("-f", "--config-file FILENAME", "This flag is for adding extra config files for things like the upload progress module ") do |config|54 opts.on("-f", "--config-file FILENAME", "This flag is for adding extra config files for things like the upload progress module.") do |config| 55 55 options[:config] = config 56 56 end 57 57 58 opts.on("-d", "--daemonize", "This will run a single merb in the background ") do |config|58 opts.on("-d", "--daemonize", "This will run a single merb in the background.") do |config| 59 59 options[:daemonize] = true 60 60 end 61 61 62 opts.on("-c", "--cluster-nodes NUM_MERBS", "Number of merb daemons to run ") do |nodes|62 opts.on("-c", "--cluster-nodes NUM_MERBS", "Number of merb daemons to run.") do |nodes| 63 63 options[:cluster] = nodes 64 64 end 65 65 66 opts.on("-p", "--port PORTNUM", "Port to run merb on, defaults to 4000 ") do |port|66 opts.on("-p", "--port PORTNUM", "Port to run merb on, defaults to 4000.") do |port| 67 67 options[:port] = port 68 68 end 69 69 70 opts.on("-h", "--host HOSTNAME", "Host to bind to (default is all IP's)") do |host|70 opts.on("-h", "--host HOSTNAME", "Host to bind to (default is all IP's).") do |host| 71 71 options[:host] = host 72 72 end 73 73 74 opts.on("-m", "--merb-root MERB_ROOT", " the path to the MERB_ROOT for the app you want to run") do |merb_root|74 opts.on("-m", "--merb-root MERB_ROOT", "The path to the MERB_ROOT for the app you want to run (default is current working dir).") do |merb_root| 75 75 options[:merb_root] = File.expand_path(merb_root) 76 76 end … … 80 80 end 81 81 82 opts.on("-s", "--start-drb PORTNUM", "This is the port number to run the drb daemon on for sessions and uplo d progress monitoring.") do |drb_port|82 opts.on("-s", "--start-drb PORTNUM", "This is the port number to run the drb daemon on for sessions and upload progress monitoring.") do |drb_port| 83 83 options[:start_drb] = true 84 84 options[:only_drb] = true … … 94 94 end 95 95 96 opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]", "Command-line option to run scripts and/or code in the merb app ") do |stuff_to_run|96 opts.on("-r", "--script-runner ['RUBY CODE'| FULL_SCRIPT_PATH]", "Command-line option to run scripts and/or code in the merb app.") do |stuff_to_run| 97 97 options[:runner] = stuff_to_run 98 98 end 99 99 100 opts.on("-g", "--generate-app PATH", "Generate a fresh merb app at PATH ") do |path|100 opts.on("-g", "--generate-app PATH", "Generate a fresh merb app at PATH.") do |path| 101 101 options[:generate] = path || Dir.pwd 102 102 end 103 103 104 opts.on("-P", "--plugin ACTION NAME", "Do ACTION with a plugin called NAME ") do |action|104 opts.on("-P", "--plugin ACTION NAME", "Do ACTION with a plugin called NAME.") do |action| 105 105 options[:plugin] = [action, ARGV] || nil 106 106 end 107 107 108 opts.on("-k", "--kill PORT or all", "Kill one merb proceses by port number. use merb -k all to kill all merbs ") do |ports|108 opts.on("-k", "--kill PORT or all", "Kill one merb proceses by port number. use merb -k all to kill all merbs.") do |ports| 109 109 options[:kill] = ports 110 110 end 111 111 112 opts.on("-M", "--merb-config FILENAME", "This flag is for explicitly declaring the merb app's config file ") do |config|112 opts.on("-M", "--merb-config FILENAME", "This flag is for explicitly declaring the merb app's config file.") do |config| 113 113 options[:merb_config] = config 114 114 end trunk/lib/merb/merb_view_context.rb
r299 r366 20 20 module GlobalHelper 21 21 end 22 # the ViewContext is really 23 # just an empty container for us to fill with instance 24 # variables from the controller, include helpers into 25 # and then use as the context object passed to Erubis 26 # when evaluating the templates. 22 # The ViewContext is really just an empty container for us to fill with 23 # instance variables from the controller, include helpers into and then use as 24 # the context object passed to Erubis when evaluating the templates. 27 25 class ViewContext 28 26 include Merb::ViewContextMixin
