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.
|
- Easy to learn and start to develop.
|
||||||
- Since it's working on LLVM, it's too fast.
|
- Since it's working on LLVM, it's too fast.
|
||||||
- Easy deploment to *Heroku*.
|
- Easy deployment to *Heroku*.
|
||||||
|
|
||||||
## The Name
|
## The Name
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ Kemal means *Mature, grown up* in Turkish.
|
||||||
|
|
||||||
- [Getting Started Tutorial](./tutorial.md)
|
- [Getting Started Tutorial](./tutorial.md)
|
||||||
- [Using Dynamic Views](./views.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)
|
- [Uploading Files](./upload.md)
|
||||||
- [Serving Static Files](./statics.md)
|
- [Serving Static Files](./statics.md)
|
||||||
- [Serving JSON API](./json.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
|
```ruby
|
||||||
# Matches /hello/kemal
|
# Matches /hello/kemal
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Serving JSON API
|
# 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
|
```ruby
|
||||||
require "kemal"
|
require "kemal"
|
||||||
|
|
|
@ -5,13 +5,13 @@ Add your files to `public` directory and Kemal will serve these files immediatel
|
||||||
```
|
```
|
||||||
app/
|
app/
|
||||||
src/
|
src/
|
||||||
awesome_web_project.cr
|
your_app.cr
|
||||||
public/
|
public/
|
||||||
js/
|
js/
|
||||||
jquery.js
|
jquery.js
|
||||||
awesome_web_project.js
|
your_app.js
|
||||||
css/
|
css/
|
||||||
awesome_web_project.css
|
your_app.css
|
||||||
index.html
|
index.html
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ Open index.html and add
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script src="/js/jquery.js"></script>
|
<script src="/js/jquery.js"></script>
|
||||||
<script src="/js/awesome_web_project.js"></script>
|
<script src="/js/your_app.js"></script>
|
||||||
<link rel="stylesheet" href="/css/awesome_web_project.css"/>
|
<link rel="stylesheet" href="/css/your_app.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
...
|
...
|
||||||
|
|
|
@ -12,8 +12,8 @@ brew install crystal-lang
|
||||||
You should create your application first:
|
You should create your application first:
|
||||||
|
|
||||||
```
|
```
|
||||||
crystal init app awesome_web_project
|
crystal init app your_app
|
||||||
cd awesome_web_project
|
cd your_app
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add *kemal* to the `shard.yml` file as a dependency.
|
Then add *kemal* to the `shard.yml` file as a dependency.
|
||||||
|
@ -41,7 +41,7 @@ Installing kemal (master)
|
||||||
|
|
||||||
## 3. Include Kemal into your project
|
## 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
|
```ruby
|
||||||
require 'kemal'
|
require 'kemal'
|
||||||
|
@ -60,21 +60,18 @@ end
|
||||||
All the code should look like this:
|
All the code should look like this:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
require "./crystal_test/*"
|
|
||||||
require "kemal"
|
require "kemal"
|
||||||
|
|
||||||
module AwesomeWebProject
|
|
||||||
get "/" do
|
get "/" do
|
||||||
"Hello World!"
|
"Hello World!"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 5. Run your awesome web project.
|
## 5. Run your awesome web project.
|
||||||
|
|
||||||
```
|
```
|
||||||
crystal build --release src/awesome_web_project.cr
|
crystal build --release src/your_app.cr
|
||||||
./awesome_web_project
|
./your_app
|
||||||
```
|
```
|
||||||
|
|
||||||
You should see some logs like these:
|
You should see some logs like these:
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
# Views
|
# 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.
|
library.
|
||||||
|
|
||||||
|
## Embedding View File
|
||||||
|
|
||||||
|
```crystal
|
||||||
|
get '/' do |env|
|
||||||
|
your_name = "Kemal"
|
||||||
|
render "views/hello.ecr"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## Writing Views
|
## 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/
|
src/
|
||||||
|
@ -17,12 +27,3 @@ Write `hello.ecr`
|
||||||
```erb
|
```erb
|
||||||
Hello <%= your_name %>
|
Hello <%= your_name %>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Embedding View File
|
|
||||||
|
|
||||||
```crystal
|
|
||||||
get '/' do |env|
|
|
||||||
your_name = "Kemal"
|
|
||||||
render "views/hello.ecr"
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
Loading…
Reference in a new issue