2.3.0 • Published 2 years ago

hvist v2.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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>
2.3.0

2 years ago

2.2.3

3 years ago

2.2.4

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago