mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Update docs
This commit is contained in:
		
							parent
							
								
									c258003b8e
								
							
						
					
					
						commit
						d825b2316a
					
				
					 6 changed files with 29 additions and 31 deletions
				
			
		|  | @ -14,7 +14,7 @@ Crystal is a programming language based on *Ruby* syntax. | |||
| 
 | ||||
|  - Easy to learn and start to develop. | ||||
|  - Since it's working on LLVM, it's too fast. | ||||
|  - Easy deploment to *Heroku*. | ||||
|  - Easy deployment to *Heroku*. | ||||
| 
 | ||||
| ## The Name | ||||
| 
 | ||||
|  | @ -24,7 +24,7 @@ Kemal means *Mature, grown up* in Turkish. | |||
| 
 | ||||
|  - [Getting Started Tutorial](./tutorial.md) | ||||
|  - [Using Dynamic Views](./views.md) | ||||
|  - [Parsing HTTP requests and Form Data](./http-requests.md) | ||||
|  - [HTTP Requests and Responses](./http-requests.md) | ||||
|  - [Uploading Files](./upload.md) | ||||
|  - [Serving Static Files](./statics.md) | ||||
|  - [Serving JSON API](./json.md) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| # HTTP Requests | ||||
| # Handling HTTP Request/Response | ||||
| 
 | ||||
| You should use `env` variable to handle HTTP params. For both `get` and `post` (and others) methods, you should use `env` object. | ||||
| You should use `env` variable to handle HTTP Request/Response. For both `get` and `post` (and others) methods, you should use the yielded `env` object. | ||||
| 
 | ||||
| ```ruby | ||||
| # Matches /hello/kemal | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| # Serving JSON API | ||||
| 
 | ||||
| Just use `to_json` method to return. | ||||
| You need to return a ```JSON``` object or need to convert the existing object via `to_json`. | ||||
| 
 | ||||
| ```ruby | ||||
| require "kemal" | ||||
|  |  | |||
|  | @ -5,13 +5,13 @@ Add your files to `public` directory and Kemal will serve these files immediatel | |||
| ``` | ||||
| app/ | ||||
|   src/ | ||||
|     awesome_web_project.cr | ||||
|     your_app.cr | ||||
|   public/ | ||||
|     js/ | ||||
|       jquery.js | ||||
|       awesome_web_project.js | ||||
|       your_app.js | ||||
|     css/ | ||||
|       awesome_web_project.css | ||||
|       your_app.css | ||||
|     index.html | ||||
| ``` | ||||
| 
 | ||||
|  | @ -21,8 +21,8 @@ Open index.html and add | |||
| <html> | ||||
|  <head> | ||||
|    <script src="/js/jquery.js"></script> | ||||
|    <script src="/js/awesome_web_project.js"></script> | ||||
|    <link rel="stylesheet" href="/css/awesome_web_project.css"/> | ||||
|    <script src="/js/your_app.js"></script> | ||||
|    <link rel="stylesheet" href="/css/your_app.css"/> | ||||
|  </head> | ||||
|  <body> | ||||
|    ... | ||||
|  |  | |||
|  | @ -12,8 +12,8 @@ brew install crystal-lang | |||
| You should create your application first: | ||||
| 
 | ||||
| ``` | ||||
| crystal init app awesome_web_project | ||||
| cd awesome_web_project | ||||
| crystal init app your_app | ||||
| cd your_app | ||||
| ``` | ||||
| 
 | ||||
| Then add *kemal* to the `shard.yml` file as a dependency. | ||||
|  | @ -41,7 +41,7 @@ Installing kemal (master) | |||
| 
 | ||||
| ## 3. Include Kemal into your project | ||||
| 
 | ||||
| Open `awesome_web_project/src/awesome_web_project.cr` and require `kemal` to use Kemal. | ||||
| Open `your_app/src/your_app.cr` and require `kemal` to use Kemal. | ||||
| 
 | ||||
| ```ruby | ||||
| require 'kemal' | ||||
|  | @ -60,21 +60,18 @@ end | |||
| All the code should look like this: | ||||
| 
 | ||||
| ```ruby | ||||
| require "./crystal_test/*" | ||||
| require "kemal" | ||||
| 
 | ||||
| module AwesomeWebProject | ||||
|   get "/" do | ||||
| get "/" do | ||||
|   "Hello World!" | ||||
|   end | ||||
| end | ||||
| ``` | ||||
| 
 | ||||
| ## 5. Run your awesome web project. | ||||
| 
 | ||||
| ``` | ||||
| crystal build --release src/awesome_web_project.cr | ||||
| ./awesome_web_project | ||||
| crystal build --release src/your_app.cr | ||||
| ./your_app | ||||
| ``` | ||||
| 
 | ||||
| You should see some logs like these: | ||||
|  |  | |||
|  | @ -1,11 +1,21 @@ | |||
| # Views | ||||
| 
 | ||||
| You can use ECR to build views. Kemal serves a `render` macro to use built-in `ECR` | ||||
| You can use ECR to build views. Kemal serves a `render` macro to use Crystal's built-in `ECR` | ||||
| library. | ||||
| 
 | ||||
| ## Embedding View File | ||||
| 
 | ||||
| ```crystal | ||||
| get '/' do |env| | ||||
|   your_name = "Kemal" | ||||
|   render "views/hello.ecr" | ||||
| end | ||||
| ``` | ||||
| 
 | ||||
| ## Writing Views | ||||
| 
 | ||||
| The ECR is actually ERB. | ||||
| ECR is pretty similar ERB(from Ruby). As you can see you can easily access the block variables in your view. In this | ||||
| example `your_name` is available for use in the view. | ||||
| 
 | ||||
| ``` | ||||
| src/ | ||||
|  | @ -17,12 +27,3 @@ Write `hello.ecr` | |||
| ```erb | ||||
| Hello <%= your_name %> | ||||
| ``` | ||||
| 
 | ||||
| ## Embedding View File | ||||
| 
 | ||||
| ```crystal | ||||
| get '/' do |env| | ||||
|   your_name = "Kemal" | ||||
|   render "views/hello.ecr" | ||||
| end | ||||
| ``` | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue