use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue38Test method testIssue.
@Test
public void testIssue() {
final String css = "h1:lang(or) { line-height: 1.2em; }";
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true);
final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
assertEquals("h1:lang(or){line-height:1.2em}", writer.getCSSAsString(cascadingStyleSheet));
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue22Test method testIssue.
@Test
public void testIssue() {
// Multiple errors contained
final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue22.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class Issue26Test method testIssue.
@Test
public void testIssue() {
final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue26.css");
assertTrue(aRes.exists());
final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setBrowserCompliantMode(true).setCustomErrorHandler(new LoggingCSSParseErrorHandler()));
assertNotNull(aCSS);
if (false)
System.out.println(new CSSWriter().getCSSAsString(aCSS));
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class CSSCompressMojo method _compressCSSFile.
private void _compressCSSFile(@Nonnull final File aChild) {
// Compress the file only if the compressed file is older than the original
// file. Note: lastModified on a non-existing file returns 0L
final File aCompressed = new File(FilenameHelper.getWithoutExtension(aChild.getAbsolutePath()) + targetFileExtension);
if (aCompressed.lastModified() < aChild.lastModified() || forceCompress) {
if (verbose)
getLog().info("Start compressing CSS file " + _getRelativePath(aChild));
else
getLog().debug("Start compressing CSS file " + _getRelativePath(aChild));
final ICSSParseExceptionCallback aExHdl = (@Nonnull final ParseException ex) -> getLog().error("Failed to parse CSS file " + _getRelativePath(aChild), ex);
final Charset aFallbackCharset = CharsetHelper.getCharsetFromName(sourceEncoding);
final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.CSS30).setFallbackCharset(aFallbackCharset).setCustomExceptionHandler(aExHdl).setBrowserCompliantMode(browserCompliantMode);
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aChild, aSettings);
if (aCSS != null) {
// We read it!
final FileSystemResource aDestFile = new FileSystemResource(aCompressed);
try {
final CSSWriterSettings aWriterSettings = new CSSWriterSettings(ECSSVersion.CSS30);
aWriterSettings.setOptimizedOutput(true);
aWriterSettings.setRemoveUnnecessaryCode(removeUnnecessaryCode);
aWriterSettings.setNewLineMode(newLineMode);
aWriterSettings.setQuoteURLs(quoteURLs);
aWriterSettings.setWriteNamespaceRules(writeNamespaceRules);
aWriterSettings.setWriteFontFaceRules(writeFontFaceRules);
aWriterSettings.setWriteKeyframesRules(writeKeyframesRules);
aWriterSettings.setWriteMediaRules(writeMediaRules);
aWriterSettings.setWritePageRules(writePageRules);
aWriterSettings.setWriteViewportRules(writeViewportRules);
aWriterSettings.setWriteSupportsRules(writeSupportsRules);
aWriterSettings.setWriteUnknownRules(writeUnknownRules);
final Charset aTargetCharset = CharsetHelper.getCharsetFromName(targetEncoding);
new CSSWriter(aWriterSettings).writeCSS(aCSS, aDestFile.getWriter(aTargetCharset, EAppend.TRUNCATE));
} catch (final IOException ex) {
getLog().error("Failed to write compressed CSS file '" + aCompressed.toString() + "' to disk", ex);
}
}
} else {
if (verbose)
getLog().info("Ignoring already compressed CSS file " + _getRelativePath(aChild));
else
getLog().debug("Ignoring already compressed CSS file " + _getRelativePath(aChild));
}
}
use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.
the class CSSVisitor30FuncTest method testVisitContent30.
@Test
public void testVisitContent30() {
for (final File aFile : new FileSystemRecursiveIterator(new File("src/test/resources/testfiles/css30/good")).withFilter(IFileFilter.filenameEndsWith(".css"))) {
final String sKey = aFile.getAbsolutePath();
if (true)
s_aLogger.info(sKey);
final CascadingStyleSheet aCSS = CSSReader.readFromFile(aFile, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
assertNotNull(sKey, aCSS);
CSSVisitor.visitCSSUrl(aCSS, new MockUrlVisitor(sKey));
}
}
Aggregations