Rust Compiled Templates with static-file handling

Overview

Rust Compiled Templates — ructe

This is my attempt at writing a HTML template system for Rust. Some inspiration comes from the scala template system used in play 2, as well as plain old jsp.

Crate docs CI

Design criteria

  • As many errors as possible should be caught at compile-time.
  • A compiled binary should include all the template code it needs, no need to read template files at runtime.
  • Compilation may take time, running should be fast.
  • Writing templates should be almost as easy as writing html.
  • The template language should be as expressive as possible.
  • It should be possible to write templates for any text-like format, not only html.
  • Any value that implements the Display trait should be outputable.
  • By default, all values should be html-escaped. There should be an easy but explicit way to output preformatted html.

Current status

Ructes is in a rather early stage, but does work; templates can be transpiled to rust functions, which are then compiled and can be called from rust code.

Template format

A template consists of three basic parts: First a preamble of use statements, each prepended by an @ sign. Secondly a declaration of the parameters the template takes. And third, the template body.

The full syntax is described in the documentation. Some examples can be seen in examples/simple/templates. A template may look something like this:

@use any::rust::Type;
@use super::statics::style_css;

@(name: &str, items: &[Type])

<html>
   <head>
     <title>@name</title>
     <link rel="stylesheet" href="/static/@style_css.name" type="text/css"/>
   </head>
   <body>
     <h1>@name</h1>
     <dl>
     @for item in items {
       <dt>@item.title()</dt>
       <dd>@item.description()</dd>
     }
     </dl>
   <body>
</html>

How to use ructe

Ructe compiles your templates to rust code that should be compiled with your other rust code, so it needs to be called before compiling, as described in the documentation. There are also examples, both for ructe itself and its futures and for using it with the web frameworks actix-web, gotham, iron. nickel, tide, and warp, There is also a separate example of using ructe with warp and diesel.

Comments
  • Support () in expressions

    Support () in expressions

    As per #2 ructe does not reliably find whole Rust expressions. A workaround for that could be supporting () as a special case. Because Rust guarantees all parenthesis are balanced in valid expressions, ructe won't need to parse full expressions, just tokenize (to skip string literals) and balance parens.

    @if let Some(i) = Some(1) {
        @i+1 // prints 1+1
        @(i+1) // error, but should be supported
    }
    

    For basic arithmetic I'm working around this using .saturating_add(1), but it's a bit silly.

    In some cases I also need more complex expressions, e.g. to convert Option<String> to Option<&str> an ugly .as_ref().map(|s| s.as_str()) is needed, but this expression is too complex for Ructe.

    enhancement 
    opened by kornelski 10
  • New bindings (or arbitrary code)

    New bindings (or arbitrary code)

    Hi.

    First of all kudos on making the only templating library I can actually use for productive work in the whole rust ecosystem.

    Would you be interested in merging a pull request adding arbitrary code evaluation and bindings?

    For the usual case where one needs a shorthand for a nested value, or bind the result of a helper to then inspect it (ie, grouping a list in groups of 3).

    I can settle for an idiomatic best practice too, any suggestions there?

    Thanks again, awesome library.

    opened by nubis 8
  • How to deal with `#[warn(clippy::too_many_arguments)]`

    How to deal with `#[warn(clippy::too_many_arguments)]`

    We've recently started a PR to clippy-fy our code https://github.com/Plume-org/Plume/pull/462 and we're hitting some limits in Ructe, with regard to how templates are generated as functions

    in our case, as functions with lots of parameters, despite having extracted a BaseContext

    Here's an example of such a function: https://github.com/Plume-org/Plume/blob/master/templates/posts/details.rs.html#L12

    opened by igalic 7
  • Use direct write calls instead of write! macro

    Use direct write calls instead of write! macro

    The write macro needs to create a Formatter and Arguments. Where possible, I've replaced it with write_str/write_all that are direct write calls.

    io::Write doesn't have write_str, only binary write_all, so in generated templates binary strings b"foo" are used where possible.

    opened by kornelski 7
  • Template direcrory structure

    Template direcrory structure

    @kaj Thank you for really awesome Template Engine. I provide several tests and it is extremely fast, compile-time template checking. But it is inconvenient thing - I can't structuring my templates. Fro example:

    templates/
        admin/
            main.rs.html
        layouts/
            _header.rs.html
            main.rs.html
    

    Are you planning implement it?

    opened by mrLSD 6
  • Allow `else if` conditions

    Allow `else if` conditions

    Can't compile this simple template:

    @()
    
    @if false {
    1
    } else if false {
    2
    } else {
    3
    }
    

    It says:

    warning: Template parse error in "templates\\test.rs.html":
    warning:    5:} else if false {
    warning:                      ^ Error in expression starting here:
    

    If I remove the else if condition, then it will compile.

    rustc 1.44.0 (49cae5576 2020-06-01) cargo 1.44.0 (05d080faa 2020-05-06) ructe 0.11.4

    enhancement 
    opened by Aunmag 5
  • SVG commit was a semver-breaking change

    SVG commit was a semver-breaking change

    2e4173eead901e2904c7a59d41fee2f8baafb473 renamed template functions, which broke all existing code.

    Can you revert the change, or yank 0.7.4 and release it as 0.8?

    opened by kornelski 5
  • end of expression

    end of expression

    Currently ructe, inspired by twirl, uses a special character (@) to signal the start of an expression, but nothing special to signal the end of an expression. This is very nice when writing simple expressions surrounded by whitespace, tags, or anything else that doesn't look like a part of an expression, but it requires ructe to know the syntax of valid rust expressions and it is problematic if an expression should be immediately followed by something that looks like an expressions.

    Should support for an optional — or required — end-of-expression marker be added? Maybe something like {=expression}? Otherwise, the expression parser will need to be improved. If I do and an end-of-expression marker, it will change the syntax of valid templates, so it should probably be decided one way or the other as soon as possible.

    How about @…\n for simple stuff and @{…} for more complicated stuff (where could contain new lines only in the latter case)?

    opened by ConnyOnny 5
  • Does using include_bytes! for static files impact incremental compile times?

    Does using include_bytes! for static files impact incremental compile times?

    I like the idea of using build.rs to implement cache busting for static files.

    I've used a hand coded technique similar to Ructe but instead of including the file in the final build executable they get loaded by the web server instead.

    Is it possible to setup Ructe to work this way. So for example

    statics::favicon_png.name would still give me the name with a hash

    But when accessing the file later on

    data = templates::statics::StaticFile::get(&name)

    I would want data.file_name instead of data.content

    And with the original file name I can let actix or whatever load the file and return the contents.

    So the executable won't have all the static files embedded.

    My reasoning for this is that I suspect it will have an impact on incremental build times, but I'm not sure how to measure that.

    Thanks

    opened by ianpurton 4
  • fix not being able to use Html<T: Display> in templates

    fix not being able to use Html in templates

    Using Html<T: Display> (theoretically) allows printing raw strings without encoding into a template, so it could be used to work around #1. During trying this out, I encountered following error:

       |
    10 | helper().to_html(&mut _ructe_out_)?;
       |          ^^^^^^^ method cannot be called on `ructe::templates::Html<String>` due to unsatisfied trait bounds
       |
      ::: /home/jojii/.cargo/registry/src/github.com-1ecc6299db9ec823/ructe-0.13.4/src/templates/utils.rs:78:1
       |
    78 | pub struct Html<T>(pub T);
       | --------------------------
       | |
       | doesn't satisfy `ructe::templates::Html<String>: _utils::ToHtml`
       | doesn't satisfy `ructe::templates::Html<String>: std::fmt::Display`
       |
       = note: the following trait bounds were not satisfied:
               `ructe::templates::Html<String>: std::fmt::Display`
               which is required by `ructe::templates::Html<String>: _utils::ToHtml`
       = help: items from traits can only be used if the trait is in scope
    help: the following trait is implemented but not in scope; perhaps add a `use` for it:
       |
    1  | use ructe::templates::ToHtml;
       |
    

    By replacing the relative import path in the templates preamble with the absolute module path fixes this issue and one can successfully work around #1
    Note: I haven't looked through all of ructes code so I can't assure they are semantically equivalent

    opened by JojiiOfficial 4
  • Make the signature of templates cleaner.

    Make the signature of templates cleaner.

    This is a breaking change.

    I hope to enable #88 with this signature change, but that doesn't really seem to happen with the change currently in this PR. So I might try a slightly different signature.

    opened by kaj 4
  • Types with lifetimes don't parse as arguments to templates

    Types with lifetimes don't parse as arguments to templates

    Some failing test cases:

    diff --git a/src/template.rs b/src/template.rs
    index d4f5a6a..91112c4 100644
    --- a/src/template.rs
    +++ b/src/template.rs
    @@ -224,6 +224,16 @@ mod test {
             check_type_expr("Vec<Foo,>");
         }
    
    +    #[test]
    +    fn generic_with_lifetime() {
    +        check_type_expr("SomeTypeWithRef<'a>");
    +    }
    +
    +    #[test]
    +    fn generic_with_anonymous_lifetime() {
    +        check_type_expr("SomeTypeWithRef<'_>");
    +    }
    +
         fn check_type_expr(expr: &str) {
             assert_eq!(type_expression(expr.as_bytes()), Ok((&b""[..], ())));
         }
    
    bug 
    opened by wezm 1
  • Wrong documentation in for calling other templates

    Wrong documentation in for calling other templates

    The documentation for calling other templates reports having to add a suffix when calling template functions. The given example did not compile for me.

    What did compile for me was changing base_page_html occurences to just base_page.

    Is the original no longer working due to a breaking chance in 0.14?

    opened by juliankrieger 0
  • directly output string instead of a function

    directly output string instead of a function

    Is it possible to add a feature such that templates to return string instead of function if the feature flag is enabled This makes it easy to onboard to new frameworks. More info at https://github.com/salvo-rs/salvo/issues/147#issuecomment-1242800547.

    // current
    let mut buf = Vec::new();
    templates::hello(&mut buf, "world");
    response.render(buf);
    
    // new
    response.render(templates::hello_world_str("world"));
    

    //cc @chrislearn

    opened by prabirshrestha 0
  • match enum struct variant defect?

    match enum struct variant defect?

    I try to match the following enum with internal struct variants

    pub enum ValidationError {
        LengthOutOfBounds {
            min: usize,
            max: usize,
        },
        InvalidName {
            invalid_chars: Vec<char>,
        },
        UniqueConstraintViolation,
    }
    

    with

    @use crate::ValidationError::{self, *};
    
    @(error: &ValidationError)
    
    @match error {
        UniqueConstraintViolation => {
            This name is taken.
        }
        LengthOutOfBounds { min, max } => {
            This field must contain at min @min and at max @max characters.
        }
        InvalidName { invalid_chars } => {
            @format!("The name must not contain any of the following characters: {:?}", invalid_chars)
        }
    }
    

    The error message is:

    warning: Template parse error in "template_src/validation_error_display_part.rs.html":
    warning:    5:@match error {
    warning:      ^ Error in expression starting here:
    warning:    5:@match error {
    warning:             ^ Error in match expression:
    warning:    8:    }
    warning:           ^ Error in match arm starting here:
    

    this works:

    @use crate::ValidationError::{self, *};
    
    @(error: &ValidationError)
    
    @match error {
        UniqueConstraintViolation(value) => {
            This name is taken.
        }
        _ => {
            other error
        }
    }
    

    In rust this works:

    impl<'s> std::fmt::Display for ValidationError<'s> {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
            use ValidationError::*;
            match self {
                LengthOutOfBounds { min, max } => {
                    write!(
                        f,
                        "This field must contain at min {} and at max {} characters.",
                        min, max
                    )
                }
                InvalidName {
                    invalid_chars,
                } => {
                    write!(
                        f,
                        "The name must not contain any of the following characters: {:?}",
                        invalid_chars
                    )
                }
                UniqueConstraintViolation => {
                    write!(f, "This name is taken.")
                }
            }
        }
    }
    

    Am I doing something wrong? Is this a defect of the library?

    I enjoy using ructe 🦀 thankyou for sharing 🙏

    opened by LittleEntity 2
  • [Feature Proposal] Utilize macros

    [Feature Proposal] Utilize macros

    It would be nice if templates could be rendered without using build scripts. The current approach is not very bad, but it could be more ergonomic with macros.

    The pro for using macros is that special build scripts would be unnecessary, and this crate would no longer need "special treatment" to set up. It might also be friendlier for development tools, but I am not entirely sure on this point.

    The con is that, as far as I understand, this would require setting up another ructe-codegen crate that hosts the procedural macro(s). This might also require exposing some previously private apis in altered form.

    For what an api using macros could look like, something like this comes to mind:

    let mut buf = Vec::new();
    render_template!("templates/hello_args_two.rs.html", &mut buf, 25, "prime", false);
    

    At least naively implemented, this has the disadvantage that templates will need to be parsed once for every use of that template. Also having so many arguments is just not very pretty or readable.

    Alternatively, something like

    include_template!("templates/hello_args_two.rs.html");
    // ...
    fn do_template_stuff() {
        let mut buf = Vec::new();
        args_two_html(&mut buf, 25, "prime", false);
        // ...
    }
    

    might be worth considering even though it is imo less intuitive because the macro looks more like a function call than a function definition.

    let hello_args = template!("templates/hello_args_two.rs.html");
    let mut buf = Vec::new();
    hello_args.render(&mut buf, 25, "prime", false);
    

    where template! returns an instance of some struct generated from within the macro might also work.

    As you can tell, this idea is not very fleshed out yet, but I believe it has a lot of potential in making the library easier to use, and I would love to hear ideas and opinions on the matter.

    opened by gpluscb 1
Releases(v0.15.0)
  • v0.15.0(Sep 18, 2022)

    • Breaking change: Most methods of StaticFiles now supports method chaining, by returning Result<&mut Self>, making typical build scripts nicer (PR #115).
    • Update (optional) rsass to 0.26 (PR #116).
    • Some doc improvements.
    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Feb 6, 2022)

    • Breaking change: The generated template functions have a simpler signature.
    • Allow litetimes in template argument types. Issue #106, PR #110.
    • Improve error handling in optional warp support, PR #109.
    • Current stable rust is 1.57, MSRV is now 1.46.0.
    • Update nom dependency to 7.1.0.
    • Update optional rsass to 0.23.0.
    • Update env_logger to 0.9 and gotham to 0.7.1 in examples
    • Dropped support for warp 0.2 (the warp02 feature and example).

    Thanks to @JojiiOfficial for reporting #106.

    Source code(tar.gz)
    Source code(zip)
  • v0.13.4(Jun 25, 2021)

    2021-06-25.

    • Allow else if after an @if block in templates. PR #104, fixes #81.
    • Add a missing } in doc example. PR #102.
    • Update optional rsass to 0.22.0.
    • Updated gotham example to 0.6.0.

    Thanks @bearfrieze for #102 and @Aunmag for #81.

    Tested with rustc 1.53.0, 1.48.0, 1.46.0, 1.44.1, 1.54.0-beta.1 and 1.55.0-nightly (7c3872e6b 2021-06-24).

    Source code(tar.gz)
    Source code(zip)
  • v0.13.2(Mar 14, 2021)

    • Improve formatting of README, PR #100.
    • Update nom to 6.1.0, which raises the MSRV to 0.44
    • Update base64 to 0.13 and itertools to 0.10.
    • Update optional rsass to 0.19.0.
    • Add warp 0.3 feature and example.
    • Add tide 0.16 feaure and update example.
    • Testing is now done with github actions rather than Travis CI.
    • Minor clippy fixes, PR #99.

    Thanks to @ibraheemdev for PR #100.

    Tested with rustc 1.50.0 (cb75ad5db 2021-02-10), 1.48.0 (7eac88abb 2020-11-16), 1.46.0 (04488afe3 2020-08-24), 1.44.1 (c7087fe00 2020-06-17), 1.51.0-beta.6 (6a1835ad7 2021-03-12), 1.52.0-nightly (acca81892 2021-03-13)

    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Nov 15, 2020)

    • Try to improve incremental compile times of projects using ructe by only writing fils if their contents actually changed. Also some code cleanup. PR #97.
    • Update ructe itself to use edition 2018 (it is still useable for projects using both editios). PR #98.
    • Fix StaticFiles::add_files_as for empty to argument and add some more documentation for it. Fixes issue #96.
    • Update optional rsass dependency to 0.16.0.
    • Add optional support for tide 0.14 and 0.15.
    • Update gotham to 0.5 and axtix-web to 3.2 in examples.

    Tested with rustc 1.47.0 (18bf6b4f0 2020-10-07), 1.42.0 (b8cedc004 2020-03-09), 1.40.0 (73528e339 2019-12-16), 1.48.0-beta.8 (121901459 2020-11-08), and 1.50.0-nightly (98d66340d 2020-11-14)

    Source code(tar.gz)
    Source code(zip)
  • v0.12.0(Aug 14, 2020)

    • Issue #79, PR #80 and #94: Support Tide framework by a feature and an example.
    • PR #91: Update basic examples to edition 2018.
    • Issue #68, PR #90: Don't eat whitespace after a for loop.
    • Issue #66, PR #89: Fix parse error for nested braces in expressions.
    • PR #84: Use std::ascii::escape_default.
    • PR #87: Provide ToHtml::to_buffer()
    • Forbid unsafe and undocumented code.
    • The build is on https://travis-ci.com/kaj/ructe now.
    • Internal cleanup.

    Thanks to @Aunmag and @prabirshrestha for reported issues and contributed code.

    Tested with rustc 1.45.2 (d3fb005a3 2020-07-31), 1.42.0 (b8cedc004 2020-03-09), 1.42.0 (b8cedc004 2020-03-09), 1.46.0-beta.4 (32c481e15 2020-08-09), and 1.47.0-nightly (81dc88f88 2020-08-13).

    Source code(tar.gz)
    Source code(zip)
  • v0.11.4(Apr 25, 2020)

  • v0.11.2(Apr 22, 2020)

  • v0.10.0(Apr 19, 2020)

    • Update rsass to 0.13.0 and improve sass error handling.
    • Drop the warp01 feature.
    • PR #72 from @kornelski: Avoid clobbering variable name.
    • Update itertools to 0.9.0 and base64 to 0.12.0.

    Thanks to @kornelski for suggestions and bug reports.

    Tested with rustc 1.42.0 (b8cedc004 2020-03-09), 1.36.0 (a53f9df32 2019-07-03), 1.34.2 (6c2484dc3 2019-05-13), 1.43.0-beta.6 (062dea094 2020-04-18), and 1.44.0-nightly (52fa23add 2020-04-18).

    Source code(tar.gz)
    Source code(zip)
  • v0.9.2(Jan 25, 2020)

    • PR #70, Issue #63: Add feature warp02, supportig warp 0.2.x, and add a name alias warp01 for the old warp 0.1.x feature. Same in examples.
    • PR #69, Issue #67: Anyting that is allowed in a string in Rust should be allowed in a string in ructe.
    • Fix clippy complaints re statics in generated code.
    • Update actix-web example to 2.0.
    • Fix doctest with mime03 feature.

    Thanks to @nocduro and @Aunmag for suggestions and bug reports.

    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Dec 25, 2019)

    • PR #65, Issue #64: An expression starting with paren ends on close.
    • RucteError now implements std::error::Error.
    • Specify which references in examples are dyn or impl.
    • Remove a useless string clone.
    • Update rsass to 0.12.0.

    Thanks to @Aunmag.

    Tested with rustc 1.40.0 (73528e339 2019-12-16), 1.36.0 (a53f9df32 2019-07-03), 1.34.2 (6c2484dc3 2019-05-13), 1.41.0-beta.1 (eb3f7c2d3 2019-12-17), and 1.42.0-nightly (a9c1c04e9 2019-12-24).

    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Nov 6, 2019)

    • Issue #62: New version number due to a semver-breaking change, reported by @kornelski.

    Otherwise same as 0.7.4:

    • PR #55 from kornelski: Improve benchmarks.
    • Part of issue #20: Allow template source files to be named *.rs.svg or *.rs.xml as well as *.rs.html. The generated template functions will simlilarly be suffixed _svg, _xml or _html (any template_html will get a template alias, for backwards compatibility.
    • PR #61 from Eroc33: Improve parsing for tuple and generic type expressions.
    • Fix old doc link in readme.
    • Update dependencies in ructe and examples.

    Thaks to @kornelski and @Eroc33.

    Source code(tar.gz)
    Source code(zip)
  • v0.7.4(Nov 2, 2019)

    Note: This release has been yanked from https://crates.io/ due to a semver-breaking change for 0.7.x. The same code has been re-released as version 0.8.0.

    • PR #55 from kornelski: Improve benchmarks.
    • Part of issue #20: Allow template source files to be named *.rs.svg or *.rs.xml as well as *.rs.html. The generated template functions will simlilarly be suffixed _svg, _xml or _html (any template_html will get a template alias, for backwards compatibility.
    • PR #61 from Eroc33: Improve parsing for tuple and generic type expressions.
    • Fix old doc link in readme.
    • Update dependencies in ructe and examples.

    Thaks to @kornelski and @Eroc33.

    Tested with rustc 1.38.0 (625451e37 2019-09-23), 1.36.0 (a53f9df32 2019-07-03), 1.34.2 (6c2484dc3 2019-05-13), 1.39.0-beta.8 (f6404c5a9 2019-10-30), and rustc 1.40.0-nightly (87cbf0a54 2019-11-01).

    Source code(tar.gz)
    Source code(zip)
  • v0.7.2(Aug 28, 2019)

    • Issue #53, PR #60: Allow empty strings everywhere quoted strings are allowed.
    • Issue #57, PR #59:Accept explicit impl and dyn in types.
    • Relax over-strict whitespace requirements, fix a regression in 0.7.0.
    • PR #56: Require buf reference to implement Write, not buf itself
    • PR #58: Fix warnings in generated code.
    • Remove no-longer-used imports.

    Thanks to @kornelski for multiple contributions.

    Tested with rustc 1.37.0 (eae3437df 2019-08-13), 1.34.2 (6c2484dc3 2019-05-13), 1.32.0 (9fda7c223 2019-01-16), 1.31.1 (b6c32da9b 2018-12-18), 1.38.0-beta.3 (72bfc3753 2019-08-27), 1.39.0-nightly (53df91a9b 2019-08-27).

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Jul 18, 2019)

    • Upgrade nom to 5.0 (#52)
    • Update rsass to 0.11.0 (which also uses nom 5.0)
    • Improve template declaration parsing and diagnostics.
    • PR #50 and #51 from @dkotrada: Fix typos in actix example.
    • Remove deprecated functions.

    Thanks to @dkotrada for your contribution!

    Tested with rustc 1.36.0 (a53f9df32 2019-07-03), rustc 1.34.2 (6c2484dc3 2019-05-13), rustc 1.32.0 (9fda7c223 2019-01-16), rustc 1.31.1 (b6c32da9b 2018-12-18), rustc 1.37.0-beta.3 (2ba6de7e2 2019-07-12), and rustc 1.38.0-nightly (bc2e84ca0 2019-07-17).

    Source code(tar.gz)
    Source code(zip)
  • v0.6.4(Jun 23, 2019)

    • Added more modern rust compiler versions (and dropped 1.26).
    • PR #49: Add an actix example.
    • PR #48 from @Noughmad: Use impl Write or generic argument instead of dynamic traits. Fixes a warning for each template when using edition 2018 in nightly rust.
    • Clearer doc about escaping special characters.
    • PR #46 from @kornelski: Add missing crates keyword

    Thanks to @kornelski and @Noughmad for your contributions!

    Tested with rustc 1.35.0 (3c235d560 2019-05-20), 1.34.2 (6c2484dc3 2019-05-13), 1.32.0 (9fda7c223 2019-01-16), 1.31.1 (b6c32da9b 2018-12-18), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.36.0-beta.5 (07a9daea9 2019-06-07), 1.37.0-nightly (de02101e6 2019-06-22).

    Source code(tar.gz)
    Source code(zip)
  • v0.6.2(Mar 16, 2019)

    • Improved documentation and examples. All public items now have documentation.

    • Improve build-time error handling. If there is an error involving an environment variable, include the variable name in the message.

    • Take more Path build-time arguements AsRef. Make it possible to simpl use a string literal as a path in more places.

    Tested with rustc 1.33.0 (2aa4c46cf 2019-02-28), 1.31.1 (b6c32da9b 2018-12-18), 1.30.1 (1433507eb 2018-11-07), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.34.0-beta.1 (744b374ab 2019-02-26), and 1.35.0-nightly (52e885628 2019-03-15).

    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Mar 14, 2019)

    • Provide a warp feature.

      All my warp + ructe projects use the same RenderRucte extension trait to make calling the templates on generating responses a bit clearer. Provide that trait here as an optional feature.

    • Make the build scripts nicer.

      Provide a struct Ructe with methods to handle the red tape from build scripts. Make the remaining parts of the build scripts shorter and more to the point.

    • Use edition 2018 in warp example.

    • Fix examples lang attribute.

      A whole bunch of examples had the html lang attibute set to sv when the content is actually in English.

    Tested with 1.33.0 (2aa4c46cf 2019-02-28), 1.31.1 (b6c32da9b 2018-12-18), 1.30.1 (1433507eb 2018-11-07), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.34.0-beta.1 (744b374ab 2019-02-26), and 1.35.0-nightly (719b0d984 2019-03-13).

    Source code(tar.gz)
    Source code(zip)
  • v0.5.10(Feb 22, 2019)

    • Convert more file names to rust names (a file name might contain dashes and dots that needs to be converted to something else (underscore) to work in a rust name).
    • Find new files in static dirs (add a cargo:rerun-if-changed line for the directory itself).

    Tested with rustc 1.32.0 (9fda7c223 2019-01-16), 1.31.1 (b6c32da9b 2018-12-18), 1.30.1 (1433507eb 2018-11-07), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.33.0-beta.9 (1f84156d2 2019-02-20), 1.34.0-nightly (633d75ac1 2019-02-21).

    Source code(tar.gz)
    Source code(zip)
  • v0.5.8(Feb 16, 2019)

    • Adapt to rsass 0.9.8 (the sass feature now requires a compiler that supports edition 2018).
    • More compact static data, using byte strings instead of numbers. (i.e. b"\xef\xbb\xbfabc" rather than [239, 187, 191, 65, 66, 67]).
    • Minor internal cleanup.
    • Update bytecount dependency.
    Source code(tar.gz)
    Source code(zip)
  • v0.5.6(Jan 4, 2019)

    • PR #41: Benchmark and improve performance of html-escaping.
    • PR #39: Silence a clippy warning about old syntax in silencing another warning.
    • Update itertools to 0.8 (and env_logger in warp example)

    Thanks to @kornelski for PRs #39 and #41.

    Tested with rustc 1.31.1 (b6c32da9b 2018-12-18), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.32.0-beta.11 (e64fee6a3 2019-01-04), and 1.33.0-nightly (c0bbc3927 2019-01-03).

    Source code(tar.gz)
    Source code(zip)
  • v0.5.4(Nov 30, 2018)

    • Support struct unpacking in @if and @for expressions.

    Tested with rustc 1.30.1 (1433507eb 2018-11-07), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.31.0-beta.19 (42053f9f0 2018-11-26), and 1.32.0-nightly (3e90a12a8 2018-11-29).

    Source code(tar.gz)
    Source code(zip)
  • v0.5.2(Nov 4, 2018)

    • Special case for empty sub-templates, mainly to avoid a warning when compiling generated code.
    • Update md5 to 0.6.
    • Update gotham in example to 0.3.0.
    • Use mime 0.3 in static example, and remove mime03 example.

    Tested with rustc 1.30.0 (da5f414c2 2018-10-24), 1.29.0 (aa3ca1994 2018-09-11), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.31.0-beta.4 (04da282bb 2018-11-01), and 1.32.0-nightly (04fdb44f5 2018-11-03).

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Nov 3, 2018)

    • Support multiple Content arguments. Impl Trait is used to make sub-templates as arguments less magic. This way we can also support more than one Content argument to the same template.
    • PR #36 / Issue #35: Test and fix support for edition=2018. Module paths used by generated code are now compatible with the 2018 edition. Also, some code in examples and documentation use more 2018-friendly module paths.
    • PR 34: Use bytecount rather than simple counting, elide one lifetime.
    • Update nom to 4.1.1, base64 to 0.10.0, bytecount to 0.4, and md5 to 0.5.
    • Update iron to 0.6 and warp to 0.1.9 in examples.
    • Minor cleanup in nickel example.

    Thanks to @KlossPeter for PR #34 and @matthewpflueger for issue #35.

    Tested with rustc 1.30.0 (da5f414c2 2018-10-24), 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.31.0-beta.4 (04da282bb 2018-11-01), and 1.32.0-nightly (8b096314a 2018-11-02).

    Source code(tar.gz)
    Source code(zip)
  • v0.4.4(Sep 6, 2018)

    • Test and fix #33, unduplicate curly brackets.
    • Add @@ escape, producing a single @ sign. Suggested in #33.
    • Some more mime types for static files.
    • Update dependencies: nom 4.0, rsass 0.9.0
    • Add a warp example, and link to kaj/warp-diesel-ructe-sample

    Thanks to @dermetfan for reporting issue #33.

    Tested with rustc 1.28.0 (9634041f0 2018-07-30), 1.27.2 (58cc626de 2018-07-18), 1.26.2 (594fb253c 2018-06-01), 1.25.0 (84203cac6 2018-03-25), 1.24.1 (d3ae9a9e0 2018-02-27), 1.23.0 (766bd11c8 2018-01-01), 1.29.0-beta.12 (4dcf42f98 2018-09-04), 1.30.0-nightly (6e0f1cc15 2018-09-05).

    Source code(tar.gz)
    Source code(zip)
  • v0.4.2(Aug 1, 2018)

    • Test and fix issue #31, comments in body.

    Thanks to @jo-so for reporting the issue, and for the test.

    Tested with rustc 1.23.0 (766bd11c8 2018-01-01), 1.24.1 (d3ae9a9e0 2018-02-27), 1.25.0 (84203cac6 2018-03-25), 1.26.2 (594fb253c 2018-06-01), 1.27.2 (58cc626de 2018-07-18), 1.29.0-beta.1 (a3bef3daf 2018-07-31), 1.29.0-nightly (e94df4acb 2018-07-31).

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Jul 5, 2018)

    Changes since v0.3.16 includes:

    • Template syntax:

      • Allow local ranges (i.e. 2..7) in loop expressions.
      • Allow underscore rust names. There is use for unused variables in templates, so allow names starting with underscore.
      • Issue #24 / PR #28: Allow logic operators in @if ... expressions.
      • Issue #25 / PR #27: Allow much more in parentehsis expressions.
    • Improved examples:

      • A new design for the framework examples web page, using svg graphics.
      • Improve code and inline documentation of iron and nickel examples.
      • Add a similar example with the Gotham framework.
    • Recognize .svg static files.

    • Allocate much fewer strings when parsing expressions in templates.

    • PR #26: use write_all rather than the write! macro in generated code, contributed by @kornelski

    • Fix application/octet-stream MIME type. Contributed by @kornelski.

    • Use write_str/write_all when generating output. Contributed by @kornelski.

    Tested with rustc 1.23.0 (766bd11c8 2018-01-01), 1.24.1 (d3ae9a9e0 2018-02-27), 1.25.0 (84203cac6 2018-03-25), 1.26.2 (594fb253c 2018-06-01), 1.27.0 (3eda71b00 2018-06-19), 1.28.0-beta.6 (915ac6602 2018-06-30), and 1.28.0-nightly (e3bf634e0 2018-06-28).

    Source code(tar.gz)
    Source code(zip)
  • v0.3.16(Apr 8, 2018)

    Changes since 0.3.14 is mainly some internal cleanup, a link fix in README and the option rsass dependency is updated to 0.8.0.

    Tested with rustc 1.23.0 (766bd11c8 2018-01-01), 1.24.1 (d3ae9a9e0 2018-02-27), 1.25.0 (84203cac6 2018-03-25), 1.26.0-beta.2 (0e350672e 2018-04-05), and 1.27.0-nightly (eeea94c11 2018-04-06).

    Source code(tar.gz)
    Source code(zip)
  • v0.3.14(Mar 11, 2018)

    Changes since v0.3.12 includes:

    • Make the space after a comma in list expressions optional.
    • Allow enum variants (and module names) in expressions.
    • Some cleanup in parser code.

    Tested with rustc version 1.18.0 (03fc9d622 2017-06-06), 1.19.0 (0ade33941 2017-07-17), 1.20.0 (f3d6973f4 2017-08-27), 1.21.0 (3b72af97e 2017-10-09), 1.22.1 (05e2e1c41 2017-11-22), 1.23.0 (766bd11c8 2018-01-01), 1.24.1 (d3ae9a9e0 2018-02-27), 1.25.0-beta.9 (16262bb5e 2018-03-09), 1.26.0-nightly (2789b067d 2018-03-06).

    Source code(tar.gz)
    Source code(zip)
  • v0.3.12(Feb 10, 2018)

    Changes since 0.3.10 includes:

    • Add a way to add static files without hashnames. A static file can be added and mapped as an arbitrary name, or a directory can be recursively added with an arbitrary prefix.

    Tested with rustc 1.18.0 (03fc9d622 2017-06-06), 1.19.0 (0ade33941 2017-07-17), 1.20.0 (f3d6973f4 2017-08-27), 1.21.0 (3b72af97e 2017-10-09), 1.22.1 (05e2e1c41 2017-11-22), 1.23.0 (766bd11c8 2018-01-01), 1.24.0-beta.11 (03f456d3c 2018-02-03), and 1.25.0-nightly (3bcda48a3 2018-02-09).

    Source code(tar.gz)
    Source code(zip)
Owner
Rasmus Kaj
Proudly polyglot programmer procrastinating proper parsing procedures performance.
Rasmus Kaj
:pencil: Compile-time HTML templates for Rust

maud Documentation (source) • API reference • Change log Maud is an HTML template engine for Rust. It's implemented as a macro, html!, which compiles

Chris Wong 1.4k Jan 1, 2023
Templates for creating rust projects with a GitHub-managed lifecycle with cargo-generate 🏗️📃

rust-templates Templates for creating rust projects with a GitHub-managed lifecycle with cargo-generate. ??️ ?? What you get: PR build validation usin

Ben Greenier 1 Oct 30, 2021
Quickly create boilerplate projects and templates.

boyl boyl is a command-line tool written in Rust to manage template folders. boyl can copy existing folders (with support for glob-like ignore pattern

Miguel M. 13 Feb 16, 2022
📦 Transpile readable code into DiamondFire templates

Welcome to fudge ?? ?? Transpile readable code into DiamondFire templates Author ?? BumpyBill & DADp Show your support Give a ⭐️ if this project helpe

null 6 Jan 25, 2022
A template for a Rust-powered static-page Try Online interface

rust-tio-template A template for a Rust-powered static-page Try Online interface What is included This is an example setup that enables all of the fol

null 2 Dec 13, 2021
Rust templating with Handlebars

handlebars-rust Handlebars templating language implemented in Rust and for Rust. Handlebars-rust is the template engine that renders the official Rust

Ning Sun 922 Dec 27, 2022
Yarte stands for Yet Another Rust Template Engine

Should we start to worry? bytes-buf feature can produce SIGILL. avx and sse flags are in almost all cpus of x86 and x86_64 architectures. More details

Juan Aguilar 249 Dec 19, 2022
A macro-based html builder for rust

Horrorshow A macro-based html templating library, compatible with stable rust (currently requires rust >= 1.37). Features This crate will degrade grac

Steven Allen 267 Dec 11, 2022
A template engine for Rust based on Jinja2/Django

Tera Tera is a template engine inspired by Jinja2 and the Django template language. <title>{% block title %}{% endblock title %}</title> <ul> {% for u

Vincent Prouillet 2.5k Jan 1, 2023
Hiccup html templating in rust

Hiccup A Clojure's Hiccup inspired macro. At the moment support for inline code execution is not guaranteed. The main objective of this lib is to prev

Julia Naomi 13 May 28, 2022
A flexible template engine for Rust

Rustache Rustache is a Rust implementation of the Mustache spec. Documentation The different Mustache tags are documented at the mustache(5) man page.

rustache 208 May 10, 2022
A minimalist Rust WebAssembly project template

MiniWASM - A minimalist Rust WebAssembly project template This is a minimal Rust-powered WebAssembly application template. It was designed to showcase

Emil Loer 160 Jul 26, 2022
MiniJinja is a powerful but minimal dependency template engine for Rust

MiniJinja: a powerful template engine for Rust with minimal dependencies MiniJinja is a powerful but minimal dependency template engine for Rust which

Armin Ronacher 686 Jan 5, 2023
A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.

Rust on ESP-IDF "Hello, World" template A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework. This is the crate you get when ru

Ivan Markov 140 Jan 4, 2023
A fast & simple boilerplate generator, built with Rust. 🦀

Boom ?? A fast & simple boilerplate generator, built with Rust. Installing boom This package is not yet downloadable on Brew or other package managers

Tristan Edwards 4 Apr 20, 2022
A template for creating services in Rust using Axum and Prisma.

A template for creating services in Rust using Axum and Prisma. This uses the super cool Prisma Rust Client.

Aaron Leopold 6 Oct 19, 2022
✨ A perfect template for a binary rust project.

Rust Template A project template for Rust, helping to structure your projects blazingly fast ⚡ . Features ?? Code-ready for binary projects. Add amazi

bwtecode 3 Aug 21, 2022
Type-safe, compiled Jinja-like templates for Rust

Askama Askama implements a template rendering engine based on Jinja. It generates Rust code from your templates at compile time based on a user-define

Dirkjan Ochtman 2k Jan 5, 2023
Compiled string templates for Rust

templariusz Compiled string templates for Rust Usage See tests for detailed usage examples Basic example use templariusz::{template, Template}; #[tem

Michał Wawrzynowicz 2 Jan 29, 2022
serve a static site, single page application or just a static file with Rust

cargo-server tl;dr: Does the same as "python -m http.server" or "npx serve" but for Rust ecosystem. cargo-server helps you serve a static site, single

Raphael Amorim 18 Oct 14, 2022