Giter Club home page Giter Club logo

tingo's Introduction

Tingo

Tingo is a Go libary for generating HTML from Go code. I found template/html too simple (no way to extend templates, create blocks etc). If you've ever used Jinja2 or the Django template language, you should know what I'm talking about.

Creating a full template language is a lot of work, so I decided to try a different approach: Doing it directly from Go.

Tingo is far from done, but it can generate some simple HTML.

Example

The example below is taken from one of the tests. It renders in 0.09ms on my computer, with auto escaping turned on.

Html(
    Head(
        Title().TextAppend("Page title"),
        Style().TextAppend("body { font-family: Arial, sans-serif }"),
    ),
    Body(
        Header(
            H1(A().TextPrepend("Page title")),
            Nav(
                Ul(
                    Li(A().TextPrepend("Home")),
                    Li(A().TextPrepend("About")),
                    Li(A().TextPrepend("Services")),
                ),
            ),
        ),
        Section(
            H2().TextPrepend("Lorem ipsum"),
            P().TextPrepend("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent cursus odio sit amet metus blandit porttitor. Etiam convallis nibh eget erat cursus molestie auctor purus semper. Ut at suscipit mauris. Duis interdum nunc sodales neque consectetur fringilla. In hac habitasse platea dictumst. Integer nec ante purus. Morbi eu arcu sit amet felis fermentum adipiscing. Proin imperdiet lorem sed diam viverra at vestibulum libero imperdiet. Duis tortor orci, interdum eu eleifend blandit, dapibus non risus. Phasellus aliquam risus quis orci porta eleifend blandit diam mollis. Vivamus eu dolor mi, nec consequat diam. Pellentesque vel neque metus. Phasellus ac nisi orci, dapibus posuere diam. Nulla adipiscing, arcu in tempus facilisis, purus tellus bibendum massa, at consectetur odio lectus a lacus."),
        ).Id("main"),
        Footer(
            P().TextPrepend("Tingo test page.").Class("credits"),
        ),
    ),
).RenderIndent("\t")

License

Tingo is available under the MIT license.

tingo's People

Contributors

oal avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.