1
0
mirror of https://github.com/actix/actix-website synced 2024-11-27 18:12:57 +01:00

Added basic example with includes

This commit is contained in:
Armin Ronacher 2018-05-23 21:28:12 +02:00
parent aebbfbf9db
commit e204566062
6 changed files with 34 additions and 15 deletions

View File

@ -23,21 +23,7 @@ The prefix should consist of value path segments.
> any request with the paths `/app`, `/app/`, or `/app/test` would match; > any request with the paths `/app`, `/app/`, or `/app/test` would match;
> however, the path `/application` would not match. > however, the path `/application` would not match.
```rust {{< include-example example="application" section="setup" >}}
# extern crate actix_web;
# use actix_web::{App, Responder, HttpRequest, http::Method};
fn index(req: HttpRequest) -> impl Responder {
"Hello world!"
}
fn main() {
let app = App::new()
.prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish();
}
```
In this example, an application with the `/app` prefix and a `index.html` resource In this example, an application with the `/app` prefix and a `index.html` resource
are created. This resource is available through the `/app/index.html` url. are created. This resource is available through the `/app/index.html` url.

1
examples/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target

4
examples/Cargo.toml Normal file
View File

@ -0,0 +1,4 @@
[workspace]
members = [
"application",
]

View File

@ -0,0 +1,6 @@
[package]
name = "application"
version = "0.1.0"
[dependencies]
actix-web = "0.6"

View File

@ -0,0 +1,15 @@
extern crate actix_web;
use actix_web::{App, Responder, HttpRequest, http::Method};
// <setup>
fn index(req: HttpRequest) -> impl Responder {
"Hello world!"
}
fn main() {
let app = App::new()
.prefix("/app")
.resource("/index.html", |r| r.method(Method::GET).f(index))
.finish();
}
// </setup>

View File

@ -0,0 +1,7 @@
{{$example := .Get "example"}}
{{$file := .Get "file" | default "main.rs"}}
{{$section := .Get "section"}}
{{$source := readFile (printf "examples/%s/src/%s" $example $file)}}
{{$source := index (findRE (printf "(?ms)// <%s>$(.*?)// </%s>" $section $section) $source) 0 }}
{{$source := trim (replaceRE "// <[^>]+>" "" $source) "\n" }}
{{- highlight $source "rust" "" -}}