aboutsummaryrefslogtreecommitdiffstats
path: root/theme-compiler
diff options
context:
space:
mode:
Diffstat (limited to 'theme-compiler')
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java104
-rw-r--r--[-rwxr-xr-x]theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java0
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java200
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java20
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java44
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java7
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/resolver/VaadinResolver.java90
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java22
-rw-r--r--theme-compiler/tests/resources/css/compass-import.css49
-rw-r--r--theme-compiler/tests/resources/scss/compass-test/compass-import.scss4
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/_compass.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass-import2.scss4
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/_css3.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/_typography.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/_utilities.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/css3/_border-radius.scss4
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/css3/_inline-block.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/css3/_opacity.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/typography/_links.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/typography/_lists.scss3
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/typography/_text.scss6
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_color.scss4
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_general.scss5
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_sprites.scss6
-rw-r--r--theme-compiler/tests/resources/scss/compass-test2/license-readme.txt26
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java18
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/testcases/scss/CompassImports.java80
27 files changed, 551 insertions, 166 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
index dbb3e571dc..7213553e18 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java
@@ -19,10 +19,10 @@ package com.vaadin.sass.internal;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -35,8 +35,9 @@ import com.vaadin.sass.internal.handler.SCSSErrorHandler;
import com.vaadin.sass.internal.parser.ParseException;
import com.vaadin.sass.internal.parser.Parser;
import com.vaadin.sass.internal.parser.SCSSParseException;
+import com.vaadin.sass.internal.resolver.ClassloaderResolver;
+import com.vaadin.sass.internal.resolver.FilesystemResolver;
import com.vaadin.sass.internal.resolver.ScssStylesheetResolver;
-import com.vaadin.sass.internal.resolver.VaadinResolver;
import com.vaadin.sass.internal.tree.BlockNode;
import com.vaadin.sass.internal.tree.MixinDefNode;
import com.vaadin.sass.internal.tree.Node;
@@ -59,10 +60,12 @@ public class ScssStylesheet extends Node {
private static HashMap<Node, Node> lastNodeAdded = new HashMap<Node, Node>();
- private String fileName;
+ private File file;
private String charset;
+ private List<ScssStylesheetResolver> resolvers = new ArrayList<ScssStylesheetResolver>();
+
/**
* Read in a file SCSS and parse it into a ScssStylesheet
*
@@ -101,8 +104,8 @@ public class ScssStylesheet extends Node {
* @throws CSSException
* @throws IOException
*/
- public static ScssStylesheet get(String identifier, String encoding)
- throws CSSException, IOException {
+ public static ScssStylesheet get(String identifier,
+ ScssStylesheet parentStylesheet) throws CSSException, IOException {
/*
* The encoding to be used is passed through "encoding" parameter. the
* imported children scss node will have the same encoding as their
@@ -122,12 +125,22 @@ public class ScssStylesheet extends Node {
SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
ScssStylesheet stylesheet = handler.getStyleSheet();
-
- InputSource source = stylesheet.resolveStylesheet(identifier);
+ if (parentStylesheet == null) {
+ // Use default resolvers
+ stylesheet.addResolver(new FilesystemResolver());
+ stylesheet.addResolver(new ClassloaderResolver());
+ } else {
+ // Use parent resolvers
+ stylesheet.setResolvers(parentStylesheet.getResolvers());
+ }
+ InputSource source = stylesheet.resolveStylesheet(identifier,
+ parentStylesheet);
if (source == null) {
return null;
}
- source.setEncoding(encoding);
+ if (parentStylesheet != null) {
+ source.setEncoding(parentStylesheet.getCharset());
+ }
Parser parser = new Parser();
parser.setErrorHandler(new SCSSErrorHandler());
@@ -145,24 +158,13 @@ public class ScssStylesheet extends Node {
return stylesheet;
}
- private static ScssStylesheetResolver[] resolvers = null;
-
- public static void setStylesheetResolvers(
- ScssStylesheetResolver... styleSheetResolvers) {
- resolvers = Arrays.copyOf(styleSheetResolvers,
- styleSheetResolvers.length);
- }
-
- public InputSource resolveStylesheet(String identifier) {
- if (resolvers == null) {
- setStylesheetResolvers(new VaadinResolver());
- }
-
- for (ScssStylesheetResolver resolver : resolvers) {
- InputSource source = resolver.resolve(identifier);
+ public InputSource resolveStylesheet(String identifier,
+ ScssStylesheet parentStylesheet) {
+ for (ScssStylesheetResolver resolver : getResolvers()) {
+ InputSource source = resolver.resolve(parentStylesheet, identifier);
if (source != null) {
File f = new File(source.getURI());
- setFileName(f.getParent());
+ setFile(f);
return source;
}
}
@@ -171,6 +173,38 @@ public class ScssStylesheet extends Node {
}
/**
+ * Retrieves a list of resolvers to use when resolving imports
+ *
+ * @since 7.2
+ * @return the resolvers used to resolving imports
+ */
+ public List<ScssStylesheetResolver> getResolvers() {
+ return Collections.unmodifiableList(resolvers);
+ }
+
+ /**
+ * Sets the list of resolvers to use when resolving imports
+ *
+ * @since 7.2
+ * @param resolvers
+ * the resolvers to set
+ */
+ public void setResolvers(List<ScssStylesheetResolver> resolvers) {
+ this.resolvers = new ArrayList<ScssStylesheetResolver>(resolvers);
+ }
+
+ /**
+ * Adds the given resolver to the resolver list
+ *
+ * @since 7.2
+ * @param resolver
+ * The resolver to add
+ */
+ public void addResolver(ScssStylesheetResolver resolver) {
+ resolvers.add(resolver);
+ }
+
+ /**
* Applies all the visitors and compiles SCSS into Css.
*
* @throws Exception
@@ -355,12 +389,28 @@ public class ScssStylesheet extends Node {
return mixinDefs.get(name);
}
- public void setFileName(String fileName) {
- this.fileName = fileName;
+ public void setFile(File file) {
+ this.file = file;
}
+ /**
+ * Returns the directory containing this style sheet
+ *
+ * @since 7.2
+ * @return The directory containing this style sheet
+ */
+ public String getDirectory() {
+ return file.getParent();
+ }
+
+ /**
+ * Returns the full file name for this style sheet
+ *
+ * @since 7.2
+ * @return The full file name for this style sheet
+ */
public String getFileName() {
- return fileName;
+ return file.getPath();
}
public static HashMap<Node, Node> getLastNodeAdded() {
diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
index d7662d35a8..d7662d35a8 100755..100644
--- a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
diff --git a/theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java b/theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java
new file mode 100644
index 0000000000..5de1f95264
--- /dev/null
+++ b/theme-compiler/src/com/vaadin/sass/internal/resolver/AbstractResolver.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * 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.vaadin.sass.internal.resolver;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import org.w3c.css.sac.InputSource;
+
+import com.vaadin.sass.internal.ScssStylesheet;
+
+/**
+ * Base class for resolvers. Implements functionality for locating paths which
+ * an import can be relative to and helpers for extracting path information from
+ * the identifier.
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public abstract class AbstractResolver implements ScssStylesheetResolver,
+ Serializable {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.sass.internal.resolver.ScssStylesheetResolver#resolve(java
+ * .lang.String)
+ */
+ @Override
+ public InputSource resolve(ScssStylesheet parentStylesheet,
+ String identifier) {
+ // Remove a possible ".scss" suffix
+ identifier = identifier.replaceFirst(".scss$", "");
+
+ List<String> potentialParentPaths = getPotentialParentPaths(
+ parentStylesheet, identifier);
+
+ // remove path from identifier as it has already been added to the
+ // parent path
+ if (identifier.contains("/")) {
+ identifier = identifier.substring(identifier.lastIndexOf("/") + 1);
+ }
+
+ for (String path : potentialParentPaths) {
+ InputSource source = normalizeAndResolve(path + "/" + identifier);
+
+ if (source != null) {
+ return source;
+ }
+
+ // Try to find partial import (_identifier.scss)
+ source = normalizeAndResolve(path + "/_" + identifier);
+
+ if (source != null) {
+ return source;
+ }
+
+ }
+
+ return normalizeAndResolve(identifier);
+ }
+
+ /**
+ * Retrieves the parent paths which should be used while resolving relative
+ * identifiers. By default uses the parent stylesheet location and a
+ * possible absolute path in the identifier.
+ *
+ * @param parentStylesheet
+ * The parent stylesheet or null if there is no parent
+ * @param identifier
+ * The identifier to be resolved
+ * @return a list of paths in which to look for the relative import
+ */
+ protected List<String> getPotentialParentPaths(
+ ScssStylesheet parentStylesheet, String identifier) {
+ List<String> potentialParents = new ArrayList<String>();
+ if (parentStylesheet != null) {
+ potentialParents.add(extractFullPath(
+ parentStylesheet.getDirectory(), identifier));
+ }
+
+ // Identifier can be a full path so extract the path part also as a
+ // potential parent
+ if (identifier.contains("/")) {
+ potentialParents.add(extractFullPath("", identifier));
+ }
+
+ return potentialParents;
+
+ }
+
+ /**
+ * Extracts the full path from the path combined with the identifier
+ *
+ * @param path
+ * The base path
+ * @param identifier
+ * The identifier which may contain a path part, separated by "/"
+ * from the real identifier
+ * @return a normalized version of the path where identifier does not
+ * contain any directory information
+ */
+ protected String extractFullPath(String path, String identifier) {
+ int lastSlashPosition = identifier.lastIndexOf("/");
+ if (lastSlashPosition == -1) {
+ return path;
+ }
+ String identifierPath = identifier.substring(0, lastSlashPosition);
+ if ("".equals(path)) {
+ return identifierPath;
+ } else {
+ return path + "/" + identifierPath;
+ }
+ }
+
+ /**
+ * Resolves the normalized version of the given identifier
+ *
+ * @param identifier
+ * The identifier to resolve
+ * @return An input source if the resolver found one or null otherwise
+ */
+ protected InputSource normalizeAndResolve(String identifier) {
+ String normalized = normalize(identifier);
+ return resolveNormalized(normalized);
+ }
+
+ /**
+ * Resolves the identifier after it has been normalized using
+ * {@link #normalize(String)}.
+ *
+ * @param identifier
+ * The normalized identifier
+ * @return an InputSource if the resolver found a source or null otherwise
+ */
+ protected abstract InputSource resolveNormalized(String identifier);
+
+ /**
+ * Normalizes "." and ".." from the path string where parent path segments
+ * can be removed. Preserve leading "..". Also ensure / is used instead of \
+ * in all places.
+ *
+ * @param path
+ * A relative or absolute file path
+ * @return The normalized path
+ */
+ protected String normalize(String path) {
+
+ // Ensure only "/" is used, also in Windows
+ path = path.replace(File.separatorChar, '/');
+
+ // Split into segments
+ String[] segments = path.split("/");
+ Stack<String> result = new Stack<String>();
+
+ // Replace '.' and '..' segments
+ for (int i = 0; i < segments.length; i++) {
+ if (segments[i].equals(".")) {
+ // Segments marked '.' are ignored
+
+ } else if (segments[i].equals("..") && !result.isEmpty()
+ && !result.lastElement().equals("..")) {
+ // If segment is ".." then remove the previous iff the previous
+ // element is not a ".." and the result stack is not empty
+ result.pop();
+ } else {
+ // Other segments are just added to the stack
+ result.push(segments[i]);
+ }
+ }
+
+ // Reconstruct path
+ StringBuilder pathBuilder = new StringBuilder();
+ for (int i = 0; i < result.size(); i++) {
+ if (i > 0) {
+ pathBuilder.append("/");
+ }
+ pathBuilder.append(result.get(i));
+ }
+ return pathBuilder.toString();
+ }
+
+}
diff --git a/theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java b/theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java
index 8711a0a3e9..755073bc4c 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/resolver/ClassloaderResolver.java
@@ -15,31 +15,19 @@
*/
package com.vaadin.sass.internal.resolver;
-import java.io.File;
import java.io.InputStream;
import org.w3c.css.sac.InputSource;
-public class ClassloaderResolver implements ScssStylesheetResolver {
+public class ClassloaderResolver extends AbstractResolver {
@Override
- public InputSource resolve(String identifier) {
- // identifier should not have .scss, fileName should
- String ext = ".scss";
- if (identifier.endsWith(".css")) {
- ext = ".css";
- }
+ public InputSource resolveNormalized(String identifier) {
String fileName = identifier;
- if (identifier.endsWith(ext)) {
- identifier = identifier.substring(0,
- identifier.length() - ext.length());
- } else {
- fileName = fileName + ext;
+ if (!fileName.endsWith(".css")) {
+ fileName += ".scss";
}
- // Ensure only "/" is used, also in Windows
- fileName = fileName.replace(File.separatorChar, '/');
-
// Filename should be a relative path starting with VAADIN/...
int vaadinIdx = fileName.lastIndexOf("VAADIN/");
if (vaadinIdx > -1) {
diff --git a/theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java b/theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java
index 9bb1969ab1..786d0875da 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/resolver/FilesystemResolver.java
@@ -18,24 +18,46 @@ package com.vaadin.sass.internal.resolver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
+import java.util.List;
import org.w3c.css.sac.InputSource;
-public class FilesystemResolver implements ScssStylesheetResolver {
+import com.vaadin.sass.internal.ScssStylesheet;
+public class FilesystemResolver extends AbstractResolver {
+
+ private String[] customPaths = null;
+
+ public FilesystemResolver(String... customPaths) {
+ this.customPaths = customPaths;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.sass.internal.resolver.AbstractResolver#getPotentialPaths(
+ * com.vaadin.sass.internal.ScssStylesheet, java.lang.String)
+ */
@Override
- public InputSource resolve(String identifier) {
- // identifier should not have .scss, fileName should
- String ext = ".scss";
- if (identifier.endsWith(".css")) {
- ext = ".css";
+ protected List<String> getPotentialParentPaths(
+ ScssStylesheet parentStyleSheet, String identifier) {
+ List<String> potentialPaths = super.getPotentialParentPaths(
+ parentStyleSheet, identifier);
+ if (customPaths != null) {
+ for (String path : customPaths) {
+ potentialPaths.add(extractFullPath(path, identifier));
+ }
}
+
+ return potentialPaths;
+ }
+
+ @Override
+ public InputSource resolveNormalized(String identifier) {
String fileName = identifier;
- if (identifier.endsWith(ext)) {
- identifier = identifier.substring(0,
- identifier.length() - ext.length());
- } else {
- fileName = fileName + ext;
+ if (!fileName.endsWith(".css")) {
+ fileName += ".scss";
}
try {
diff --git a/theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java b/theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java
index 45f10836a3..64b3d10d88 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/resolver/ScssStylesheetResolver.java
@@ -17,6 +17,8 @@ package com.vaadin.sass.internal.resolver;
import org.w3c.css.sac.InputSource;
+import com.vaadin.sass.internal.ScssStylesheet;
+
public interface ScssStylesheetResolver {
/**
* Called with the "identifier" of a stylesheet that the resolver should try
@@ -26,9 +28,12 @@ public interface ScssStylesheetResolver {
* stylesheet was found, e.g "runo.scss" might result in a URI like
* "VAADIN/themes/runo/runo.scss".
*
+ * @param parentStylesheet
+ * The parent style sheet
* @param identifier
* used fo find stylesheet
* @return InputSource for stylesheet (with URI set) or null if not found
*/
- public InputSource resolve(String identifier);
+ public InputSource resolve(ScssStylesheet parentStylesheet,
+ String identifier);
} \ No newline at end of file
diff --git a/theme-compiler/src/com/vaadin/sass/internal/resolver/VaadinResolver.java b/theme-compiler/src/com/vaadin/sass/internal/resolver/VaadinResolver.java
deleted file mode 100644
index fec16a54c8..0000000000
--- a/theme-compiler/src/com/vaadin/sass/internal/resolver/VaadinResolver.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2000-2013 Vaadin Ltd.
- *
- * 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.vaadin.sass.internal.resolver;
-
-import java.io.File;
-import java.util.Stack;
-
-import org.w3c.css.sac.InputSource;
-
-public class VaadinResolver implements ScssStylesheetResolver {
-
- @Override
- public InputSource resolve(String identifier) {
-
- // Remove extra "." and ".."
- identifier = normalize(identifier);
-
- InputSource source = null;
-
- // Can we find the scss from the file system?
- ScssStylesheetResolver resolver = new FilesystemResolver();
- source = resolver.resolve(identifier);
-
- if (source == null) {
- // How about the classpath?
- resolver = new ClassloaderResolver();
- source = resolver.resolve(identifier);
- }
-
- return source;
- }
-
- /**
- * Normalizes "." and ".." from the path string where parent path segments
- * can be removed. Preserve leading "..".
- *
- * @param path
- * A relative or absolute file path
- * @return The normalized path
- */
- private static String normalize(String path) {
-
- // Ensure only "/" is used, also in Windows
- path = path.replace(File.separatorChar, '/');
-
- // Split into segments
- String[] segments = path.split("/");
- Stack<String> result = new Stack<String>();
-
- // Replace '.' and '..' segments
- for (int i = 0; i < segments.length; i++) {
- if (segments[i].equals(".")) {
- // Segments marked '.' are ignored
-
- } else if (segments[i].equals("..") && !result.isEmpty()
- && !result.lastElement().equals("..")) {
- // If segment is ".." then remove the previous iff the previous
- // element is not a ".." and the result stack is not empty
- result.pop();
- } else {
- // Other segments are just added to the stack
- result.push(segments[i]);
- }
- }
-
- // Reconstruct path
- StringBuilder pathBuilder = new StringBuilder();
- for (int i = 0; i < result.size(); i++) {
- if (i > 0) {
- pathBuilder.append("/");
- }
- pathBuilder.append(result.get(i));
- }
- return pathBuilder.toString();
- }
-
-}
diff --git a/theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java b/theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java
index cb9896967a..e52767bb5a 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/visitor/ImportNodeHandler.java
@@ -16,7 +16,6 @@
package com.vaadin.sass.internal.visitor;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
@@ -57,25 +56,14 @@ public class ImportNodeHandler {
ImportNode importNode = (ImportNode) n;
if (!importNode.isPureCssImport()) {
try {
- StringBuilder filePathBuilder = new StringBuilder(
- styleSheet.getFileName());
- filePathBuilder.append(File.separatorChar).append(
- importNode.getUri());
- if (!filePathBuilder.toString().endsWith(".scss")) {
- filePathBuilder.append(".scss");
- }
-
// set parent's charset to imported node.
ScssStylesheet imported = ScssStylesheet.get(
- filePathBuilder.toString(),
- styleSheet.getCharset());
- if (imported == null) {
- imported = ScssStylesheet.get(importNode.getUri());
- }
+ importNode.getUri(), styleSheet);
if (imported == null) {
- throw new FileNotFoundException(importNode.getUri()
- + " (parent: "
- + ScssStylesheet.get().getFileName() + ")");
+ throw new FileNotFoundException("Import '"
+ + importNode.getUri() + "' in '"
+ + styleSheet.getFileName()
+ + "' could not be found");
}
traverse(imported);
diff --git a/theme-compiler/tests/resources/css/compass-import.css b/theme-compiler/tests/resources/css/compass-import.css
new file mode 100644
index 0000000000..e3d4b5fcca
--- /dev/null
+++ b/theme-compiler/tests/resources/css/compass-import.css
@@ -0,0 +1,49 @@
+.content-navigation {
+ border-color: #3bbfce;
+ color: #0000ff;
+}
+
+.border {
+ padding: 8px;
+ margin: 8px;
+ border-color: #3bbfce;
+}
+
+.body {
+ background-image: url(compass/folder-test2/bg.png);
+ background: transparent url(compass/folder-test2/img/loading-indicator.gif);
+ background-image: url(http://abc/bg.png);
+ background-image: url(/abc/bg.png);
+}
+
+.base {
+ color: red;
+}
+
+.text {
+ font-weight: bold;
+}
+
+.footer {
+ border: 2px solid black;
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+}
+
+.banner {
+ border: 1px solid black;
+ font-color: red;
+}
+
+.interpolation-test {
+ font-size: 14px;
+}
+
+.header {
+ width: 100%;
+}
+
+.badError {
+ border-width: 3px;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test/compass-import.scss b/theme-compiler/tests/resources/scss/compass-test/compass-import.scss
new file mode 100644
index 0000000000..36d041b33c
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test/compass-import.scss
@@ -0,0 +1,4 @@
+@import "compass";
+.badError {
+ border-width: 3px;
+}
diff --git a/theme-compiler/tests/resources/scss/compass-test2/_compass.scss b/theme-compiler/tests/resources/scss/compass-test2/_compass.scss
new file mode 100644
index 0000000000..9b741c0f03
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/_compass.scss
@@ -0,0 +1,3 @@
+@import "compass/utilities";
+@import "compass/typography";
+@import "compass/css3";
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass-import2.scss b/theme-compiler/tests/resources/scss/compass-test2/compass-import2.scss
new file mode 100644
index 0000000000..36d041b33c
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass-import2.scss
@@ -0,0 +1,4 @@
+@import "compass";
+.badError {
+ border-width: 3px;
+}
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/_css3.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/_css3.scss
new file mode 100644
index 0000000000..42163ba193
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/_css3.scss
@@ -0,0 +1,3 @@
+@import "css3/border-radius";
+@import "css3/inline-block";
+@import "css3/opacity";
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/_typography.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/_typography.scss
new file mode 100644
index 0000000000..a65c1ff292
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/_typography.scss
@@ -0,0 +1,3 @@
+@import "typography/links";
+@import "typography/lists";
+@import "typography/text";
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/_utilities.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/_utilities.scss
new file mode 100644
index 0000000000..644ad3368b
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/_utilities.scss
@@ -0,0 +1,3 @@
+@import "utilities/color";
+@import "utilities/general";
+@import "utilities/sprites";
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_border-radius.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_border-radius.scss
new file mode 100644
index 0000000000..752003104b
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_border-radius.scss
@@ -0,0 +1,4 @@
+.banner {
+ border: 1px solid black;
+ font-color: red;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_inline-block.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_inline-block.scss
new file mode 100644
index 0000000000..3fefab83b2
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_inline-block.scss
@@ -0,0 +1,3 @@
+.interpolation-test {
+ font-size: 14px;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_opacity.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_opacity.scss
new file mode 100644
index 0000000000..f6bf34fe24
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/css3/_opacity.scss
@@ -0,0 +1,3 @@
+.header {
+ width: 100%;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_links.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_links.scss
new file mode 100644
index 0000000000..bc7318558e
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_links.scss
@@ -0,0 +1,3 @@
+.base {
+ color: red;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_lists.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_lists.scss
new file mode 100644
index 0000000000..af174b7095
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_lists.scss
@@ -0,0 +1,3 @@
+.text {
+ font-weight: bold;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_text.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_text.scss
new file mode 100644
index 0000000000..8239527f7b
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/typography/_text.scss
@@ -0,0 +1,6 @@
+.footer {
+ border: 2px solid black;
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_color.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_color.scss
new file mode 100644
index 0000000000..ea1b7a55f0
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_color.scss
@@ -0,0 +1,4 @@
+.content-navigation {
+ border-color: #3bbfce;
+ color: #0000ff;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_general.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_general.scss
new file mode 100644
index 0000000000..0c58c6433d
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_general.scss
@@ -0,0 +1,5 @@
+.border {
+ padding: 8px;
+ margin: 8px;
+ border-color: #3bbfce;
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_sprites.scss b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_sprites.scss
new file mode 100644
index 0000000000..28960f89fc
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/compass/utilities/_sprites.scss
@@ -0,0 +1,6 @@
+.body {
+ background-image: url(../folder-test2/bg.png);
+ background: transparent url(../folder-test2/img/loading-indicator.gif);
+ background-image: url(http://abc/bg.png);
+ background-image: url(/abc/bg.png);
+} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/compass-test2/license-readme.txt b/theme-compiler/tests/resources/scss/compass-test2/license-readme.txt
new file mode 100644
index 0000000000..90ba808179
--- /dev/null
+++ b/theme-compiler/tests/resources/scss/compass-test2/license-readme.txt
@@ -0,0 +1,26 @@
+The design here is to use the stylesheets located at:
+https://github com/chriseppstein/compass/tree/stable/frameworks/compass/stylesheets
+
+and update the VAADIN code to be able to read them in such that an existing JRuby implementation can be replaced with VAADIN without any changes to one's *.scss and *.css files.
+
+The current short snippets of SCSS that are included here only for testing Compass compatibility might not qualify as significant or substantial parts, but in any case Compass is being mentioned for related tests pointing to the original implementation. These small portions of Compass are copied and modified for the testing of compatibility only.
+
+The license for Compass mentioned here:
+https://github.com/chriseppstein/compass/blob/stable/LICENSE.markdown
+
+is as follows:
+
+
+
+
+Copyright (c) 2009 Christopher M. Eppstein
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. No attribution is required by products that make use of this software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
+
+Contributors to this project agree to grant all rights to the copyright holder of the primary product. Attribution is maintained in the source control history of the product.
diff --git a/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java b/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java
index 59b49888c2..0183142747 100644
--- a/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java
+++ b/theme-compiler/tests/src/com/vaadin/sass/resolvers/VaadinResolverTest.java
@@ -40,16 +40,26 @@ import java.lang.reflect.Method;
import org.junit.Assert;
import org.junit.Test;
-import com.vaadin.sass.internal.resolver.VaadinResolver;
+import com.vaadin.sass.internal.resolver.AbstractResolver;
+import com.vaadin.sass.internal.resolver.ClassloaderResolver;
+import com.vaadin.sass.internal.resolver.FilesystemResolver;
public class VaadinResolverTest {
@Test
- public void testPathNormalization() throws Exception {
+ public void testFilesystemResolverPathNormalization() throws Exception {
+ testPathNormalization(new FilesystemResolver());
+ }
+
+ @Test
+ public void testClassloaderResolverPathNormalization() throws Exception {
+ testPathNormalization(new ClassloaderResolver());
+ }
- VaadinResolver resolver = new VaadinResolver();
+ public void testPathNormalization(AbstractResolver resolver)
+ throws Exception {
- Method normalizeMethod = VaadinResolver.class.getDeclaredMethod(
+ Method normalizeMethod = AbstractResolver.class.getDeclaredMethod(
"normalize", String.class);
normalizeMethod.setAccessible(true);
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/CompassImports.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/CompassImports.java
new file mode 100644
index 0000000000..1e3eb09f0c
--- /dev/null
+++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/CompassImports.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * 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.vaadin.sass.testcases.scss;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.w3c.css.sac.CSSException;
+
+import com.vaadin.sass.AbstractTestBase;
+import com.vaadin.sass.internal.ScssStylesheet;
+import com.vaadin.sass.internal.handler.SCSSDocumentHandler;
+import com.vaadin.sass.internal.handler.SCSSDocumentHandlerImpl;
+import com.vaadin.sass.internal.parser.Parser;
+import com.vaadin.sass.internal.resolver.FilesystemResolver;
+import com.vaadin.sass.internal.tree.ImportNode;
+
+public class CompassImports extends AbstractTestBase {
+
+ String scssOtherDirectory = "/scss/compass-test/compass-import.scss";
+ String scssSameDirectory = "/scss/compass-test2/compass-import2.scss";
+ String css = "/css/compass-import.css";
+
+ String compassPath = "/scss/compass-test2";
+
+ @Test
+ public void testParser() throws CSSException, IOException {
+ Parser parser = new Parser();
+ SCSSDocumentHandler handler = new SCSSDocumentHandlerImpl();
+ parser.setDocumentHandler(handler);
+ parser.parseStyleSheet(getClass().getResource(scssOtherDirectory)
+ .getPath());
+ ScssStylesheet root = handler.getStyleSheet();
+ ImportNode importVariableNode = (ImportNode) root.getChildren().get(0);
+ Assert.assertEquals("compass", importVariableNode.getUri());
+ Assert.assertFalse(importVariableNode.isPureCssImport());
+ }
+
+ @Test
+ public void testCompiler() throws Exception {
+ testCompiler(scssSameDirectory, css, null);
+ }
+
+ @Test
+ public void testCompilerWithCustomPath() throws Exception {
+ File rootPath = new File(getClass().getResource(compassPath).toURI());
+
+ testCompiler(scssOtherDirectory, css, rootPath.getPath());
+ }
+
+ public void testCompiler(String scss, String css, String additionalPath)
+ throws Exception {
+ comparisonCss = getFileContent(css);
+ ScssStylesheet sheet = getStyleSheet(scss);
+ Assert.assertNotNull(sheet);
+ sheet.addResolver(new FilesystemResolver(additionalPath));
+
+ sheet.compile();
+ parsedScss = sheet.toString();
+ Assert.assertEquals("Original CSS and parsed CSS do not match",
+ comparisonCss, parsedScss);
+ }
+}