mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Move filter methods to dsl
This commit is contained in:
		
							parent
							
								
									eb64b52f84
								
							
						
					
					
						commit
						274d34cfc6
					
				
					 2 changed files with 18 additions and 15 deletions
				
			
		|  | @ -1,7 +1,11 @@ | |||
| # Kemal DSL is defined here and it's baked into global scope. | ||||
| # The DSL currently consists of HTTP verbs(get post put patch delete options), | ||||
| # WebSocket(ws) and custom error handler(error). | ||||
| HTTP_METHODS = %w(get post put patch delete options) | ||||
| # The DSL currently consists of | ||||
| # - get post put patch delete options | ||||
| # - WebSocket(ws) | ||||
| # - before_* | ||||
| # - error | ||||
| HTTP_METHODS   = %w(get post put patch delete options) | ||||
| FILTER_METHODS = %w(get post put patch delete options all) | ||||
| 
 | ||||
| {% for method in HTTP_METHODS %} | ||||
|   def {{method.id}}(path, &block : HTTP::Server::Context -> _) | ||||
|  | @ -18,3 +22,14 @@ end | |||
| def error(status_code, &block : HTTP::Server::Context, Exception -> _) | ||||
|   Kemal.config.add_error_handler status_code, &block | ||||
| end | ||||
| 
 | ||||
| # All the helper methods available are: | ||||
| #  - before_all, before_get, before_post, before_put, before_patch, before_delete, before_options | ||||
| #  - after_all, after_get, after_post, after_put, after_patch, after_delete, after_options | ||||
| {% for type in ["before", "after"] %} | ||||
|   {% for method in FILTER_METHODS %} | ||||
|     def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> _) | ||||
|      Kemal::FilterHandler::INSTANCE.{{type.id}}({{method}}.upcase, path, &block) | ||||
|     end | ||||
|   {% end %} | ||||
| {% end %} | ||||
|  |  | |||
|  | @ -83,15 +83,3 @@ module Kemal | |||
|     end | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| # All the helper methods available are: | ||||
| #  - before_all, before_get, before_post, before_put, before_patch, before_delete | ||||
| #  - after_all, after_get, after_post, after_put, after_patch, after_delete | ||||
| ALL_METHODS = %w(get post put patch delete all) | ||||
| {% for type in ["before", "after"] %} | ||||
|   {% for method in ALL_METHODS %} | ||||
|     def {{type.id}}_{{method.id}}(path = "*", &block : HTTP::Server::Context -> _) | ||||
|      Kemal::FilterHandler::INSTANCE.{{type.id}}({{method}}.upcase, path, &block) | ||||
|     end | ||||
|   {% end %} | ||||
| {% end %} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue