Coder Social home page Coder Social logo

javascript-template's Introduction

javascript-template

javascript template jstl

Ayada是一个javascript版的模板引擎,采用与jsp完全兼容的jstl语法。因此它与jsp的jstl一模一样,如果你写过jsp,那么使用它就不是问题。 目前的版本采用解释模式,并且不支持javascript脚本,你只能使用jstl来编写模板。 支持javascript的脚本的版本正在开发中,将会很快推出。java版的已经支持java脚本,参见https://github.com/xuesong123/java-template 另外新版的将会同时支持在nodejs下以jsp的方式运行。这意味着你既可以在客户端浏览器中使用它作为模板引擎,也可以在nodejs下作为服务端jsp运行。

node_modules\webserver是一个nodejs版的jsp/servlet容器。它与java的jsp/servlet类似,你可以使用它以jsp/servlet的方式开发web应用程序。 它与常见的jsp/servlet容器如tomcat、resin的jsp/servlet容器类似,你可以使用filter, servlet, jsp等。它也包含session支持。总之它包含了jsp/servlet容器所有的功能。 bootstract.js是它的一个demo。你可以运行它看到效果。它会自动扫描指定目录下的所有目录,并根据目录中WEB-INF/web.js中的配置自动创建web应用。并具有文件监控功能, 当WEB-INF下指定目录下的.js文件改变时,应用会自动重新加载。当然你也可以指定不使用监控功能,这比较适用于生产环境。 demo中还包含了一个应用程序管理控制台,你可以在这个应用中管理所有的应用,包括启动,停止和重新启动。 目前对于jsp仅支持javascript脚本,而不支持jstl,因为我们之前希望在容器中只使用jstl,应用可以自己决定使用不同的模板引擎,但是现在我们决定让它完整的支持jsp的全部功能。 这个功能我们会很快推出。

Ayada is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.

@see https://github.com/xuesong123/java-template

Tag Example

c:if

<c:if test="${1 == 1}">1 == 1</c:if>

out: 1 == 1

c:forEach & c:each

<c:forEach items="${1, 2, 3}" var="myvar" varStatus="status">
    ${status.index}: ${myvar}
</c:forEach>

out: 0: 1 1: 2 2: 3

c:forEach & c:each

<c:forEach begin="1" end="3" step="1" var="myvar" varStatus="status">
    ${status.index}: ${myvar}
</c:forEach>

out: 0: 1 1: 2 2: 3

c:forEach & c:each var varList = [1, 2, 3];

<c:forEach items="${varList}" var="myvar" varStatus="status">
    ${status.index}: ${myvar}
</c:forEach>

out: 0: 1 1: 2 2: 3

c:set

<c:set var="myvar1" value="${myvar}"/>
<c:set var="myvar1" value="1,2,3"/>

c:out

<c:out value="${myvar}" defaultValue="1,2,3" escapeXml="true"/>

out: 1,2,3

c:choose & c:when & c:otherwise

<c:choose>
    <c:when test="${userList.length > 6}"><div>test1</div></c:when>
    <c:when test="${userList.length > 7}"><div>test2</div></c:when>
    <c:otherwise><div>test3</div></c:otherwise>
</c:choose>

c:comment

<c:comment>
    ...
</c:comment>

fmt:formatDate

<fmt:formatDate var="mydate1" value="${mydate}" pattern="yyyy-MM-dd"/>

t:import

<t:import name="app:cache" className="com.mytest.taglib.CacheTag"/>

import a tag, scope: current page

t:include

<t:include file="/include/mytest.jsp"/>

include a page

API Example

// scope: global
com.skin.ayada.jstl.TagLibraryFactory.setup("app:scrollpage", com.mytest.taglib.ScrollPageTag);

 * @param home - work directory
 * @param expire
var templateContext = new com.skin.ayada.template.TemplateContext("/", 300);

var writer = var writer = new com.skin.io.StringWriter();
var context = {userList: [{userName: "test", userAge: 20}]};
templateContext.execute("source1", context, writer);
alert(writer.toString());

javascript-template's People

Contributors

abeet avatar xuesong123 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.