Permalink
Browse files

first open source release

  • Loading branch information...
cezary-biernacki committed Nov 10, 2011
1 parent 874e493 commit 0cfb5666dd6e92e989ef28fab61ce6210ed703fa
View
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry exported="true" kind="var" path="LIB/slf4j-api-1.6.1.jar" sourcepath="/LIB/slf4j-api-1.6.1-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/commons-lang-2.1.jar" sourcepath="/LIB/commons-lang-2.1-src.zip"/>
+ <classpathentry exported="true" kind="var" path="LIB/tapestry5-annotations-5.2.6.jar" sourcepath="/LIB/tapestry5-annotations-5.2.6-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/tapestry-core-5.2.6.jar" sourcepath="/LIB/tapestry-core-5.2.6-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/tapestry-ioc-5.2.6.jar" sourcepath="/LIB/tapestry-ioc-5.2.6-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/javassist-3.12.1.GA.jar" sourcepath="/LIB/javassist-3.12.1.GA-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/js-rhino-1.7.jar" sourcepath="/LIB/js-rhino-1.7-sources.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/antlr-runtime-3.1.1.jar"/>
+ <classpathentry exported="true" kind="var" path="LIB/woodstox-core-asl-4.0.3.jar" sourcepath="/LIB/woodstox-core-asl-4.0.3-sources.zip"/>
+ <classpathentry exported="true" kind="var" path="LIB/xerces-2.6.2.jar"/>
+ <classpathentry kind="var" path="LIB/log4j-1.2.14.jar">
+ <accessrules>
+ <accessrule kind="nonaccessible" pattern="**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="var" path="LIB/slf4j-log4j12-1.6.1.jar"/>
+ <classpathentry kind="var" path="LIB/servlet-api-2.4.jar">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.nondependency" value=""/>
+ </attributes>
+ </classpathentry>
+ <classpathentry combineaccessrules="false" kind="src" path="/t52transformers"/>
+ <classpathentry kind="output" path="target/classes-eclipse"/>
+</classpath>
View
@@ -0,0 +1 @@
+target
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>t5conduit</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,12 @@
+#Wed Sep 14 14:35:34 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
View
@@ -0,0 +1,25 @@
+Module for Tapestry 5.3 that seemlessly integrate LessCSS and CoffeeScript.
+
+Just add uk.org.cezary.t5conduit.T5ConduitModule as submodule to AppModule using @SubModule.
+After that all your '*.coffee' and '*.less' resources will be automatically compiled to
+JavaScript or CSS before sending to a user browser.
+
+
+If you want to use t5conduit with Tapestry 5.2, add t52transformers (https://github.com/cezary-biernacki/t52transformers.git) module to your project.
+
+You can find already compiled binaries in https://github.com/cezary-biernacki/t5conduit-bin.git
+
+---
+Written by Cezary Biernacki.
+
+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.
View
67 pom.xml
@@ -0,0 +1,67 @@
+<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>
+ <groupId>uk.org.cezary</groupId>
+ <artifactId>t5conduit</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1-SNAPSHOT</version>
+ <name>LessCSS and CoffeeScript integration for Tapestry 5.2 and 5.3</name>
+ <url>https://github.com/cezary-biernacki/t5conduit.git</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-core</artifactId>
+ <version>${tapestry-release-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.7R1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <optimize>true</optimize>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <!-- This repository is only needed when the tapestry-release-version is a snapshot release. -->
+ <repository>
+ <id>apache-snapshots</id>
+ <url>http://repository.apache.org/snapshots/</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+
+ <!-- As above, this can be commented out when access to the snapshot version of a Tapestry Maven plugin is not required. -->
+ <pluginRepository>
+ <id>apache-snapshots</id>
+ <url>http://repository.apache.org/snapshots/</url>
+ </pluginRepository>
+
+ </pluginRepositories>
+
+ <properties>
+ <tapestry-release-version>5.3.0</tapestry-release-version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+</project>
@@ -0,0 +1,73 @@
+// Copyright 2011 Cezary Biernacki. 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 uk.org.cezary.t5conduit;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry5.services.assets.ResourceDependencies;
+
+/**
+ * A helper service that allows loading files relative to a class loader. Useful for implementing {@link DependencySourceLoader},
+ * used by {@link LessToCssTransformer}.
+ * Created: 5 Oct 2011
+ * </p>
+ *
+ * @author Cezary Biernacki
+ */
+
+public class ClassPathLoader {
+
+
+ public String readFile(Class<?> clazz, String prefix, String name, Resource baseResource, ResourceDependencies dependencies) throws IOException {
+ if (!name.startsWith(prefix)) {
+ return null;
+ }
+
+ final String strippedName = name.substring(prefix.length());
+ final String resolvedName;
+ if (!strippedName.startsWith("/")) {
+ resolvedName = String.format("/%s/%s", clazz.getPackage().getName().replace('.', '/'), strippedName);
+ } else {
+ resolvedName = strippedName;
+ }
+
+ final ClasspathResource resource = new ClasspathResource(clazz.getClassLoader(), resolvedName);
+ if (!resource.exists()) {
+ return null;
+ }
+
+ dependencies.addDependency(resource);
+
+ final Reader reader = new BufferedReader(new InputStreamReader(resource.toURL().openStream(), "UTF-8"));
+ try {
+ final StringBuilder b = new StringBuilder();
+
+ int c;
+ while ((c = reader.read()) != -1) {
+ b.append((char) c);
+ }
+
+ return b.toString();
+ } finally {
+ reader.close();
+ }
+ }
+
+
+}
@@ -0,0 +1,94 @@
+// Copyright 2011 Cezary Biernacki., 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 uk.org.cezary.t5conduit;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.services.assets.ResourceDependencies;
+import org.apache.tapestry5.services.assets.ResourceTransformer;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+
+
+/**
+ * Transforms <code>.coffee</code> to JavaScript.
+ * <p>
+ * Created: 15 Sep 2011
+ * </p>
+ *
+ * @author Cezary Biernacki
+ * @see <a href="http://coffeescript.org/">http://coffeescript.org/</a>
+ */
+
+public class CoffeeToJsTransformer implements ResourceTransformer {
+
+ private static final String COFFEE_JS = "coffee-script-1.1.2.js";
+
+ private final Scriptable globalScope;
+
+ public CoffeeToJsTransformer() throws IOException {
+ final Reader reader = new InputStreamReader(getClass().getResourceAsStream(COFFEE_JS), "UTF-8");
+
+ try {
+ Context context = Context.enter();
+ context.setOptimizationLevel(-1); // Without this, Rhino hits a 64K bytecode limit and
+ // fails
+ try {
+ globalScope = context.initStandardObjects();
+ context.evaluateReader(globalScope, reader, COFFEE_JS, 0, null);
+ } finally {
+ Context.exit();
+ }
+ } finally {
+ reader.close();
+ }
+ }
+
+ @Override
+ public InputStream transform(Resource source, ResourceDependencies dependencies) throws IOException {
+ final StringBuilder b = new StringBuilder();
+
+ final InputStreamReader reader = new InputStreamReader(source.openStream(), "UTF-8");
+ try {
+ int c;
+ while ((c = reader.read()) != -1) {
+ b.append((char) c);
+ }
+ } finally {
+ reader.close();
+ }
+
+ final String result = this.compile(b.toString());
+ return new ByteArrayInputStream(result.getBytes("UTF-8"));
+ }
+
+ private String compile(String source) {
+
+ final Context context = Context.enter();
+ try {
+ Scriptable scope = context.newObject(globalScope);
+ scope.setParentScope(globalScope);
+ scope.put("source", scope, source);
+ return (String) context.evaluateString(scope, "CoffeeScript.compile(source);",
+ "CoffeeToJsTransformer", 0, null);
+ } finally {
+ Context.exit();
+ }
+ }
+}
@@ -0,0 +1,44 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// 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 uk.org.cezary.t5conduit;
+
+import java.io.IOException;
+
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.services.assets.ResourceDependencies;
+
+/**
+ * Interface for loading files requested from transformed files.
+ * Used to configure {@link LessToCssTransformer}, which calls it
+ * for resolving <code>@import</code> clauses in <code>.less</code> file.<p>
+ * <p>
+ * Created: 5 Oct 2011
+ * </p>
+ *
+ * @author Cezary Biernacki
+ */
+
+public interface DependencySourceLoader {
+
+ /**
+ * Should read a given source file if it exits and return its content.
+ * @param name a file name with path, as specified in a parent source file.
+ *
+ * @return a content of file or <code>null</code> if the file can not be found.
+ */
+ String readFile(String name, Resource baseResource, ResourceDependencies dependencies) throws IOException;
+}
+
+
Oops, something went wrong.

0 comments on commit 0cfb566

Please sign in to comment.