0.2.4 • Published 7 months ago

nsp-jstl-taglib v0.2.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

nsp-jstl-taglib

Node.js CI npm version

NSP taglib for JSTL Jakarta Standard Tag Library

  • JSTL core library - e.g. <c:if test="${test}"></c:if>
  • JSTL formatting library - e.g. <fmt:formatDate value="${date}" pattern="yyyy-MM-dd"/>
  • JSTL functions library - e.g. ${ fn:toUpperCase("abc") }
  • See TypeScript declaration files for API detail.

SYNOPSIS

import {createNSP} from "nsp-server-pages";
import {cTags, fmtTags, fnFunctions} from "nsp-jstl-taglib";

const nsp = createNSP();

nsp.addTagLib({ns: "c", tag: cTags});
nsp.addTagLib({ns: "fmt", tag: fmtTags});
nsp.addTagLib({ns: "fn", fn: fnFunctions});

const context = {title: "nsp", upper: true};

const render = await nsp.loadJSP("path/to/template.jsp");

const html = await render(context);

console.log(html);
// => <h1>NSP</h1>
<c:if test="${upper}">
  <h1>
    <c:out value="${fn:toUpperCase(title)}" default="Untitled"/>
  </h1>
</c:if>

COMMONJS

  • Both ES Modules and CommonJS supported.
const {createNSP} = require("nsp-server-pages");
const {cTags, fmtTags, fnFunctions} = require("nsp-jstl-taglib");

COMPATIBILITY

JSTL core library

tagstatusnote
<c:choose>👍 OK
<c:if>👍 OK
<c:import>👍 OK
<c:forEach>👍 OK
<c:forTokens>👍 OK
<c:out>👍 OK
<c:otherwise>👍 OK
<c:param>👍 OK
<c:redirect>🚫 N/Anot available by design
<c:remove>👍 OK
<c:set>👍 OK
<c:url>👍 OK
<c:when>👍 OK

scope="xxx" attribute is just ignored as nsp supports only request scope.

JSTL formatting library

tagstatusnote
<fmt:requestEncoding>👍 OK
<fmt:setLocale>👍 OK
<fmt:timeZone>👍 OK
<fmt:setTimeZone>👍 OK
<fmt:bundle>👍 OKimplement ResourceBundle.getBundle hook
<fmt:setBundle>👍 OKimplement ResourceBundle.getBundle hook
<fmt:message>👍 OK
<fmt:param>👍 OK
<fmt:formatNumber>👍 OKworks mostly. some feature still missing
<fmt:parseNumber>👍 OK
<fmt:formatDate>👍 OKworks mostly. some feature still missing
<fmt:parseDate>🕑 Not yet

Implement ResourceBundle.getBundle hook which returns an array of key-value pair properties. The hook is called by <fmt:bundle> and <fmt:setBundle> tags.

const nsp = createNSP();

nsp.hook("ResourceBundle.getBundle", async (basename) => {
    const properties = {"key": "value"};
    return [properties];
});

JSTL functions library

functionstatusequivalant method
${ fn:contains() }👍 OKString#includes
${ fn:containsIgnoreCase() }👍 OK
${ fn:endsWith() }👍 OKString#endsWith
${ fn:escapeXml() }👍 OK
${ fn:indexOf() }👍 OKString#indexOf
${ fn:join() }👍 OKArray#join
${ fn:length() }👍 OK
${ fn:replace() }👍 OKString#replace
${ fn:split() }👍 OKString#split
${ fn:startsWith() }👍 OKString#startsWith
${ fn:substring() }👍 OKString#substring
${ fn:substringAfter() }👍 OK
${ fn:substringBefore() }👍 OK
${ fn:toLowerCase() }👍 OKString#toLowerCase
${ fn:toUpperCase() }👍 OKString#toUpperCase
${ fn:trim() }👍 OKString#trim

LINKS

LICENSE

// SPDX-License-Identifier: Apache-2.0
0.2.4

7 months ago

0.2.3

8 months ago

0.2.0

8 months ago