An open API service indexing awesome lists of open source software.

https://github.com/franbarinstance/neutral-cache-test

Rust template engine with cache and no cache - Neutral TS
https://github.com/franbarinstance/neutral-cache-test

cache-template rust-template rust-template-engine rust-web-template template template-cache web-template web-templates

Last synced: 3 months ago
JSON representation

Rust template engine with cache and no cache - Neutral TS

Awesome Lists containing this project

README

          

Rust template engine with cache and !cache
==========================================

Example of the Neutral TS cache in the terminal.

Download, navitate to neutral-cache-test directory and:

```plaintext
cargo run
```

Arbitrary key/value arguments can be set:

```plaintext
cargo run -- --argname argvalue
cargo run -- --argname "arg value"
```

There is an argument (`inject`) designed to try to inject code:

```plaintext
cargo run -- --inject "{:include; /path/to/secrets :}"
```

`inject` has the default value `{:exit; 403 :}`, what happens if the injection succeeds can be tested with:

```plaintext
cargo run -- --exit 403
```

The directory of the disk cache will be the temporary directory of the system, it can be changed in `main.rs` is indicated.

Cache
-----

The cache is modular, allowing only parts of the template to be included in the cache:

```plaintext


Cache

{:cache; /120/ >>

{:code; ... :}

:}

{:date; %H:%M:%S :}

{:cache; /120/ >>

{:code; ... :}

:}

```
Or exclude parts of the cache, the previous example would be much better like this:

```plaintext
{:cache; /120/ >>



Cache


{:!cache;
{:date; %H:%M:%S :}
:}


:}
```

Overview of cache syntax
------------------------

```plaintext
{:cache; /expires/addtoid/only_custom_id/ >> ... :}
{:cache; /expires/addtoid/ >> ... :}
{:cache; /expires/ >> ... :}
{:!cache; ... :}
```

* expires: Seconds of life in the cache
* addtoid: Add a literal to the cache ID
* only_custom_id: Use only the ID passed as ID

The only mandatory parameter is `expires`, the cache automatically generates an ID with context data, such as language, cookies, ... and code.

Example
-------

The example template is in the `neutral-cache-test/tpl` directory with the name `index.ntpl`, you can modify it as much as you want:

```plaintext


Test Neutral TS cache



Outside cache : {:;CONTEXT->GET->inject:} vs {:;inject:}
Outside filter: {:&;CONTEXT->GET->inject:} vs {:&;inject:}

{:cache; /10/{:;inject:}/ >>
{:^filled; CONTEXT->GET->exit >>
{:exit; {:;CONTEXT->GET->exit:} :}
:}
{:^;:}

Arguments:
{:each; CONTEXT->GET key val >>
{:^;:}
{:&;key:} = {:;val:}
{:^;:}
:}
----------------------------------------------------
Inject ....: {:;inject:} vs {:;CONTEXT->GET->inject:}
In cache ..: {:date; %H:%M:%S :} (10)
No cache ..: {:!cache; {:date; %H:%M:%S :} (!) :}
Nesting ...: {:cache; /20/ >>
{:date; %H:%M:%S :} (20) / {:!cache; {:date; %H:%M:%S :} (!) :}
:}
Crazy .....: {:!cache;
{:cache; /30/ >>
{:date; %H:%M:%S :} (30) / {:cache; /40/ >>
{:date; %H:%M:%S :} (40) / {:cache; /50/ >>
{:date; %H:%M:%S :} (50) ({:;inject:}) / {:!cache;
{:date; %H:%M:%S :} (!) {:;inject:}
:}
:}
:}
:}
:}

:}

```

Links
-----
- [Repository](https://gitlab.com/neutralfw/neutralts)
- [Crate](https://crates.io/crates/neutralts)
- [Docs](https://docs.rs/neutralts/latest/neutralts/doc/index.html)