Code Monkey home page Code Monkey logo

jsp-js's Introduction

JSP-JS Build Status

JSP-JS is a Java Server Pages rendering library for nodejs.

To render JSP to HTML, simply remove Java code. Currently supported tags are:

  • <%@include%>
  • <%@taglib tagdir="[path]">
  • <%=..%>
  • ${..}
  • <c:if>
  • <c:else>
  • <c:choose>
  • <c:when>
  • <c:otherwise>
  • <c:forEach>
  • <c:set>
  • <jsp:body>
  • <jsp:doBody>
  • <jsp:attribute>
  • <jsp:invoke>

Tests

Run:

npm run demo

Then open your browser to http://localhost:8080/page/test.jsp.

Usage

Import he renderer like so:

const JSPJs = require('jsp-js').Renderer;

const jsp = new JSPJs(options);
jsp.render('file', data);

The renderer also provides a promise wrapper for easy integration in promise-based code:

jsp.renderPromise('file', data).then((html) => console.log(html));

Constructor options

The following options can be provided to the constructor:

  • root: the root path where templates are
  • tags: a library of custom tags
  • globals: globally available data

Custom tags

Custom tags can be handled by providing them to the constructor options. These are anonymous functions that take the arguments:

  • node the tag node being evaluated
  • index the position of the node in the jsp template. Useful for debugging
  • data the current context data (as an object)
  • renderer the instanciated renderer

A custom tag handler must return a string.

Usage with Express

Please read the code of test/tests.js to have an idea of how to integrate this library with Express.

jsp-js's People

Contributors

chanjungkim avatar comum avatar guillaume-thisplace avatar luobotang avatar muhammaddadu avatar

Watchers

 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.