Skip to content

juancarlospaco/nim-html-dsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nim-HTML-DSL

HTML DSL

Use

import html_dsl

const page = html:
  heads:
    title "Title"
    meta(name="foo", content="bar")
  bodys:
    p "Powered by Nim Metaprogramming"
    `<!--` "HTML Comment"
    a(text="Nim", href="https://nim-lang.org")
    divs:
      p "Example"

assert page is string
echo page
Click to see Output

Build for Development:

<!DOCTYPE html>
<html class='has-navbar-fixed-top'>
  <head>
    <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="foo" content="bar" >
    <title>Title</title>
  </head>
  <body class='has-navbar-fixed-top'>
    <p > Powered by Nim Metaprogramming</p>

    <!--  HTML Comment  -->

    <a href="https://nim-lang.org" > Nim</a>
    <div >
      <p > Example</p>
      <p > Example</p>
    </div>
  </body>
</html>

Build for Release:

<!DOCTYPE html><html class='has-navbar-fixed-top'><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="foo" content="bar" ><title>Title</title></head><body class='has-navbar-fixed-top'><p>Powered by Nim Metaprogramming</p><a href="https://nim-lang.org" >Nim</a><div><p>Example</p><p>Example</p></div></body></html>

Design

  • 1 file, ~300 Lines of Code, as fast as const, 42 Kilobytes Hello World file size.
  • Works for JavaScript and NodeJS and NimScript.
  • Bulma CSS ready, Spectre CSS ready.
  • Minified when build for Release, Pretty-Printed when build for Development.
  • Functional Programming, no side-effects, all functions are func.
  • <div> is named divs, <body> is named bodys, <head> is named heads, to avoid eventual name shadowing with other libs.
  • HTML5, UTF-8, Responsive, all Tags supported, all Attributes supported.

FAQ

  • Whats the Performance cost of using this?.
  1. Zero. None. Everything is done at Compile-Time.
  • Can be used with Jester?.

Yes.