Code Monkey home page Code Monkey logo

denjucks's Introduction

DEPRECATED

Use https://github.com/valtlai/nunjucks-deno instead

Denjucks

Denjucks is a powerful templating language and engine for Deno applications, and provides an easy syntax for making scalable web applications using Deno.

Internally, Denjucks is a fork of Mozilla's Nunjucks for NodeJS, with the following changes:

  • Uses ESM syntax instead of CommonJS syntax
  • Uses Deno file system APIs instead of NodeJS file system APIs
  • Wraps all NodeJS dependencies into ESM compatible syntax

Installation

To install, simply import the raw module from the github repository in your Deno code:

// @deno-types="https://deno.land/x/denjucks/mod.d.ts"
import denjucks from "https://deno.land/x/denjucks/mod.js";

When running the file the first time, the source code for denjucks will be downloaded and cached on your machine.

Basic Usage

Rendering a template from a string:

// @deno-types="https://deno.land/x/denjucks/mod.d.ts"
import denjucks from "https://deno.land/x/denjucks/mod.js";

console.log(
    denjucks.renderString("hello {{ txt }}", {txt: "world"})
);

will print to the console:

hello world

Rendering a template from a file:

Remember to include the --allow-read flag when running the deno command or an error will be thrown, as the deno sandbox prevents reads by default

With the file _base.html as the parent template:

<html>
    <head></head>
    <body>
        {% block content %}{% endblock content %}
    </body>
</html>

And the file index.html as the template that will extend the parent:

{% extends "_base.html" %}

{% block content %}
    <p>Hello {{ txt }}</p>
{% endblock content %}

Calling render on index.html:

// @deno-types="https://deno.land/x/denjucks/mod.d.ts"
import denjucks from "https://deno.land/x/denjucks/mod.js";

console.log(
    denjucks.render("index.html", {txt: "World"})
);

Will print to the console:

<html>
    <head></head>
    <body>
        <p>Hello World</p>
    </body>
</html>

Documentation

Since Denjucks is a port of Nunjucks, it uses the exact same syntax as Nunjucks. See here for full documentation on Nunjucks.

References

Nunjucks is a full featured templating engine for javascript. It is heavily inspired by jinja2. View the docs here.

denjucks's People

Contributors

cj81499 avatar denjucks avatar ogonkov avatar oscarotero avatar

Watchers

 avatar  avatar

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.