diff --git a/book/src/creating_templates.md b/book/src/creating_templates.md index 8ce3f08e..b6f8f35b 100644 --- a/book/src/creating_templates.md +++ b/book/src/creating_templates.md @@ -55,6 +55,10 @@ recognized: name: &'a str, } ``` + +* `in_doc` (as `in_doc = true`): + please see the section ["documentation as template code"](#documentation-as-template-code). + * `ext` (as `ext = "txt"`): lets you specify the content type as a file extension. This is used to infer an escape mode (see below), and some web framework integrations use it to determine the content type. @@ -66,6 +70,7 @@ recognized: name: &'a str, } ``` + * `print` (as `print = "code"`): enable debugging by printing nothing (`none`), the parsed syntax tree (`ast`), the generated code (`code`) or `all` for both. The requested data will be printed to stdout at @@ -75,6 +80,7 @@ recognized: #[template(path = "hello.html", print = "all")] struct HelloTemplate<'a> { ... } ``` + * `block` (as `block = "block_name"`): renders the block by itself. Expressions outside of the block are not required by the struct, and inheritance is also supported. This can be useful when you need to @@ -85,6 +91,7 @@ recognized: #[template(path = "hello.html", block = "hello")] struct HelloTemplate<'a> { ... } ``` + * `escape` (as `escape = "none"`): override the template's extension used for the purpose of determining the escaper for this template. See the section on configuring custom escapers for more information. @@ -93,6 +100,7 @@ recognized: #[template(path = "hello.html", escape = "none")] struct HelloTemplate<'a> { ... } ``` + * `syntax` (as `syntax = "foo"`): set the syntax name for a parser defined in the configuration file. The default syntax , "default", is the one provided by Rinja. @@ -101,6 +109,7 @@ recognized: #[template(path = "hello.html", syntax = "foo")] struct HelloTemplate<'a> { ... } ``` + * `config` (as `config = "config_file_path"`): set the path for the config file to be used. The path is interpreted as relative to your crate root. ```rust @@ -110,6 +119,7 @@ recognized: ``` ## Documentation as template code +[#documentation-as-template-code]: #documentation-as-template-code As an alternative to supplying the code template code in an external file (as `path` argument), or as a string (as `source` argument), you can also enable the `"code-in-doc"` feature. diff --git a/rinja_derive/src/lib.rs b/rinja_derive/src/lib.rs index 51570979..4b5f2814 100644 --- a/rinja_derive/src/lib.rs +++ b/rinja_derive/src/lib.rs @@ -63,6 +63,29 @@ use syn::parse_quote_spanned; /// web framework integrations use it to determine the content type. /// Cannot be used together with `path`. /// +/// ### in_doc +/// +/// E.g. `in_doc = true` +/// +/// As an alternative to supplying the code template code in an external file (as `path` argument), +/// or as a string (as `source` argument), you can also enable the `"code-in-doc"` feature. +/// With this feature, you can specify the template code directly in the documentation +/// of the template `struct`. +/// +/// Instead of `path = "…"` or `source = "…"`, specify `in_doc = true` in the `#[template]` +/// attribute, and in the struct's documentation add a ```` ```rinja ```` code block: +/// +/// ```rust,ignore +/// /// ```rinja +/// ///
{{ lines|linebreaksbr }}
+/// /// ``` +/// #[derive(Template)] +/// #[template(ext = "html", in_doc = true)] +/// struct Example<'a> { +/// lines: &'a str, +/// } +/// ``` +/// /// ### print /// /// E.g. `print = "code"`