5 releases

0.1.8 Jan 8, 2025
0.1.7 Jan 7, 2025

#3 in #crab

Download history 493/week @ 2024-12-28 312/week @ 2025-01-04 36/week @ 2025-01-11 17/week @ 2025-02-01

68 downloads per month

MIT license

19KB
333 lines

🦀 Crab Markup Language

CRML is a simple markup language which compiles all given files into a Rust module which fits right into your crate source.

The generated crml/mod.rs file exports functions which build the contents of your given templates as HTML.

Configuration

Your project must contain a crml.json file in order to tell the CLI how to build your templates. The repository contains an example crml.json file which links to examples/simple to build templates.

You can run this example for yourself with the following commands:

just test

The only key you need to provide in this file is the directory where your templates are stored.

{
    "root_dir": "./templates"
}

Usage

A very simple usage example is shown in the example.

Base template

You can add "slots" to templates and allow them to act as a base for other templates.

Imagine a template like this:

@<!DOCTYPE html>
%html
    %head
        %title'Document Title
    %-head

    %body
        %slot[name="body_content"]
    %-body
%-html

This template creates an HTML element in its body which looks like this:

<slot name="body_content"/>

We can then say that we're going to render into this specific slot from this specific file by referencing its "address" in other files.

%s:first.body_content
// everything here (for the rest of the file) will be put into the
// "body_content" slot element of the "first" template

Debug

You can create a crml_dbg directory in your project root to debug the Rust generated by the template macro. This directory will have the macro output written to it every time the macro is run.

Attribution

CRML is licensed under the MIT license. You can view the license here.

Dependencies

~0.7–1.5MB
~33K SLoC