Use Node to compile CoffeeScript, when available
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/6fb9a38e Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/6fb9a38e Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/6fb9a38e Branch: refs/heads/master Commit: 6fb9a38ed845dd0663fa285e57fc4f885ebe8328 Parents: 75fda37 Author: Howard M. Lewis Ship <hls...@apache.org> Authored: Fri Jun 21 13:53:11 2013 -0700 Committer: Howard M. Lewis Ship <hls...@apache.org> Committed: Fri Jun 21 13:53:11 2013 -0700 ---------------------------------------------------------------------- .../wro4j/NodeOrRhinoCoffeeScriptCompiler.java | 63 ++++++++++++++++++++ .../tapestry5/wro4j/modules/WRO4JModule.java | 14 +---- 2 files changed, 64 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fb9a38e/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/NodeOrRhinoCoffeeScriptCompiler.java ---------------------------------------------------------------------- diff --git a/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/NodeOrRhinoCoffeeScriptCompiler.java b/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/NodeOrRhinoCoffeeScriptCompiler.java new file mode 100644 index 0000000..03e175d --- /dev/null +++ b/tapestry-wro4j/src/main/java/org/apache/tapestry5/internal/wro4j/NodeOrRhinoCoffeeScriptCompiler.java @@ -0,0 +1,63 @@ +// Copyright 2013 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 org.apache.tapestry5.internal.wro4j; + +import org.slf4j.Logger; +import ro.isdc.wro.extensions.processor.js.NodeCoffeeScriptProcessor; +import ro.isdc.wro.extensions.processor.js.RhinoCoffeeScriptProcessor; +import ro.isdc.wro.model.resource.Resource; +import ro.isdc.wro.model.resource.processor.ResourcePreProcessor; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +/** + * Creates either a {@link NodeCoffeeScriptProcessor} or a {@link RhinoCoffeeScriptProcessor} + * and delegates the process() method to it. {@link ro.isdc.wro.extensions.processor.js.CoffeeScriptProcessor} should + * do this, but doesn't work correctly inside Tapestry due to its home-grown injection system. + */ +public class NodeOrRhinoCoffeeScriptCompiler implements ResourcePreProcessor +{ + private final Logger logger; + + private final ResourcePreProcessor processor; + + public NodeOrRhinoCoffeeScriptCompiler(Logger logger) + { + this.logger = logger; + processor = create(); + } + + private ResourcePreProcessor create() + { + NodeCoffeeScriptProcessor processor = new NodeCoffeeScriptProcessor(); + + if (processor.isSupported()) + { + logger.info("'coffee' command is available; using Node to compile CoffeeScript files."); + return processor; + } + + logger.info("'coffee' command is not available, using Rhino to compile CoffeeScript files."); + + return new RhinoCoffeeScriptProcessor(); + } + + public void process(Resource resource, Reader reader, Writer writer) throws IOException + { + processor.process(resource, reader, writer); + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/6fb9a38e/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java ---------------------------------------------------------------------- diff --git a/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java b/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java index 05b39a7..5b35c23 100644 --- a/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java +++ b/tapestry-wro4j/src/main/java/org/apache/tapestry5/wro4j/modules/WRO4JModule.java @@ -33,7 +33,6 @@ import org.apache.tapestry5.services.assets.StreamableResourceSource; import org.apache.tapestry5.wro4j.services.ResourceProcessorSource; import ro.isdc.wro.extensions.processor.js.GoogleClosureCompressorProcessor; import ro.isdc.wro.extensions.processor.js.RhinoCoffeeScriptProcessor; -import ro.isdc.wro.extensions.processor.support.coffeescript.CoffeeScript; import ro.isdc.wro.model.resource.processor.ResourcePreProcessor; import ro.isdc.wro.model.resource.processor.impl.css.CssCompressorProcessor; @@ -65,18 +64,7 @@ public class WRO4JModule @Contribute(ResourceProcessorSource.class) public static void provideDefaultProcessors(MappedConfiguration<String, ResourcePreProcessor> configuration) { - configuration.add("CoffeeScriptCompiler", - new RhinoCoffeeScriptProcessor() - { - @Override - protected CoffeeScript newCoffeeScript() - { - return new CoffeeScript().setOptions("bare"); - } - } - ); - - + configuration.addInstance("CoffeeScriptCompiler", NodeOrRhinoCoffeeScriptCompiler.class); configuration.addInstance("CSSMinimizer", CssCompressorProcessor.class); configuration.add("JavaScriptMinimizer", new GoogleClosureCompressorProcessor()); }