Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wagon-engine

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wagon-engine

A very cool node HTML templating engine.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Wagon Engine

Wagon is a very fast and cool templating engine for fast development.

Here is quick example on the syntax.

<div id="myDiv">
    {#if (usingWagon === true)}
        {niceMessage()}
    {:else}
        Use it because it is cool.
    {/if}
</div>

As you can see, it is literally javascript in html.

Now lets try to compile this template.

let renderer = Template.fromFile("fullPathToTemplate.html").compile();
console.log(
  renderer({
    usingWagon: true,
    niceMessage: () => "Yay, you are using Wagon!",
  })
);

Ouputs

<div id="myDiv">Yay, you are using Wagon!</div>

Time to spice things up!

with for loops...

{#for (let i = 0; i < 10; i ++>)}
    {i}
{/for}

Outputs...

0 1 2 3 4 5 6 7 8 9

with while loops...

{#while (true)}
    Oops no good
{/while}

Outputs...

Nothing just like any javascript never ending loop.

with literally javascript code...

{%
    class Human {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
        greet() {
            return `Hello, my name is ${this.name} and I am ${this.age}.`
        }
    }
}
{new Human("Bob", 20).greet()}

Outputs...

Hello, my name is Bob and I am 20

Very simple syntax...

syntaxdescriptionexample
{code}Evaluated and displayed{"You will see me"}
{% code}Evaluated, but not displayed{% let m = "You will not"}
{# block statement}Open a block statement{# if (true)}
{: block statement}Chains a block statement{: else if (true)}
{/...}Closes a block statement{/ if}
{@ code}Evaluated during compile time{@ this.include("./partial.html")}

Render time variables

namedescription
$mainRoot template name (full path)
$htmlIn generation HTML
$codeGenerated code
dataProps passed from the renderer

$html can be modified by the template.

So...

{% $html += "Hello world"}

will be the same as...

{"Hello world"}

or even simpler...

Hello world

Compile time variables and methods

namedescription
this.mainRoot template name (full path)
this.nameCurrent template name (full path)
this.rawRaw template
this.codeIn genration code
this.varsRender time variable names. eg. $html
this.define(string name, any value)Define a constant
this.include(string relativePath)Inserts compiled code from another template
this.add(string code)Inserts code during compile time

Syntax highlighting

There is syntax highlighter in the VScode Marketplace. https://marketplace.visualstudio.com/items?itemName=str1z.html-wagon-syntax-highlighting

Keywords

FAQs

Package last updated on 23 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc