diff options
-rw-r--r-- | theme-compiler/src/com/vaadin/sass/resolver/VaadinResolver.java | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/resolver/VaadinResolver.java b/theme-compiler/src/com/vaadin/sass/resolver/VaadinResolver.java index 93fdf6bfec..1caf5dcac8 100644 --- a/theme-compiler/src/com/vaadin/sass/resolver/VaadinResolver.java +++ b/theme-compiler/src/com/vaadin/sass/resolver/VaadinResolver.java @@ -1,46 +1,49 @@ package com.vaadin.sass.resolver; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.w3c.css.sac.InputSource; public class VaadinResolver implements ScssStylesheetResolver { @Override public InputSource resolve(String identifier) { - String ext = ".scss"; if (identifier.endsWith(".css")) { - ext = ".css"; + // CSS support mainly for testing, don't load from classpath etc + ScssStylesheetResolver resolver = new FilesystemResolver(); + return resolver.resolve(identifier); } - // 'normalize' identifier to use in themeFile - String fileName = identifier; - if (identifier.endsWith(ext)) { - identifier = identifier.substring(0, - identifier.length() - ext.length()); - } - // also look here - String themeFile = "VAADIN/themes/" + identifier + "/" + fileName; + InputSource source = null; - // first plain file - ScssStylesheetResolver resolver = new FilesystemResolver(); - InputSource source = resolver.resolve(fileName); + Pattern pattern = Pattern + .compile("\\.\\.\\/([^\\/]+)\\/([^\\/]+\\.scss)"); + Matcher matcher = pattern.matcher(identifier); - if (source == null) { - // then file in theme - source = resolver.resolve(themeFile); - } + if (matcher.find()) { + // theme include + ScssStylesheetResolver resolver = new FilesystemResolver(); + source = resolver.resolve(identifier); - if (source == null) { - // then plain via classloader - resolver = new ClassloaderResolver(); + if (source == null) { + String themeName = matcher.group(1); + String fileName = matcher.group(2); + resolver = new ClassloaderResolver(); + String id = "VAADIN/themes/" + themeName + "/" + fileName; + source = resolver.resolve(id); + } + + } else { + ScssStylesheetResolver resolver = new FilesystemResolver(); source = resolver.resolve(identifier); - } - if (source == null) { - // then try theme via classloader - source = resolver.resolve(themeFile); + if (source == null) { + resolver = new ClassloaderResolver(); + source = resolver.resolve(identifier); + } } return source; } - } |