B4J Library [Web] MiniHtml

Yet the potential or use cases of this library may be unknown as you can literally write plain HTML and save it as a file.

GitHub: https://github.com/pyhoon/MiniHtml-B4X

Sample:
B4X:
Sub AppStart (Args() As String)
    GenerateHtml
    StartMessageLoop
End Sub

Sub GenerateHtml
    Dim html As MiniHtml
    html.Initialize
    'html.Flat = True
    html.Text("#macro( header )")
    html.DocType
    html.Language("en")
    html.Comment(" velocity.vm ")
    html.Head
    html.Meta(html.Attrs(Array("http-equiv", "content"), Array("content-type", "text/html; charset=utf-8")))
    html.Meta(html.Attrs(Array("name", "content"), Array("viewport", "width=device-width, initial-scale=1")))
    html.Text("$csrf")
    html.Meta(html.Attrs(Array("name", "content"), Array("description", "")))
    html.Meta(html.Attrs(Array("name", "content"), Array("author", "")))
    html.Title("$APP_TITLE")
    html.Headx
    html.Body
    html.H1("Hello, World!")
    html.Img("/img/hello.png")
    html.Bodyx
    html.Htmlx
    Dim content As String = html.ToString
    Log(content)
    File.WriteString(File.DirApp, "velocity.vm", content)
End Sub

Output:
HTML:
#macro( header )
<!DOCTYPE html>
<html lang="en">
<!-- velocity.vm -->
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    $csrf
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>$APP_TITLE</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <img src="/img/hello.png" />
</body>
</html>
 

Attachments

  • MiniHtml.b4xlib
    1.7 KB · Views: 144
  • MiniHtmlExample.zip
    985 bytes · Views: 164
Last edited:

EnriqueGonzalez

Expert
Licensed User
Longtime User
i once made something very similar but it was easier as you didn't have to think in the end tags.
 

aeric

Expert
Licensed User
Longtime User
i once made something very similar but it was easier as you didn't have to think in the end tags.
I wish I didn't need to reinvent the wheel.
Thanks for sharing.
Maybe I can borrow part of your "wheel".
 
Top