diff options
author | Henri Sara <hesara@vaadin.com> | 2012-08-08 14:27:31 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-08-08 14:44:49 +0300 |
commit | cfa455d6cfd4a535fd77cbc76637a57e7024e9ac (patch) | |
tree | cecb66492671ed20fa9865581da12930ed502047 /build | |
parent | 620e096b45f27ecc5aa85d164ca8b81df000e593 (diff) | |
download | vaadin-framework-cfa455d6cfd4a535fd77cbc76637a57e7024e9ac.tar.gz vaadin-framework-cfa455d6cfd4a535fd77cbc76637a57e7024e9ac.zip |
Standard themes in SCSS form, updated CompileDefaultTheme (#9223)
Conversion performed for most themes trivial, just rename file and wrap
in a mixin. For chameleon compounds, also nesting used. In some cases,
related small files combined in a single SCSS file
Chameleon accordion and select contain fixes other than just a missing
semicolon.
Diffstat (limited to 'build')
-rw-r--r-- | build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java | 206 |
1 files changed, 56 insertions, 150 deletions
diff --git a/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java index 0f7ec4a14b..a23e5e912e 100644 --- a/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java +++ b/build/buildhelpers/com/vaadin/buildhelpers/CompileDefaultTheme.java @@ -1,21 +1,16 @@ package com.vaadin.buildhelpers; -import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.DataInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Arrays; -import java.util.Comparator; + +import com.vaadin.sass.ScssStylesheet; /** - * Helper to combine css divded into separate per component dirs into one to + * Helper to combine css divided into separate per component dirs into one to * optimize http requests. - * */ public class CompileDefaultTheme { @@ -42,79 +37,83 @@ public class CompileDefaultTheme { break; } } + + for (String themeName : new String[] { BASE, RUNO, LIFERAY, CHAMELEON }) { + try { + processSassTheme(themeName, false, ver); + System.out.println("Compiling theme " + themeName + + " successful"); + } catch (Exception e) { + System.err.println("Compiling theme " + themeName + " failed"); + e.printStackTrace(); + } + } + // Compile Reindeer last, since it requires the spriting operation // (makes testing the other themes a bit faster, since you don't need to // wait for the spriting operation to finish before the theme CSS is // compiled) - combineTheme(new String[] { BASE }, false, ver); - combineTheme(new String[] { BASE, RUNO }, false, ver); - combineTheme(new String[] { BASE, LIFERAY }, false, ver); - combineTheme(new String[] { BASE, CHAMELEON }, false, ver); - combineTheme(new String[] { BASE, REINDEER }, true, ver); + for (String themeName : new String[] { REINDEER }) { + try { + processSassTheme(themeName, true, ver); + System.out.println("Compiling theme " + themeName + + " successful"); + } catch (Exception e) { + System.err.println("Compiling theme " + themeName + " failed"); + e.printStackTrace(); + } + } } - /** - * - * @param themeNames - * All themes that should be combined together (to include - * inheritance). The order is the same in which the styles are - * catenated. The resulted file is placed in the last specified - * theme folder. - * - * @param - * @throws IOException - */ - private static void combineTheme(String[] themeNames, - boolean useSmartSprites, String version) throws IOException { + private static void processSassTheme(String themeName, + boolean useSmartSprites, String version) throws Exception { - StringBuffer combinedCss = new StringBuffer(); + StringBuffer cssHeader = new StringBuffer(); // Theme version if (version == null) { version = "9.9.9.INTERNAL-DEBUG-BUILD"; } version = version.replaceAll("\\.", "_"); - combinedCss.append(".v-theme-version:after {content:\"" + version + cssHeader.append(".v-theme-version:after {content:\"" + version + "\";}\n"); - combinedCss.append(".v-theme-version-" + version - + " {display: none;}\n"); - - for (int j = 0; j < themeNames.length; j++) { - File f = new File(THEME_DIR + themeNames[j]); - combinedCss - .append("/* Automatically compiled css file from subdirectories. */\n"); - - File[] subdir = f.listFiles(); - Arrays.sort(subdir, new Comparator<File>() { - public int compare(File arg0, File arg1) { - return arg0.compareTo(arg1); - } - }); + cssHeader.append(".v-theme-version-" + version + " {display: none;}\n"); - for (int i = 0; i < subdir.length; i++) { - File dir = subdir[i]; - String folder = dir.getName(); - String filename = dir.getPath() + "/" + folder + ".css"; - - processCSSFile(new File(filename), folder, themeNames[j], - combinedCss, j < themeNames.length - 1); - } + // TODO temporary hack for Reindeer + if (useSmartSprites) { + // TODO removed "../" from paths here + cssHeader + .append("/** sprite: verticals; sprite-image: url(common/img/vertical-sprites.png); sprite-layout: vertical */\n"); + cssHeader + .append("/** sprite: horizontals; sprite-image: url(common/img/horizontal-sprites.png); sprite-layout: horizontal */\n"); + cssHeader + .append("/** sprite: black-verticals; sprite-image: url(common/img/black-vertical-sprites.png); sprite-layout: vertical; sprite-matte-color: #1e2022 */\n"); + cssHeader + .append("/** sprite: black-horizontals; sprite-image: url(common/img/black-horizontal-sprites.png); sprite-layout: horizontal; sprite-matte-color: #1e2022 */\n"); + cssHeader + .append("/** sprite: buttons; sprite-image: url(button/img/button-sprites.png); sprite-layout: vertical */\n"); + cssHeader + .append("/** sprite: black-buttons; sprite-image: url(button/img/black-button-sprites.png); sprite-layout: vertical */\n"); } - String stylesCssDir = THEME_DIR + themeNames[themeNames.length - 1] - + "/"; + String stylesCssDir = THEME_DIR + themeName + "/"; String stylesCssName = stylesCssDir + "styles.css"; + // Process as SASS file + File inputFile = new File(stylesCssDir + "styles.scss"); + ScssStylesheet scss = ScssStylesheet.get(inputFile); + scss.compile(); + BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName)); - out.write(combinedCss.toString()); + out.write(cssHeader.toString()); + out.write(scss.toString()); out.close(); - System.out.println("Compiled CSS to " + THEME_DIR - + themeNames[themeNames.length - 1] + "/styles.css (" - + combinedCss.toString().length() + " bytes)"); + System.out.println("Compiled CSS to " + stylesCssName + " (" + + scss.toString().length() + " bytes)"); if (useSmartSprites) { - createSprites(themeNames[themeNames.length - 1]); + createSprites(themeName); System.out.println("Used SmartSprites to create sprites"); File oldCss = new File(stylesCssName); oldCss.delete(); @@ -128,99 +127,6 @@ public class CompileDefaultTheme { } } - private static void processCSSFile(File cssFile, String folder, - String themeName, StringBuffer combinedCss, boolean inheritedFile) - throws FileNotFoundException, IOException { - if (cssFile.isFile()) { - - combinedCss.append("\n"); - - FileInputStream fstream = new FileInputStream(cssFile); - // Get the object of DataInputStream - DataInputStream in = new DataInputStream(fstream); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - String strLine; - while ((strLine = br.readLine()) != null) { - - // Parse import rules - if (strLine.startsWith("@import")) { - // All import statements must be exactly - // @import "file-to-import.css"; - // or - // @import "subdir1[/subdir2]*/file-to-import.css" - // ".." and other similar paths are not allowed in the url - String importFilename = strLine.split("\"")[1]; - - File importFile = new File(THEME_DIR + themeName + "/" - + folder + "/" + importFilename); - if (importFile.isFile()) { - String currentFolder = folder; - if (importFilename.contains("/")) { - currentFolder = currentFolder - + "/" - + importFilename.substring(0, - importFilename.lastIndexOf("/")); - } - processCSSFile(importFile, currentFolder, themeName, - combinedCss, inheritedFile); - } else { - System.out - .println("File not found for @import statement " - + THEME_DIR - + themeName - + "/" - + folder - + "/" + importFilename); - } - } - - strLine = updateUrls(folder, themeName, inheritedFile, strLine); - - if (!strLine.startsWith("@import")) { - combinedCss.append(strLine); - combinedCss.append("\n"); - } - } - // Close the input stream - in.close(); - } - } - - private static String updateUrls(String folder, String themeName, - boolean inheritedFile, String strLine) { - // Define image url prefix - String urlPrefix = ""; - if (inheritedFile) { - urlPrefix = "../" + themeName + "/"; - } - - if (strLine.indexOf("url(/") > 0) { - // Do nothing for urls beginning with / - } else if (strLine.indexOf("url(../") >= 0) { - // eliminate a path segment in the folder name for every - // "../" - String[] folderSegments = folder.split("/"); - int segmentCount = folderSegments.length; - while (segmentCount > 0 && strLine.indexOf("url(../") >= 0) { - segmentCount--; - strLine = strLine.replaceAll("url\\(../", ("url\\(")); - } - // add remaining path segments to urlPrefix - StringBuilder sb = new StringBuilder(urlPrefix); - for (int i = 0; i < segmentCount; i++) { - sb.append(folderSegments[i]); - sb.append("/"); - } - strLine = strLine.replaceAll("url\\(", ("url\\(" + sb.toString())); - - } else { - strLine = strLine.replaceAll("url\\(", ("url\\(" + urlPrefix - + folder + "/")); - - } - return strLine; - } - private static void createSprites(String themeName) throws FileNotFoundException, IOException { String[] parameters = new String[] { "--sprite-png-depth", "AUTO", |