mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	WIP
This commit is contained in:
		
							parent
							
								
									2af03085d2
								
							
						
					
					
						commit
						73d6123f3d
					
				
					 4 changed files with 41 additions and 1 deletions
				
			
		
							
								
								
									
										6
									
								
								spec/asset/hello_with_content_for.ecr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								spec/asset/hello_with_content_for.ecr
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| Hello <%= name %> | ||||
| 
 | ||||
| <% content_for "custom" do |io| %> | ||||
| 	io << "<h1> Hello from otherside </h1>" | ||||
| 	io | ||||
| <% end %> | ||||
							
								
								
									
										3
									
								
								spec/asset/layout_with_yield.ecr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								spec/asset/layout_with_yield.ecr
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| <html><%= content %></html> | ||||
| 
 | ||||
| <%= yield_content "custom" %> | ||||
|  | @ -34,4 +34,14 @@ describe "Views" do | |||
|     client_response = call_request_on_app(request) | ||||
|     client_response.body.should contain("<html>Hello world") | ||||
|   end | ||||
| 
 | ||||
|   it "renders layout with content_for" do | ||||
|     get "/view" do | ||||
|       name = "Kemal" | ||||
|       render "spec/asset/hello_with_content_for.ecr", "spec/asset/layout_with_yield.ecr" | ||||
|     end | ||||
|     request = HTTP::Request.new("GET", "/view") | ||||
|     client_response = call_request_on_app(request) | ||||
|     client_response.body.should contain("<html>Hello world") | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -1,5 +1,18 @@ | |||
| require "kilt" | ||||
| 
 | ||||
| CONTENTS = {} of String => MemoryIO -> String | ||||
| 
 | ||||
| def content_for(name : String, &block : MemoryIO -> String) | ||||
|   puts "Called content_for" | ||||
|   CONTENTS[name] = block | ||||
|   # CONTENTS[name] = block | ||||
| end | ||||
| 
 | ||||
| def yield_content(name) | ||||
|   puts "Called yield_content" | ||||
|   CONTENTS[name].call | ||||
| end | ||||
| 
 | ||||
| # Uses built-in ECR to render views. | ||||
| # # Usage | ||||
| # get '/' do | ||||
|  | @ -7,7 +20,12 @@ require "kilt" | |||
| # end | ||||
| macro render(filename, layout) | ||||
|   content = render {{filename}} | ||||
|   if CONTENTS.size > 0 | ||||
|     puts "CONTENTS greater than 0" | ||||
|     render {{layout}} | ||||
|   else | ||||
|     render {{layout}} | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| macro render(filename, *args) | ||||
|  | @ -20,6 +38,9 @@ macro return_with(env, status_code = 200, response = "") | |||
|   next | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # Adds given HTTP::Handler+ to handlers. | ||||
| def add_handler(handler) | ||||
|   Kemal.config.add_handler handler | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue