Template Engine with CSS-JS-like syntaxis.
import xtpl from 'xtpl';
import stringMode from 'xtpl-mode-string';
// Create template factory
const templateFactory = xtpl.fromString('h1.title | Hi, ${props.name}!', {
mode: stringMode({prettify: true}),
scope: ['props'],
});
// Get template
const template = templateFactory();
// Usage
cont html = template({
props: {
name: 'xtpl'
},
});.foo.bar-><div class="foo bar"/>h1.caption-><h1 class="caption"/>.welcome | Hi!-><h2 class="welcome">Hi!</h2>form[method="post"]-><form method="post"/>
input[type="text"][value="..."]— css-like enumerableinput[type="text" value="..."]— space separated
- className:
.is-${state}.${someClassName} - tag + className:
${tagName}.is-${state} - attributes:
form[method="${type}" action="api/${method}"] - text:
h1 | Hi, ${username}!
// Bla-bla-bla
.text | ok.text |>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean mattis at sapien elementum tempor.
Aliquam consequat egestas nisl quis pharetra.<|.main |# Click <a href="#next">me</a>. #|.panel
.&-title > h1 | ${title}
p.&-text | ${text}⏬ ⏬ ⏬
<div class="panel">
<div class="panel-title"><h1>...</h1></div>
<p class="panel-text">...</p>
</div>i.left + i.right⏬ ⏬ ⏬
<i class="left"></i>
<i class="right"></i>.panel
.&-title > .&-close + | Wow!
.&-content | Bla-bla-bal⏬ ⏬ ⏬
<div class="panel">
<div class="panel-title">
<div class="panel-title-close"><div>
Wow!
</div>
<p class="panel-content">Bla-bla-bal</p>
</div>.button
class.&_${attrs.type}: true
| ${attrs.text}⏬ ⏬ ⏬
<div class="button button_primary">
OK
</div>// Define
btn = [text, type]
button.button
class.&_${attrs.type}: true
| ${text}
// Usage
btn[text="Continue"]
btn[text="Send" type="primary"]⏬ ⏬ ⏬
<button class="button">Continue</div>
<button class="button button_primary">Send</div>// Define
box = []
.box > __default() // Call default
// Usage
box
h2 | News
p | ...⏬ ⏬ ⏬
<div class="box">
h2 | News
p | ...
</div>// Define
panel = []
.&__head > head() // Call slot
.&__body > body()
// Checking the existence of slot
if (typeof footer === 'undefined')
.&__footer > footer()
else
.&__footer-empty
// Usage
panel
// Define slot
head = ()
h2 | Wow!
body = ()
p | Bla-bla-bla...⏬ ⏬ ⏬
<div class="panel">
<div class="panel__head"><h2>Wow!</h2></div>
<div class="panel__body"><p>Bla-bla-bla...</p></div>
<div class="panel__footer-empty"><p>Bla-bla-bla...</p></div>
</div>// Define
box = []
content = ()
h1 | default
.body > content()
// Define
hello = [name]
content = (text)
| Hi, ${text}!
.body > content(name.charAt(0).toUpperCase() + name.substr(1))
// Usage
hello[name="rubaxa"]// Define
hello = [name]
content = (text)
| Hi, ${text}!
.body > content(name.charAt(0).toUpperCase() + name.substr(1))
// Usage
hello[name="rubaxa"]
// Override slot and added `h1` wrapper
content = (text)
h1 > super.content(text)
// Or can define a combined block.
BigHello = [name]
hello[name="${name}"]
// Override slot and added `h1` wrapper
content = (text)
h1 > super.content(text)
// and usage
BigHello[name="rubaxa"]a[<]— beforea[>]— aftera[<>]— at both sides
p > img[<] + img[<>] + img[>]⏬ ⏬ ⏬
<p> <img/> <img/> <img/> </p>