Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 21 files changed
  • 0 commit comments
  • 1 contributor
View
11 .gitignore
@@ -0,0 +1,11 @@
+bin/
+*~
+*.launch
+gwt-unitCache*/
+classes/
+deploy/
+target/
+.*
+examples/src/main/webapp/gwtHoganExample/
+examples/src/main/webapp/WEB-INF/lib/
+
View
171 examples/pom.xml
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<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/maven-v4_0_0.xsd">
+
+ <!-- POM file generated with GWT webAppCreator -->
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan-examples</artifactId>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan-project</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <properties>
+ <!-- GWT needs at least java 1.5 -->
+ <webappDirectory>src/main/webapp</webappDirectory>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-servlet</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-user</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-dev</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <!-- Generate compiled stuff in the folder used for developing mode -->
+ <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
+
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ <include>**/*.gwt.xml</include>
+ <include>**/*.html</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <!-- GWT Maven Plugin -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>gwt-maven-plugin</artifactId>
+ <version>2.4.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ <!-- Plugin configuration. There are many available options, see gwt-maven-plugin
+ documentation at codehaus.org -->
+ <configuration>
+ <runTarget>gwtHogan.html</runTarget>
+ <hostedWebapp>${webappDirectory}</hostedWebapp>
+ <module>com.villagechief.gwt.hogan.examples.gwtHoganExamples</module>
+ </configuration>
+ </plugin>
+
+ <!-- Copy static web files before executing gwt:run -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1.1</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>exploded</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <webappDirectory>${webappDirectory}</webappDirectory>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.4.1</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${webappDirectory}/WEB-INF/classes</directory>
+ <includes>
+ <include>**/*.class</include>
+ <include>**/*.xml</include>
+ <include>**/*.js</include>
+ </includes>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ <fileset>
+ <directory>${webappDirectory}/WEB-INF/deploy</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
View
35 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/GwtHoganExample.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.examples.client;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.RootPanel;
+
+/**
+ * Entry point classes define <code>onModuleLoad()</code>.
+ */
+public class GwtHoganExample implements EntryPoint {
+ /**
+ * This is the entry point method.
+ */
+ public void onModuleLoad() {
+ Test test = GWT.create(Test.class);
+ RootPanel.get().add(test);
+ }
+}
View
45 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/Test.html
@@ -0,0 +1,45 @@
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<H2>GWT Hogan Examples</H2>
+
+Examples of loading data:<br/>
+Test 1, field 1: {{data.field1}}<br/>
+Test 2, field 1(without html formatting): {{data2.field1}}<br/>
+Test 1, field 2(using html formatting): {{{data2.field1}}}<br/>
+<br/>
+
+A JSONArray list:
+<ul>
+{{#list}}<li>{{.}}</li>{{/list}}
+</ul>
+<br/>
+
+
+<div id="placeholder1"></div>
+<input type="button" id="button1" value="Template Button" style="visibility:none:" />
+
+<br/>
+<br/>
+
+<i>
+And of course you can do everything else you can using Hogan (or more specifically, mustache, since that's the engine that Hogan uses).
+For more info see <a href="https://github.com/janl/mustache.js" target="_blank">https://github.com/janl/mustache.js</a>
+
+</i>
View
102 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/Test.java
@@ -0,0 +1,102 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.examples.client;
+
+import static com.google.gwt.query.client.GQuery.*;
+
+import java.util.Date;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONString;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.css.CSS;
+import com.google.gwt.query.client.css.RGBColor;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
+import com.villagechief.gwt.hogan.client.HoganWidget;
+
+public class Test extends HoganWidget {
+ Button b = new Button();
+
+ public Test() {
+ b.setText("GWT Button");
+
+ // can add java beans as long as it's been passed to the AutoBean
+ // Factory...
+ TestDataFactory beanFactory = GWT.create(TestDataFactory.class);
+ TestData test1 = beanFactory.data().as(); // just track the object, we
+ // can look it up again
+ // later...
+ test1.setField1("test");
+ test1.setNumber(1);
+ test1.setDateField(new Date());
+ addParameter("data", test1);
+
+ // can also use an an impelemented object
+ TestData test2 = new TestDataImpl();
+ test2.setField1("<b>test2</b>");
+ test2.setNumber(1);
+ test2.setDateField(new Date());
+ addParameter("data2", beanFactory.create(TestData.class, test2));
+
+ // or pass in json object directly
+ JSONArray arr = new JSONArray();
+ arr.set(0, new JSONString("item 1"));
+ arr.set(1, new JSONString("item 2"));
+ arr.set(2, new JSONString("item 3"));
+ addParameter("list", arr);
+
+ // gwt events work...
+ b.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ Window.alert("button click (gwt event)");
+ }
+ });
+ }
+
+ @Override
+ protected void onLoad() {
+ super.onLoad();
+ // since the javascript is only rendered on load, we can only interact
+ // with the template at this point
+
+ // add a gwt widget into a div using a gquery selector
+ add(b, $("#placeholder1"));
+
+ // and gquery also works
+ $("#button1").click(new Function() {
+ public boolean f(Event e) {
+ Window.alert("button click (gquery event)");
+ return true;
+ }
+ });
+
+ // do a lame gquery animation
+ $("#button1").animate("top:'+=500'", 500, new Function() {
+ public void f(Element e) {
+ $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));
+ $(e).animate("top:'-=500'");
+ }
+ });
+ }
+}
View
31 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/TestData.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.examples.client;
+
+import java.util.Date;
+
+public interface TestData {
+ public String getField1();
+ public void setField1(String v);
+
+ public Date getDateField();
+ public void setDateField(Date v);
+
+ public Integer getNumber();
+ public void setNumber(Integer v);
+}
View
25 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/TestDataFactory.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.examples.client;
+
+import com.google.web.bindery.autobean.shared.AutoBean;
+import com.google.web.bindery.autobean.shared.AutoBeanFactory;
+
+public interface TestDataFactory extends AutoBeanFactory {
+ AutoBean<TestData> data();
+}
View
47 examples/src/main/java/com/villagechief/gwt/hogan/examples/client/TestDataImpl.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.examples.client;
+
+import java.util.Date;
+
+public class TestDataImpl implements TestData{
+ private String field1;
+ private Date dateField;
+ private Integer number;
+
+ public String getField1() {
+ return field1;
+ }
+ public void setField1(String v) {
+ this.field1 = v;
+ }
+
+ public Date getDateField() {
+ return dateField;
+ }
+ public void setDateField(Date v) {
+ this.dateField = v;
+ }
+
+ public Integer getNumber() {
+ return number;
+ }
+ public void setNumber(Integer v) {
+ this.number = v;
+ }
+}
View
37 examples/src/main/java/com/villagechief/gwt/hogan/examples/gwtHoganExamples.gwt.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<module rename-to='gwtHoganExample'>
+ <inherits name='com.google.gwt.user.User' />
+ <inherits name='com.google.gwt.user.theme.standard.Standard' />
+
+ <!-- required for gwt-hogan -->
+ <inherits name="com.google.gwt.json.JSON" />
+ <!-- required for doing jquery like expressions -->
+ <inherits name='com.google.gwt.query.Query'/>
+ <!-- required for passing java objects to templates -->
+ <inherits name="com.google.web.bindery.autobean.AutoBean"/>
+ <!-- include gwt-hogan -->
+ <inherits name="com.villagechief.gwt.hogan.gwtHogan" />
+
+ <entry-point class='com.villagechief.gwt.hogan.examples.client.GwtHoganExample' />
+ <source path='client' />
+
+</module>
View
32 examples/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <!-- Default page to serve -->
+ <welcome-file-list>
+ <welcome-file>gwtHogan.html</welcome-file>
+ </welcome-file-list>
+
+</web-app>
View
31 examples/src/main/webapp/gwtHogan.css
@@ -0,0 +1,31 @@
+/** Example rules used by the template application (remove for your app) */
+h1 {
+ font-size: 2em;
+ font-weight: bold;
+ color: #777777;
+ margin: 40px 0px 70px;
+ text-align: center;
+}
+
+.sendButton {
+ display: block;
+ font-size: 16pt;
+}
+
+/** Most GWT widgets already have a style name defined */
+.gwt-DialogBox {
+ width: 400px;
+}
+
+.dialogVPanel {
+ margin: 5px;
+}
+
+.serverResponseLabelError {
+ color: red;
+}
+
+/** Set ids using widget.getElement().setId("idOfElement") */
+#closeButton {
+ margin: 15px 6px 6px;
+}
View
37 examples/src/main/webapp/gwtHogan.html
@@ -0,0 +1,37 @@
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!doctype html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <link type="text/css" rel="stylesheet" href="gwtHogan.css">
+ <title>Gwt Hogan Example</title>
+ <script type="text/javascript" language="javascript" src="gwtHoganExample/gwtHoganExample.nocache.js"></script>
+ </head>
+ <body>
+ <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
+
+ <noscript>
+ <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
+ Your web browser must have JavaScript enabled in order for this application to display correctly.
+ </div>
+ </noscript>
+ </body>
+</html>
View
127 gwt-hogan/pom.xml
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009-2011 the original author or authors. See the notice.md
+ file distributed with this work for additional information regarding copyright
+ ownership. Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License. You may
+ obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software distributed
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the License. -->
+<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/maven-v4_0_0.xsd">
+
+ <!-- POM file generated with GWT webAppCreator -->
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan-project</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <properties>
+ <!-- GWT needs at least java 1.5 -->
+ <webappDirectory>src/main/webapp</webappDirectory>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-servlet</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-user</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- TODO: this seems wrong? -->
+ <dependency>
+ <groupId>com.google.gwt</groupId>
+ <artifactId>gwt-dev</artifactId>
+ <version>${gwtVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- support jquery style selectors -->
+ <dependency>
+ <groupId>com.googlecode.gwtquery</groupId>
+ <artifactId>gwtquery</artifactId>
+ <version>${gQueryVersion}</version>
+ </dependency>
+
+ <!-- server side javascript compilation of the hogan templates -->
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.7R2</version>
+ </dependency>
+
+ <!-- requirement of google json, not sure why it's not included -->
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20090211</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <!-- Generate compiled stuff in the folder used for developing mode -->
+ <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
+
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.java</include>
+ <include>**/*.gwt.xml</include>
+ <include>**/*.js</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <!-- Copy static web files before executing gwt:run -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.4.1</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${webappDirectory}/WEB-INF/classes</directory>
+ <includes>
+ <include>**/*.class</include>
+ <include>**/*.xml</include>
+ <include>**/*.js</include>
+ </includes>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
View
24 gwt-hogan/src/main/java/com/villagechief/gwt/hogan/client/HasParameters.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.client;
+
+public interface HasParameters {
+ public void addParameter(String key, Object value);
+
+ public Object getParameter(String key);
+}
View
78 gwt-hogan/src/main/java/com/villagechief/gwt/hogan/client/HoganWidget.java
@@ -0,0 +1,78 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.client;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.json.client.JSONNull;
+import com.google.gwt.json.client.JSONValue;
+import com.google.gwt.query.client.GQuery;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.web.bindery.autobean.shared.AutoBean;
+import com.google.web.bindery.autobean.shared.AutoBeanUtils;
+
+public abstract class HoganWidget extends ComplexPanel implements HasParameters {
+ protected Map<String, Object> parameters = new HashMap<String, Object>();
+
+ public HoganWidget() {
+ setElement(DOM.createDiv());
+ }
+
+ public void addParameter(String key, Object value) {
+ if (value == null) {
+ parameters.put(key, JSONNull.getInstance());
+ } else if (value instanceof JSONValue || value instanceof AutoBean) {
+ parameters.put(key, value);
+ } else {
+ AutoBean<?> bean = AutoBeanUtils.getAutoBean(value);
+ if (bean == null)
+ throw new IllegalArgumentException(key + " must be loaded into AutoBean");
+ parameters.put(key, bean);
+ }
+ }
+
+ public Object getParameter(String key) {
+ return parameters.get(key);
+ }
+
+ protected Map<String, Object> getParameters() {
+ return parameters;
+ }
+
+ @Override
+ public void add(Widget child) {
+ super.add(child, getElement());
+ }
+
+ public void add(Widget child, GQuery container) {
+ child.removeFromParent();
+
+ // Logical attach.
+ getChildren().add(child);
+
+ // Physical attach.
+ container.append(child.getElement());
+
+ // Adopt.
+ adopt(child);
+ }
+
+}
View
30 gwt-hogan/src/main/java/com/villagechief/gwt/hogan/gwtHogan.gwt.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<module>
+ <inherits name='com.google.gwt.user.User' />
+ <inherits name="com.google.web.bindery.autobean.AutoBean" />
+ <script src="https://s3.amazonaws.com/villagechief/libs/hogan/hogan.js"></script>
+
+ <generate-with class="com.villagechief.gwt.hogan.server.HoganGenerator">
+ <when-type-assignable class="com.villagechief.gwt.hogan.client.HoganWidget" />
+ </generate-with>
+ <source path='client' />
+</module>
View
150 gwt-hogan/src/main/java/com/villagechief/gwt/hogan/server/HoganGenerator.java
@@ -0,0 +1,150 @@
+/**
+ * Copyright (C) 2009-2012 the original author or authors.
+ * See the notice.md file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.villagechief.gwt.hogan.server;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringReader;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.SimpleScriptContext;
+
+import com.google.gwt.core.ext.Generator;
+import com.google.gwt.core.ext.GeneratorContext;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
+import com.google.gwt.user.rebind.SourceWriter;
+
+public class HoganGenerator extends Generator {
+ @Override
+ public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
+ // Build a new class, that implements a "paintScreen" method
+ JClassType classType;
+
+ try {
+ String name = typeName + "Generated";
+ classType = context.getTypeOracle().getType(typeName);
+ SourceWriter src = getSourceWriter(classType, context, logger);
+ if ( src == null )
+ return name;
+
+ // fetch the template;
+ // TODO: make this name configurable some how?
+ String templateResource = "/" + typeName.replace(".", "/") + ".html";
+ InputStream templateStream = getClass().getResourceAsStream(templateResource);
+ if (templateStream == null) {
+ logger.log(TreeLogger.ERROR, "Template not found: " + templateResource);
+ throw new UnableToCompleteException();
+ }
+ InputStreamReader streamReader = new InputStreamReader(templateStream);
+ StringBuilder sb = new StringBuilder();
+ char[] cbuf = new char[1024];
+ int len;
+ while ( (len=streamReader.read(cbuf)) >= 0) {
+ sb.append(cbuf, 0, len);
+ }
+
+ ScriptEngineManager engineMgr = new ScriptEngineManager();
+ ScriptEngine engine = engineMgr.getEngineByName("ECMAScript");
+ if (engine == null) {
+ logger.log(TreeLogger.ERROR, "ECMAScript scripting engine not defined");
+ throw new UnableToCompleteException();
+ }
+ InputStream hoganInputStream = HoganGenerator.class.getResourceAsStream("hogan.js");
+ if (hoganInputStream == null) {
+ logger.log(TreeLogger.ERROR, "hogan.js is missing");
+ throw new UnableToCompleteException();
+ }
+ Reader hoganReader = new InputStreamReader(hoganInputStream);
+ Reader templatesReader = new StringReader("Hogan.compile(data, {asString: true});");
+
+ ScriptContext scriptContext = new SimpleScriptContext();
+ Bindings b = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+ b.put("data", sb.toString());
+
+ engine.eval(hoganReader, scriptContext);
+ String template = (String) engine.eval(templatesReader, scriptContext);
+
+
+ src.println("@Override");
+ src.println("protected void onLoad() {");
+ src.println(" JSONObject data = new JSONObject();");
+ src.println(" Map<String, Object> params = new HashMap<String, Object>();");
+ src.println(" for ( Entry<String, Object> e : getParameters().entrySet() ){");
+ src.println(" JSONValue bean = null;");
+ src.println(" if ( e.getValue() instanceof JSONValue )");
+ src.println(" bean = (JSONValue)e.getValue();");
+ src.println(" else if ( e.getValue() instanceof AutoBean<?> )");
+ src.println(" bean = (JSONValue)JSONParser.parseStrict(AutoBeanCodex.encode((AutoBean<?>)e.getValue()).getPayload());");
+ src.println(" data.put(e.getKey(), bean);");
+ src.println(" }");
+ src.println(" render(getElement(), data.getJavaScriptObject());");
+ src.println(" super.onLoad();");
+ src.println("}");
+ src.println("");
+ src.println("static native void render(Object el, JavaScriptObject params) /*-{");
+ src.println(" var t = new $wnd.HoganTemplate();");
+ src.println(" t.r = " + template + ";");
+ src.println(" el.innerHTML = t.render(params);");
+ src.println("}-*/;");
+
+ src.commit(logger);
+
+ System.out.println("Generating for: " + typeName);
+ return name;
+
+ } catch ( Throwable e ){
+ logger.log(TreeLogger.ERROR, e.getMessage());
+ e.printStackTrace(System.err);
+ throw new UnableToCompleteException();
+ }
+ }
+
+ public SourceWriter getSourceWriter(JClassType classType, GeneratorContext context, TreeLogger logger) {
+ String packageName = classType.getPackage().getName();
+ String simpleName = classType.getSimpleSourceName() + "Generated";
+ ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
+ composer.setSuperclass(classType.getName());
+
+ // Need to add whatever imports your generated class needs.
+ composer.addImport("com.google.gwt.core.client.JavaScriptObject");
+ composer.addImport("com.google.gwt.json.client.JSONObject");
+ composer.addImport("com.google.gwt.json.client.JSONParser");
+ composer.addImport("com.google.web.bindery.autobean.shared.AutoBean");
+ composer.addImport("com.google.web.bindery.autobean.shared.AutoBeanCodex");
+ composer.addImport("com.google.web.bindery.autobean.shared.AutoBeanUtils");
+ composer.addImport("java.util.HashMap");
+ composer.addImport("java.util.Map");
+ composer.addImport("java.util.Map.Entry");
+ composer.addImport("com.google.gwt.json.client.JSONValue");
+
+ PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
+ if (printWriter == null) {
+ return null;
+ } else {
+ SourceWriter sw = composer.createSourceWriter(context, printWriter);
+ return sw;
+ }
+ }
+}
View
545 gwt-hogan/src/main/java/com/villagechief/gwt/hogan/server/hogan.js
@@ -0,0 +1,545 @@
+/*
+ * Copyright 2011 Twitter, Inc.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var HoganTemplate = (function () {
+
+ function constructor(text) {
+ this.text = text;
+ }
+
+ constructor.prototype = {
+
+ // render: replaced by generated code.
+ r: function (context, partials, indent) { return ''; },
+
+ // variable escaping
+ v: hoganEscape,
+
+ render: function render(context, partials, indent) {
+ return this.r(context, partials, indent);
+ },
+
+ // tries to find a partial in the curent scope and render it
+ rp: function(name, context, partials, indent) {
+ var partial = partials[name];
+
+ if (!partial) {
+ return '';
+ }
+
+ return partial.r(context, partials, indent);
+ },
+
+ // render a section
+ rs: function(context, partials, section) {
+ var buf = '',
+ tail = context[context.length - 1];
+
+ if (!isArray(tail)) {
+ return buf = section(context, partials);
+ }
+
+ for (var i = 0; i < tail.length; i++) {
+ context.push(tail[i]);
+ buf += section(context, partials);
+ context.pop();
+ }
+
+ return buf;
+ },
+
+ // maybe start a section
+ s: function(val, ctx, partials, inverted, start, end, tags) {
+ var pass;
+
+ if (isArray(val) && val.length === 0) {
+ return false;
+ }
+
+ if (!inverted && typeof val == 'function') {
+ val = this.ls(val, ctx, partials, start, end, tags);
+ }
+
+ pass = (val === '') || !!val;
+
+ if (!inverted && pass && ctx) {
+ ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);
+ }
+
+ return pass;
+ },
+
+ // find values with dotted names
+ d: function(key, ctx, partials, returnFound) {
+
+ var names = key.split('.'),
+ val = this.f(names[0], ctx, partials, returnFound),
+ cx = null;
+
+ if (key === '.' && isArray(ctx[ctx.length - 2])) {
+ return ctx[ctx.length - 1];
+ }
+
+ for (var i = 1; i < names.length; i++) {
+ if (val && typeof val == 'object' && names[i] in val) {
+ cx = val;
+ val = val[names[i]];
+ } else {
+ val = '';
+ }
+ }
+
+ if (returnFound && !val) {
+ return false;
+ }
+
+ if (!returnFound && typeof val == 'function') {
+ ctx.push(cx);
+ val = this.lv(val, ctx, partials);
+ ctx.pop();
+ }
+
+ return val;
+ },
+
+ // find values with normal names
+ f: function(key, ctx, partials, returnFound) {
+ var val = false,
+ v = null,
+ found = false;
+
+ for (var i = ctx.length - 1; i >= 0; i--) {
+ v = ctx[i];
+ if (v && typeof v == 'object' && key in v) {
+ val = v[key];
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ return (returnFound) ? false : "";
+ }
+
+ if (!returnFound && typeof val == 'function') {
+ val = this.lv(val, ctx, partials);
+ }
+
+ return val;
+ },
+
+ // higher order templates
+ ho: function(val, cx, partials, text, tags) {
+ var t = val.call(cx, text, function(t) {
+ return Hogan.compile(t, {delimiters: tags}).render(cx, partials);
+ });
+ var s = Hogan.compile(t.toString(), {delimiters: tags}).render(cx, partials);
+ this.b = s;
+ return false;
+ },
+
+ // higher order template result buffer
+ b: '',
+
+ // lambda replace section
+ ls: function(val, ctx, partials, start, end, tags) {
+ var cx = ctx[ctx.length - 1],
+ t = val.call(cx);
+
+ if (val.length > 0) {
+ return this.ho(val, cx, partials, this.text.substring(start, end), tags);
+ }
+
+ if (typeof t == 'function') {
+ return this.ho(t, cx, partials, this.text.substring(start, end), tags);
+ }
+
+ return t;
+ },
+
+ // lambda replace variable
+ lv: function(val, ctx, partials) {
+ var cx = ctx[ctx.length - 1];
+ return Hogan.compile(val.call(cx).toString()).render(cx, partials);
+ }
+
+ };
+
+ var rAmp = /&/g,
+ rLt = /</g,
+ rGt = />/g,
+ rApos =/\'/g,
+ rQuot = /\"/g,
+ hChars =/[&<>\"\']/;
+
+ function hoganEscape(str) {
+ str = String(str === null ? '' : str);
+ return hChars.test(str) ?
+ str
+ .replace(rAmp,'&amp;')
+ .replace(rLt,'&lt;')
+ .replace(rGt,'&gt;')
+ .replace(rApos,'&#39;')
+ .replace(rQuot, '&quot;') :
+ str;
+ }
+
+ var isArray = Array.isArray || function(a) {
+ return Object.prototype.toString.call(a) === '[object Array]';
+ };
+
+ return constructor;
+
+})();
+
+var Hogan = (function () {
+
+ // Setup regex assignments
+ // remove whitespace according to Mustache spec
+ var rIsWhitespace = /\S/,
+ rQuot = /\"/g,
+ rNewline = /\n/g,
+ rCr = /\r/g,
+ rSlash = /\\/g,
+ tagTypes = {
+ '#': 1, '^': 2, '/': 3, '!': 4, '>': 5,
+ '<': 6, '=': 7, '_v': 8, '{': 9, '&': 10
+ };
+
+ function scan(text, delimiters) {
+ var len = text.length,
+ IN_TEXT = 0,
+ IN_TAG_TYPE = 1,
+ IN_TAG = 2,
+ state = IN_TEXT,
+ tagType = null,
+ tag = null,
+ buf = '',
+ tokens = [],
+ seenTag = false,
+ i = 0,
+ lineStart = 0,
+ otag = '{{',
+ ctag = '}}';
+
+ function addBuf() {
+ if (buf.length > 0) {
+ tokens.push(new String(buf));
+ buf = '';
+ }
+ }
+
+ function lineIsWhitespace() {
+ var isAllWhitespace = true;
+ for (var j = lineStart; j < tokens.length; j++) {
+ isAllWhitespace =
+ (tokens[j].tag && tagTypes[tokens[j].tag] < tagTypes['_v']) ||
+ (!tokens[j].tag && tokens[j].match(rIsWhitespace) === null);
+ if (!isAllWhitespace) {
+ return false;
+ }
+ }
+
+ return isAllWhitespace;
+ }
+
+ function filterLine(haveSeenTag, noNewLine) {
+ addBuf();
+
+ if (haveSeenTag && lineIsWhitespace()) {
+ for (var j = lineStart, next; j < tokens.length; j++) {
+ if (!tokens[j].tag) {
+ if ((next = tokens[j+1]) && next.tag == '>') {
+ // set indent to token value
+ next.indent = tokens[j].toString()
+ }
+ tokens.splice(j, 1);
+ }
+ }
+ } else if (!noNewLine) {
+ tokens.push({tag:'\n'});
+ }
+
+ seenTag = false;
+ lineStart = tokens.length;
+ }
+
+ function changeDelimiters(text, index) {
+ var close = '=' + ctag,
+ closeIndex = text.indexOf(close, index),
+ delimiters = trim(
+ text.substring(text.indexOf('=', index) + 1, closeIndex)
+ ).split(' ');
+
+ otag = delimiters[0];
+ ctag = delimiters[1];
+
+ return closeIndex + close.length - 1;
+ }
+
+ if (delimiters) {
+ delimiters = delimiters.split(' ');
+ otag = delimiters[0];
+ ctag = delimiters[1];
+ }
+
+ for (i = 0; i < len; i++) {
+ if (state == IN_TEXT) {
+ if (tagChange(otag, text, i)) {
+ --i;
+ addBuf();
+ state = IN_TAG_TYPE;
+ } else {
+ if (text.charAt(i) == '\n') {
+ filterLine(seenTag);
+ } else {
+ buf += text.charAt(i);
+ }
+ }
+ } else if (state == IN_TAG_TYPE) {
+ i += otag.length - 1;
+ tag = tagTypes[text.charAt(i + 1)];
+ tagType = tag ? text.charAt(i + 1) : '_v';
+ if (tagType == '=') {
+ i = changeDelimiters(text, i);
+ state = IN_TEXT;
+ } else {
+ if (tag) {
+ i++;
+ }
+ state = IN_TAG;
+ }
+ seenTag = i;
+ } else {
+ if (tagChange(ctag, text, i)) {
+ tokens.push({tag: tagType, n: trim(buf), otag: otag, ctag: ctag,
+ i: (tagType == '/') ? seenTag - ctag.length : i + otag.length});
+ buf = '';
+ i += ctag.length - 1;
+ state = IN_TEXT;
+ if (tagType == '{') {
+ i++;
+ }
+ } else {
+ buf += text.charAt(i);
+ }
+ }
+ }
+
+ filterLine(seenTag, true);
+
+ return tokens;
+ }
+
+ function trim(s) {
+ if (s.trim) {
+ return s.trim();
+ }
+
+ return s.replace(/^\s*|\s*$/g, '');
+ }
+
+ function tagChange(tag, text, index) {
+ if (text.charAt(index) != tag.charAt(0)) {
+ return false;
+ }
+
+ for (var i = 1, l = tag.length; i < l; i++) {
+ if (text.charAt(index + i) != tag.charAt(i)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ function buildTree(tokens, kind, stack, customTags) {
+ var instructions = [],
+ opener = null,
+ token = null;
+
+ while (tokens.length > 0) {
+ token = tokens.shift();
+ if (token.tag == '#' || token.tag == '^' || isOpener(token, customTags)) {
+ stack.push(token);
+ token.nodes = buildTree(tokens, token.tag, stack, customTags);
+ instructions.push(token);
+ } else if (token.tag == '/') {
+ if (stack.length === 0) {
+ throw new Error('Closing tag without opener: /' + token.n);
+ }
+ opener = stack.pop();
+ if (token.n != opener.n && !isCloser(token.n, opener.n, customTags)) {
+ throw new Error('Nesting error: ' + opener.n + ' vs. ' + token.n);
+ }
+ opener.end = token.i;
+ return instructions;
+ } else {
+ instructions.push(token);
+ }
+ }
+
+ if (stack.length > 0) {
+ throw new Error('missing closing tag: ' + stack.pop().n);
+ }
+
+ return instructions;
+ }
+
+ function isOpener(token, tags) {
+ for (var i = 0, l = tags.length; i < l; i++) {
+ if (tags[i].o == token.n) {
+ token.tag = '#';
+ return true;
+ }
+ }
+ }
+
+ function isCloser(close, open, tags) {
+ for (var i = 0, l = tags.length; i < l; i++) {
+ if (tags[i].c == close && tags[i].o == open) {
+ return true;
+ }
+ }
+ }
+
+ function generate(tree, text, options) {
+ var code = 'i = i || "";var c = [cx];var b = i + "";var _ = this;'
+ + walk(tree)
+ + 'return b;';
+
+ if (options.asString) {
+ return 'function(cx,p,i){' + code + ';}';
+ }
+
+ var template = new HoganTemplate(text);
+ template.r = new Function('cx', 'p', 'i', code);
+ return template;
+ }
+
+ function esc(s) {
+ return s.replace(rSlash, '\\\\')
+ .replace(rQuot, '\\\"')
+ .replace(rNewline, '\\n')
+ .replace(rCr, '\\r');
+ }
+
+ function chooseMethod(s) {
+ return (~s.indexOf('.')) ? 'd' : 'f';
+ }
+
+ function walk(tree) {
+ var code = '';
+ for (var i = 0, l = tree.length; i < l; i++) {
+ var tag = tree[i].tag;
+ if (tag == '#') {
+ code += section(tree[i].nodes, tree[i].n, chooseMethod(tree[i].n),
+ tree[i].i, tree[i].end, tree[i].otag + " " + tree[i].ctag);
+ } else if (tag == '^') {
+ code += invertedSection(tree[i].nodes, tree[i].n,
+ chooseMethod(tree[i].n));
+ } else if (tag == '<' || tag == '>') {
+ code += partial(tree[i]);
+ } else if (tag == '{' || tag == '&') {
+ code += tripleStache(tree[i].n, chooseMethod(tree[i].n));
+ } else if (tag == '\n') {
+ code += text('"\\n"' + (tree.length-1 == i ? '' : ' + i'));
+ } else if (tag == '_v') {
+ code += variable(tree[i].n, chooseMethod(tree[i].n));
+ } else if (tag === undefined) {
+ code += text('"' + esc(tree[i]) + '"');
+ }
+ }
+ return code;
+ }
+
+ function section(nodes, id, method, start, end, tags) {
+ return 'if(_.s(_.' + method + '("' + esc(id) + '",c,p,1),' +
+ 'c,p,0,' + start + ',' + end + ', "' + tags + '")){' +
+ 'b += _.rs(c,p,' +
+ 'function(c,p){ var b = "";' +
+ walk(nodes) +
+ 'return b;});c.pop();}' +
+ 'else{b += _.b; _.b = ""};';
+ }
+
+ function invertedSection(nodes, id, method) {
+ return 'if (!_.s(_.' + method + '("' + esc(id) + '",c,p,1),c,p,1,0,0,"")){' +
+ walk(nodes) +
+ '};';
+ }
+
+ function partial(tok) {
+ return 'b += _.rp("' + esc(tok.n) + '",c[c.length - 1],p,"' + (tok.indent || '') + '");';
+ }
+
+ function tripleStache(id, method) {
+ return 'b += (_.' + method + '("' + esc(id) + '",c,p,0));';
+ }
+
+ function variable(id, method) {
+ return 'b += (_.v(_.' + method + '("' + esc(id) + '",c,p,0)));';
+ }
+
+ function text(id) {
+ return 'b += ' + id + ';';
+ }
+
+ return ({
+ scan: scan,
+
+ parse: function(tokens, options) {
+ options = options || {};
+ return buildTree(tokens, '', [], options.sectionTags || []);
+ },
+
+ cache: {},
+
+ compile: function(text, options) {
+ // options
+ //
+ // asString: false (default)
+ //
+ // sectionTags: [{o: '_foo', c: 'foo'}]
+ // An array of object with o and c fields that indicate names for custom
+ // section tags. The example above allows parsing of {{_foo}}{{/foo}}.
+ //
+ // delimiters: A string that overrides the default delimiters.
+ // Example: "<% %>"
+ //
+ options = options || {};
+
+ var t = this.cache[text];
+
+ if (t) {
+ return t;
+ }
+
+ t = generate(this.parse(scan(text, options.delimiters), options), text, options);
+ return this.cache[text] = t;
+ }
+ });
+})();
+
+// Export the hogan constructor for Node.js and CommonJS.
+if (typeof module !== 'undefined' && module.exports) {
+ module.exports = Hogan;
+ module.exports.Template = HoganTemplate;
+} else if (typeof define === 'function' && define.amd) {
+ define(function () { return Hogan; });
+} else if (typeof exports !== 'undefined') {
+ exports.Hogan = Hogan;
+ exports.HoganTemplate = HoganTemplate;
+}
View
5 notice.md
@@ -0,0 +1,5 @@
+Gwt Hogan Copyright Notices
+==========================
+
+Copyright 2009-2012 Ben van Klinken
+
View
201 pom.xml
@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009-2011 the original author or authors.
+ See the notice.md file distributed with this work for additional
+ information regarding copyright ownership.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan-project</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>${project.artifactId}</name>
+ <description>Gwt Hogan is a templating solution for GWT.</description>
+
+ <properties>
+ <!-- Convenience property to set the GWT version -->
+ <gwtVersion>2.4.0</gwtVersion>
+ <gQueryVersion>1.1.0</gQueryVersion>
+ </properties>
+
+ <url>http://www.villagechief.com</url>
+ <inceptionYear>2012</inceptionYear>
+
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <connection>scm:git@github.com:ustramooner/gwt-hogan.git</connection>
+ <developerConnection>git@github.com:ustramooner/gwt-hogan.git</developerConnection>
+ <url>https://github.com/ustramooner/gwt-hogan</url>
+ </scm>
+
+ <developers>
+ <developer>
+ <id>bvanklinken</id>
+ <name>Ben van Klinken</name>
+ <email>ustramooner@users.sourceforge.net</email>
+ <url>http://villagechief.com</url>
+ <timezone>+10</timezone>
+ </developer>
+ </developers>
+
+ <modules>
+ <module>gwt-hogan</module>
+ <module>examples</module>
+ </modules>
+
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>gwt-maven-plugin</artifactId>
+ <version>${gwtVersion}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>resources</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <failIfNoTests>false</failIfNoTests>
+ <useFile>false</useFile>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.7</version>
+
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+
+ <configuration>
+ <charset>UTF-8</charset>
+ <docencoding>UTF-8</docencoding>
+ <version>false</version>
+ <author>true</author>
+ <keywords>true</keywords>
+
+ <doctitle>${project.name} API Reference (${project.version})</doctitle>
+ <windowtitle>${project.name} API Reference (${project.version})</windowtitle>
+ <links>
+ <link>http://download.oracle.com/javase/6/docs/api</link>
+ <link>http://google-web-toolkit.googlecode.com/svn/javadoc/2.2</link>
+ </links>
+ <encoding>UTF-8</encoding>
+ <locale>en_US</locale>
+ <linksource>true</linksource>
+ <excludePackageNames>*.internal</excludePackageNames>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <!--
+ Do a license check by running : mvn -P license license:check
+ UPdate the license check by running : mvn -P license license:format
+ -->
+ <profile>
+ <id>license</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <version>1.6.0</version>
+ <configuration>
+ <quiet>false</quiet>
+ <header>src/main/resources/license-header.txt</header>
+ <aggregate>true</aggregate>
+ <includes>
+ <include>src/**</include>
+ <include>**/pom.xml</include>
+ </includes>
+ <excludes>
+ <!-- ignore files produced during a build -->
+ <exclude>**/target/**</exclude>
+ <exclude>**/WEB-INF/classes/**</exclude>
+
+ <exclude>**/*.response-headers</exclude>
+ <exclude>**/*.response</exclude>
+
+ <!-- ignore binary files -->
+ <exclude>**/*.jpg</exclude>
+ <exclude>**/*.png</exclude>
+ <exclude>**/*.gif</exclude>
+ <exclude>**/*.ico</exclude>
+ <exclude>**/*.ipr</exclude>
+ <exclude>**/*.iml</exclude>
+ <exclude>**/*.iws</exclude>
+ </excludes>
+ <useDefaultExcludes>false</useDefaultExcludes>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
View
116 readme.rd
@@ -4,8 +4,122 @@
Description
-----------
-GwtHogan is a templating solution for GWT
+GwtHogan is a templating solution for GWT.
+It changes the Gwt paradigm of widget based code and brings a more familiar jquery + templates approach to coding while maintaining the power of GWT/Java as a strongly typed language and very efficient javascript compiler
+Features
+--------
+
+* Generator which compiles the templates
+* Can work with Native Java Object data or JSON object data
+* Can manipulate the template and add widgets to the template using GQuery
+
+Getting started
+---------------
+
+* Check out the source and run 'mvn clean install'
+* Change directory into the examples directory, and run mvn gwt:run
+
+Setup:
+* Use the following maven dependency. NOTE: there's no distribution, so for now you'll have to use your local repository.
+ <dependency>
+ <groupId>com.villagechief.gwt</groupId>
+ <artifactId>gwt-hogan</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+* Add the following to your gwt.xml file:
+ <!-- required for gwt-hogan -->
+ <inherits name="com.google.gwt.json.JSON" />
+ <!-- required for doing jquery like expressions -->
+ <inherits name='com.google.gwt.query.Query'/>
+ <!-- required for passing java objects to templates -->
+ <inherits name="com.google.web.bindery.autobean.AutoBean"/>
+ <!-- include gwt-hogan -->
+ <inherits name="com.villagechief.gwt.hogan.gwtHogan" />
+
+The HoganWidget:
+----------------
+
+A template is made up of 2 components, the html mustache file and a Java class. For example:
+
+MyTemplate.java:
+ public class MyTemplate extends HoganWidget {
+ public Test(){
+ addParameter("planet", new JSONString("world"));
+ }
+ }
+MyTemplate.html:
+ Hello {{planet}}
+
+MyTemplate can then be used like any other widget. But it MUST be constructed using GWT.create. For example:
+ MyTemplate myTemplate = GWT.create(MyTemplate.class);
+ RootPanel.get().add(myTemplate);
+
+
+Adding Widgets must be done after the widget is loaded onto the page. You can use
+GQuery to provide a selector to the add function which will be the container
+
+MyTemplate.html:
+ Click this button: <span id="button"></span>
+MyTemplate.java:
+ public class MyTemplate extends HoganWidget {
+ public void onLoad(){
+ super.onLoad();
+ add(new Button(), $("#button1"));
+ }
+ }
+
+
+Using Java Objects:
+-------------------
+Gwt Java objects need to be managed by the Gwt AutoBeans framework.
+See http://code.google.com/p/google-web-toolkit/wiki/AutoBean for more details.
+
+AutoBeans and *Managed* java objects can be passed as parameters to a HoganWidget
+
+Data object:
+ public interface TestData {
+ public String getField1();
+ public void setField1(String v);
+ }
+Factory:
+ public interface TestDataFactory extends AutoBeanFactory {
+ AutoBean<TestData> data();
+ }
+MyTemplate.java:
+ public class MyTemplate extends HoganWidget {
+ public Test(){
+ TestDataFactory beanFactory = GWT.create(TestDataFactory.class);
+ TestData test1 = beanFactory.data().as(); //get a managed TestData object
+ test1.setField1("foo");
+
+ addParameter("data", test1);
+ }
+ }
+MyTemplate.html
+ Field1: {{data.field1}}
+
+
+Event Handling and DOM Handling
+-------------------------------
+A HoganWidget doesn't contain widgets the way a normal GWT Composite widget does, but you can use GwtQuery to manipulate the DOM.
+
+So for a template like:
+ Hello <span id="planet"></span>
+
+You can put in your Template widget:
+
+ import static com.google.gwt.query.client.GQuery.*;
+ public MyTemplate()}
+ $("#planet").text("world");
+ }
+
+References
+..........
+
+* AutoBeans: http://code.google.com/p/google-web-toolkit/wiki/AutoBean
+* GwtQuery: http://code.google.com/p/gwtquery/wiki/GettingStarted
+* GWT Json: http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/json/client/package-tree.html

No commit comments for this range

Something went wrong with that request. Please try again.