Skip to content

0.3.2 - Look! A Library!

Latest
Compare
Choose a tag to compare
@BritishWerewolf BritishWerewolf released this 09 Apr 14:04
· 21 commits to main since this release

This release adds a lib.rs file to the package.
What this means, is that we can compile the binary and use the package in other projects without needing to maintain two codebases.

New Filters

Additional filters have been added: reverse and truncate.
reverse will simply reverse the value, truncate is slightly more complicated.

This is the syntax for any placeholder within the templates.

{{ £variable_name[ | filter_name[ = [key: ]value]...] }}

All filters are completely optional, and can be chained by placing a | after each call.
Some filters don't have any arguments, and any that do always have default values, as well as one of the arguments being deemed as the default argument.

As of this release, there is just a single filter that accepts arguments: truncate.
truncate has the following signature.

truncate = characters: 20, trail ...

Here the defaults are provided. It's important to note that characters is the default argument.

**What's a default argument?

This is just a convenience to keep templates from becoming verbose.

Giving a filter a default argument (as well as default values!), means that we can just simply provide the filter name, and get sensible defaults.
Let's look at an example.

<p>{{ £content | truncate }}</p>

This is nice and simple, we are just using the default values here, but what about if we wanted to change the point at which we truncate?!

Well, now we have two options.

<p>{{ £content | truncate = 42 }}</p>
<p>{{ £content | truncate = characters: 42 }}</p>

By assuming that a value without a key, is a particular key, then we can keep our templates more concise.
If you wish to change any value that is not the default, then you will always need to provide that key. That means that this is invalid.

<p>{{ £content | truncate = -- }}</p>

This will attempt to assign -- to the characters key, which will break as that expects an unsigned integer.

Justfile

There is now a justfile which will start adding more recipes.
This should just help building the project and testing.

Housekeeping

Now that we have a lib.rs and main.rs file; the functionality has been split across these files.
Tests have been moved to a tests/tests.rs file too.

This also has the benefit of giving us a docs.rs page too!

Full Changelog: 0.2.1...0.3.2