Merge pull request #22 from nutzam/add_jetx_starter

add: start-jetx for jetbrick-template
This commit is contained in:
Wendal Chen 2017-11-23 21:43:19 +08:00 committed by GitHub
commit d55244108c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 191 additions and 7 deletions

View File

@ -77,7 +77,7 @@ public class MainLauncher {
- [x] [Quartz](http://www.quartz-scheduler.org)
- [ ] 模板引擎
- [x] [Beetl](http://ibeetl.com/)
- [ ] [jetbrick-template](https://github.com/subchen/jetbrick-template-2x)
- [x] [jetbrick-template](https://github.com/subchen/jetbrick-template-2x)
- [ ] Vecloity
- [ ] FreeMarker
- [ ] Thymeleaf

View File

@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-demo-simple</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-demo-simple-jetx</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jetty</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-jetx</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/nutz/org.nutz.boot.starter.NbStarter</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.nutz.demo.simple.MainLauncher</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,17 +1,20 @@
package io.nutz.demo.zbus.rpc;
package io.nutz.demo.simple;
import org.nutz.boot.NbApp;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
@IocBean
public class MainLauncher {
@Ok("raw")
@At("/time/now")
public long now() {
return System.currentTimeMillis();
@At({"/", "/index"})
@Ok("jetx:/index.jetx")
public NutMap index() {
NutMap obj = new NutMap();
obj.setv("name", "NB").setv("age", 18);
return obj;
}
public static void main(String[] args) throws Exception {

View File

@ -0,0 +1,7 @@
jetty.port=8080
jetty.host=127.0.0.1
jdbc.type=druid
jdbc.url=jdbc:h2:mem:~
jdbc.driverClassName=org.h2.Driver

View File

@ -0,0 +1,7 @@
log4j.rootLogger=debug,Console
log4j.logger.org.eclipse.jetty=info
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>NB demo for Beetl</title>
</head>
<body>
<div>
<h2>Context Path = '${base}'</h2>
</div>
<div>
<h2>From Action name=${obj.name}, age=${obj.age}</h2>
</div>
</body>
</html>

View File

@ -12,6 +12,7 @@
<module>nutzboot-demo-simple-dao</module>
<module>nutzboot-demo-simple-redis</module>
<module>nutzboot-demo-simple-beetl</module>
<module>nutzboot-demo-simple-jetx</module>
</modules>
<properties>
</properties>

View File

@ -0,0 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-parent</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-starter-jetx</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.subchen</groupId>
<artifactId>jetbrick-template</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>com.github.subchen</groupId>
<artifactId>jetbrick-template-nutz</artifactId>
<version>2.1.5</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,51 @@
package org.nutz.boot.starter.jetx;
import java.util.Properties;
import org.nutz.boot.AppContext;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.ViewMaker;
import jetbrick.template.JetEngine;
import jetbrick.template.web.JetWebEngine;
import jetbrick.template.web.nutz.JetTemplateView;
@IocBean(name="$views_jetx")
public class JetxViewMakerStarter implements ViewMaker {
@Inject
protected PropertiesProxy conf;
@Inject
protected AppContext appContext;
protected String suffix;
protected JetEngine engine;
public View make(Ioc ioc, String type, final String value) {
if (engine == null) {
Properties prop = new Properties();
for (String key : conf.keySet()) {
if (key.startsWith("jetx.")) {
prop.put(key.substring("jetx.".length()), conf.get(key));
}
}
prop.setProperty("jetx.template.loaders", "$classpathLoader");
prop.setProperty("$classpathLoader", "jetbrick.template.loader.ClasspathResourceLoader");
prop.setProperty("$classpathLoader.root", "/template/");
prop.setProperty("$classpathLoader.reloadable", "true");
engine = JetWebEngine.create(Mvcs.getServletContext(), prop, null);
suffix = engine.getConfig().getTemplateSuffix().substring(1);
}
if (suffix.equals(type)) {
return new JetTemplateView(value);
}
return null;
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.jetx.JetxViewMakerStarter

View File

@ -5,6 +5,7 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import org.nutz.boot.aware.AppContextAware;
@ -209,6 +210,7 @@ public class NbApp {
public void prepareStarterClassList() throws Exception {
starterClasses = new ArrayList<>();
HashSet<String> classNames = new HashSet<>();
Enumeration<URL> _en = ctx.getClassLoader().getResources("META-INF/nutz/org.nutz.boot.starter.NbStarter");
while (_en.hasMoreElements()) {
URL url = _en.nextElement();
@ -218,7 +220,10 @@ public class NbApp {
String tmp = Streams.readAndClose(reader);
if (!Strings.isBlank(tmp)) {
for (String _tmp : Strings.splitIgnoreBlank(tmp, "[\n]")) {
Class<?> klass = ctx.getClassLoader().loadClass(_tmp.trim());
String className = _tmp.trim();
if (!classNames.add(className))
continue;
Class<?> klass = ctx.getClassLoader().loadClass(className);
if (!klass.getPackage().getName().startsWith(NbApp.class.getPackage().getName()) && klass.getAnnotation(IocBean.class) != null) {
starterIocLoader.addClass(klass);
}

View File

@ -61,6 +61,7 @@
<module>nutzboot-starter-redis</module>
<module>nutzboot-starter-disque</module>
<module>nutzboot-starter-beetl</module>
<module>nutzboot-starter-jetx</module>
</modules>
<profiles>
<profile>