Skip to content

ogghostjelly/shtml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SHTML

HTML at Compile-time

Note

This project is still in active (albeit slow) development so expect breaking changes. The documentation isn't great either but it's something I'll be working on. In the meantime feel free to contribute!

A lisp-like HTML templating language built off of mal. This is not suited for major production settings. If you found a bug or have a suggestion create an issue or to submit code create a pull request. I made this because I was dissatisfied with the state of SSG templating languages.

Clone and run it:

git clone https://github.com/OgGhostJelly/shtml.git
cd shtml
cargo run -- help         # Display help text
#cargo run -- build site/ # Build the example site
#cargo run -- repl        # Start the repl

Examples

Numbers, comments and ignoring

<main>
    @; this is a comment
    @(+ 1 2)
    
    @; '#' ignores the value
    @(# + 5 6)
</main>

--- vvv ---

<main>
    3


</main>

Using more complex functions

<main>
    @(do
        (def! r (range 0 10))
        (str (join r " + ") " = " (accum + r)))
</main>

--- vvv ---

<main>
    0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
</main>

Including files

[index.html]
<main>
    @(include "#template.html" [greeting "Hello"])
</main>

[#template.html]
<p>@greeting from @file</p>

--- vvv ---

<main>
    <p>Hello from #template.html</p>
</main>

Custom tags

<main>
    @(defn! x@say
        [p text]
        <p>"@text" said @(p 'name)</p>)

    <x@say name="Bob">What's up</x@say>
</main>

--- vvv ---

<main>
    <p>"What's up" said Bob</p>
</main>

Compiling to JS

Important

This is not yet implemented, there are older versions of shtml that do implement this but they are very buggy and janky!

<main>
    @(def! greeting "Hello, World!")
    @(script (alert ~greeting))
</main>

--- vvv ---

<main>
    <script> alert("Hello, World") </script>
</main>

About

HTML at compile time

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages