Coder Social home page Coder Social logo

lejs's Introduction

Lionel Lionel Embedded JavaScript Templates (LeJS)

LeJS Actions Build Status

This repository is dedicated to serving as a platform for practice and training purposes. It should not be used in production environment.

Features

  • Unescaped output with {{ }}
  • IF statement with {# }} {/# ]]
  • Maping objects with {> }} {/> }}

Usage

Node

let template = lejs.compile(str, options);
template(data);
// => Rendered String

lejs.render(str, data, options);
// => Rendered String

lejs.renderFile(filename, data, options);

CLI

.lejs

<p>Hello {{world}}</p>
<ul>
{>li}}
    <li>Index: {{+index}}. {{+value}}</li>
{/>li}}
</ul>
{#details}}
<details>
    {{detail}}
</details>
{/#details}}

JSON data

{
  "world": "World",
  "li": [
    {
      "value": "Line 1"
    },
    {
      "value": "Line 2"
    }
  ],
  "details": true,
  "detail": "This value is visible, because details is true"
}

Output

<p>Hello World</p>
<ul>

    <li>Index: 0. Line 1</li>

    <li>Index: 1. Line 2</li>

</ul>

<details>
    This value is visible, because details is true
</details>

CLI call

node ./dist/bin/cli.js ./test/files/example.lejs -f ./test/files/example.json
# OR
lejs ./test/files/example.lejs -f ./test/files/example.json

Tags

  • {{ }} Value output tag
  • {# }} IF statement start tag
  • {/# }} IF statement end tag
  • {> }} MAP start tag
  • {{+ }} MAP variable tag
  • {/> }} MAP end tag

lejs's People

Contributors

reterics avatar

Watchers

 avatar

lejs's Issues

IF parser is not working recursively

Recursive IF statement is not working as expected.

Steps:
test.txt:

{>asd}}
something2
{>asd2}}
something
{/>asd2}}
something3
{/>asd}}

and the CLI: node ./dist/bin/cli.js ./test.txt -i "asd=2&asd2=1"

Output:

something3
{/>asd}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.