mirror of
https://github.com/actix/actix-website
synced 2024-11-23 16:31:08 +01:00
Added basic example with includes
This commit is contained in:
parent
aebbfbf9db
commit
e204566062
@ -23,21 +23,7 @@ The prefix should consist of value path segments.
|
||||
> any request with the paths `/app`, `/app/`, or `/app/test` would match;
|
||||
> however, the path `/application` would not match.
|
||||
|
||||
```rust
|
||||
# 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();
|
||||
}
|
||||
```
|
||||
{{< include-example example="application" section="setup" >}}
|
||||
|
||||
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.
|
||||
|
1
examples/.gitignore
vendored
Normal file
1
examples/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target
|
4
examples/Cargo.toml
Normal file
4
examples/Cargo.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"application",
|
||||
]
|
6
examples/application/Cargo.toml
Normal file
6
examples/application/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "application"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "0.6"
|
15
examples/application/src/main.rs
Normal file
15
examples/application/src/main.rs
Normal 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>
|
7
layouts/shortcodes/include-example.html
Normal file
7
layouts/shortcodes/include-example.html
Normal 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" "" -}}
|
Loading…
Reference in New Issue
Block a user