hvist

2.3.0 • Public • Published

Sample

import hvist from 'hvist'

// compile template from file
const filename = '/path/to/file.at';
const fileTempalate = await hvist.compileFile(filename);

// compile template from source
const source = '?title; html { head title $title; body "Some content" }';
const template = await hvist.compile(source);

// any render arguments
const args = {title: 'Some title'};

// render template to text
const text = await template.text(args);

console.log(text);

// render template to buffer
const buffer = await template.buffer(args);

// render template to file
await template.save('/path/to/result.html', args);

// render template to output stream
await template.print(args);

// render template to any stream
const stream = {
	write(chunk){ console.log(chunk) }
};

await template.pipe(stream, args);

Template language sample

main.at

// optional argument title
?title = 'Default Title'

@doctype(html)

html(lang='en') {

	head {
		title $title.toUpperCase();
	}

	// @ - insert include contents here
	body main @
}

page.at

// replace Article tag
@module Article {
	?image; // require argument
	section.article {
		img(src=$image); // print img tag
		@; // insert content
	}
}

// replace Title tag
@module Title { h2.article @ }

// replace Content tag
@module Content { p.content @ }

// import main file and insert @-content
@import 'main.at'(title='Page Title') {

	Article(image='./image.png') {
		Title 'Article Title';
		Content 'Article Content';
	}
}

Output HTML (without white spaces)

<!DOCTYPE html>
<html lang="en">

  <head>
    <title>PAGE TITLE</title>
  </head>

  <body>
    <main>
      <section class="article">
      	<img src="./image.png" />
        <h2 class="article">Article Title</h2>
        <p class="article">Article Content</p>
      </section>
    </main>
  </body>

</html>

Readme

Keywords

Package Sidebar

Install

npm i hvist

Weekly Downloads

2

Version

2.3.0

License

ISC

Unpacked Size

150 kB

Total Files

73

Last publish

Collaborators

  • gabriel.zoroaster