Avoid requiring webrick at boot time
This is a bit uglier but allows deferring loading webrick until the serve command is invoked as opposed to when it's required.
This commit is contained in:
		
							parent
							
								
									e99a9e5821
								
							
						
					
					
						commit
						491cce7a99
					
				|  | @ -40,7 +40,7 @@ module Jekyll | ||||||
| 
 | 
 | ||||||
|           s.mount( |           s.mount( | ||||||
|             options['baseurl'], |             options['baseurl'], | ||||||
|             FileHandler, |             custom_file_handler, | ||||||
|             destination, |             destination, | ||||||
|             file_handler_options |             file_handler_options | ||||||
|           ) |           ) | ||||||
|  | @ -99,6 +99,21 @@ module Jekyll | ||||||
|           opts |           opts | ||||||
|         end |         end | ||||||
| 
 | 
 | ||||||
|  |         # Custom WEBrick FileHandler servlet for serving "/file.html" at "/file" | ||||||
|  |         # when no exact match is found. This mirrors the behavior of GitHub | ||||||
|  |         # Pages and many static web server configs. | ||||||
|  |         def custom_file_handler | ||||||
|  |           Class.new WEBrick::HTTPServlet::FileHandler do | ||||||
|  |             def search_file(req, res, basename) | ||||||
|  |               if file = super | ||||||
|  |                 file | ||||||
|  |               else | ||||||
|  |                 super(req, res, "#{basename}.html") | ||||||
|  |               end | ||||||
|  |             end | ||||||
|  |           end | ||||||
|  |         end | ||||||
|  | 
 | ||||||
|         def start_callback(detached) |         def start_callback(detached) | ||||||
|           unless detached |           unless detached | ||||||
|             Proc.new { Jekyll.logger.info "Server running...", "press ctrl-c to stop." } |             Proc.new { Jekyll.logger.info "Server running...", "press ctrl-c to stop." } | ||||||
|  | @ -131,19 +146,6 @@ module Jekyll | ||||||
| 
 | 
 | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       # Custom WEBrick FileHandler servlet for serving "/file.html" at "/file" |  | ||||||
|       # when no exact match is found. This mirrors the behavior of GitHub Pages |  | ||||||
|       # and many static web server configs. |  | ||||||
|       require 'webrick' |  | ||||||
|       class FileHandler < ::WEBrick::HTTPServlet::FileHandler |  | ||||||
|         def search_file(req, res, basename) |  | ||||||
|           if file = super |  | ||||||
|             file |  | ||||||
|           else |  | ||||||
|             super(req, res, "#{basename}.html") |  | ||||||
|           end |  | ||||||
|         end |  | ||||||
|       end |  | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue