Skip to content
/ ltml Public

A simple and concise templating engine that takes advantage of elegant Lua syntax.

License

Notifications You must be signed in to change notification settings

tmpim/ltml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LTML

Documentation Travis build status MIT License Discord

A simple and concise templating engine that takes advantage of elegant Lua syntax.

Explanation

LTML utilizes Lua's tables and optional parentheses around table and string literals to allow for a simple template syntax that can be easily rendered as HTML. LTML is portable enough to run in any typical Lua environment, given you can use setfenv (<5.1) or load (5.2+). It is even possible to run LTML in the browser.

Example

def "cool_message" ( data.message:reverse() ),
def "groceries" { "Milk", "Eggs", "Bread" },
def "item" ( function(name) return li { name } end ),

doctype "html",
comment "This page was rendered with <3 by LTML",
html {
    head {
        title "LTML Example"
    },
    body {
        h1 "LTML Example",
        p { data.message },
        p { cool_message },
        br,
        a { href = "https://justyn.is", "Check out my blog!" },
        a { href = "https://github.com/tmpim/ltml" } "LTML is awesome!",
        img { src = data.img },
        h2 "Grocery list:",
        ul {
            map (groceries, item)
        }
    }
}

This renders to (prettified for readability):

<!DOCTYPE html>
<!-- This page was rendered with <3 by LTML -->
<html>
    <head>
        <title>LTML Example</title>
    </head>
    <body>
        <h1>LTML Example</h1>
        <p>This page was created using only Lua (no HTML, JS) with LTML!</p>
        <p>!LMTL htiw )SSC ,SJ ,LMTH on( auL ylno gnisu detaerc saw egap sihT</p>
        <br />
        <a href="https://justyn.is">Check out my blog!</a>
        <a href="https://github.com/tmpim/ltml">LTML is awesome!</a>
        <img src="http://www.lua.org/manual/5.3/logo.gif" />
        <h2>Grocery list:</h2>
        <ul>
            <li>Milk</li>
            <li>Eggs</li>
            <li>Bread</li>
        </ul>
    </body>
</html>

A more explanatory version of this template (and LTML as a whole) can be found in ltml/example/example.ltml.lua

Example code for executing and rendering templates can be found in ltml/example/example.lua

Disclaimer

LTML is a very immature library, things are subject to change, and it is very much in testing, so utilize it with caution.

Contributing

Standard Lua style conventions should be followed when pushing to this repository.

About

A simple and concise templating engine that takes advantage of elegant Lua syntax.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published