Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14 from sroebuck/master

Added Less filter using Apache 2 licensed lesscss-engine library
  • Loading branch information...
commit f033a09aa662778e14af6cdb2f7231aeb9dd143a 2 parents 1b132a4 + 504de90
@jstrachan jstrachan authored
View
2  pom.xml
@@ -214,6 +214,8 @@
<module>scalate-jsp-converter</module>
<module>scalate-markdownj</module>
<module>scalate-jruby</module>
+ <module>scalate-pegdown</module>
+ <module>scalate-less</module>
</modules>
View
8 project/build/Scalate.scala
@@ -15,6 +15,8 @@ class ScalateParentProject(info: ProjectInfo) extends ParentProject(info) {
lazy val scalate_war = project("scalate-war", "scalate-war", new ScalateWar(_), scalate_core, scalate_test)
lazy val scalate_sample = project("scalate-sample", "scalate-sample", new ScalateSample(_), scalate_core, scalate_test, scalate_war)
lazy val scalate_bookstore = project("scalate-bookstore", "scalate-bookstore", new ScalateBookstore(_), scalate_core, scalate_test, scalate_war)
+ lazy val scalate_pegdown = project("scalate-pegdown", "scalate-pegdown", new ScalatePegdown(_), scalate_core, scalate_test)
+ lazy val scalate_less = project("scalate-less", "scalate-less", new ScalateLess(_), scalate_core, scalate_test)
class ScalateProject(info: ProjectInfo) extends DefaultProject(info) {
@@ -63,4 +65,10 @@ class ScalateParentProject(info: ProjectInfo) extends ParentProject(info) {
class ScalateBookstore(info: ProjectInfo) extends ScalateWebProject(info) {
}
+ class ScalatePegdown(info: ProjectInfo) extends ScalateWebProject(info) {
+ }
+
+ class ScalateLess(info: ProjectInfo) extends ScalateWebProject(info) {
+ }
+
}
View
86 scalate-less/pom.xml
@@ -0,0 +1,86 @@
+<?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>
+ <parent>
+ <groupId>org.fusesource.scalate</groupId>
+ <artifactId>scalate-project</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>scalate-less</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>${project.artifactId}</name>
+ <description>A Scalate filter that uses Less</description>
+
+ <properties>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.fusesource.scalate</groupId>
+ <artifactId>scalate-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.asual.lesscss</groupId>
+ <artifactId>lesscss-engine</artifactId>
+ <version>1.0.41</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.fusesource.scalate</groupId>
+ <artifactId>scalate-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.scalatest</groupId>
+ <artifactId>${scalatest-artifact}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>com.asual.lesscss</id>
+ <name>Asual Public Repository</name>
+ <url>http://www.asual.com/maven/content/groups/public</url>
+ </repository>
+ </repositories>
+
+</project>
View
19 scalate-less/src/main/resources/META-INF/services/org.fusesource.scalate/addon.index
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+org.fusesource.scalate.filter.LessFilter
View
47 scalate-less/src/main/scala/org/fusesource/scalate/filter/LessFilter.scala
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.fusesource.scalate.filter
+
+import org.fusesource.scalate.{TemplateEngineAddOn, RenderContext, TemplateEngine}
+import com.asual.lesscss.LessEngine
+
+/**
+ * Renders Less syntax.
+ *
+ * @author <a href="mailto:stuart.roebuck@gmail.com">Stuart Roebuck</a>
+ */
+object LessFilter extends Filter with TemplateEngineAddOn {
+
+ private val lessEngine = new LessEngine
+
+ def filter(context: RenderContext, content: String) = {
+ synchronized {
+ // This code block is synchronized as I'm not confident that the Less filter is thread safe.
+ val css = lessEngine.compile(content).stripLineEnd
+ """<style type="text/css">%n%s%n</style>""".format(css)
+ }
+ }
+
+ /**
+ * Add the less filter to the template engine.
+ */
+ def apply(te: TemplateEngine) {
+ te.filters += "less" -> LessFilter
+ te.pipelines += "less" -> List(LessFilter)
+ }
+}
View
22 scalate-pegdown/src/main/scala/org/fusesource/scalate/filter/PegDownFilter.scala
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (C) 2009-2011 the original author or authors.
* See the notice.md file distributed with this work for additional
* information regarding copyright ownership.
@@ -17,24 +17,6 @@
*/
package org.fusesource.scalate.filter
-/**
- * Copyright (C) 2009-2010 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.
- */
-
import org.fusesource.scalate.{TemplateEngineAddOn, RenderContext, TemplateEngine}
import org.fusesource.scalate.filter.Filter
import org.pegdown.{Extensions, PegDownProcessor}
@@ -42,7 +24,7 @@ import org.pegdown.{Extensions, PegDownProcessor}
/**
* Renders markdown syntax with multi-markdown like extras.
*
- * @author <a href="stuart.roebuck@gmail.com">Stuart Roebuck</a>
+ * @author <a href="mailto:stuart.roebuck@gmail.com">Stuart Roebuck</a>
*/
object PegDownFilter extends Filter with TemplateEngineAddOn {
Please sign in to comment.
Something went wrong with that request. Please try again.