Search in sources :

Example 11 with CSSReaderSettings

use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.

the class Issue19Test method testIssue.

@Test
public void testIssue() {
    // Multiple errors contained
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue19.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, new CSSReaderSettings().setFallbackCharset(StandardCharsets.UTF_8).setCSSVersion(ECSSVersion.CSS30).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setBrowserCompliantMode(true));
    assertNotNull(aCSS);
    if (false)
        System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
    assertEquals(1, aCSS.getRuleCount());
    assertEquals(1, aCSS.getStyleRuleCount());
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Example 12 with CSSReaderSettings

use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.

the class Issue34Test method testIssue.

@Test
@Ignore("TODO")
public void testIssue() {
    final String css = ".pen {background-color:red} {* some incorrect block *} .pen {background-color: blue}";
    final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setCustomErrorHandler(new LoggingCSSParseErrorHandler()).setCustomExceptionHandler(new LoggingCSSParseExceptionCallback());
    final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
    assertNotNull(cascadingStyleSheet);
    final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
    s_aLogger.info(writer.getCSSAsString(cascadingStyleSheet));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) LoggingCSSParseExceptionCallback(com.helger.css.handler.LoggingCSSParseExceptionCallback) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with CSSReaderSettings

use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.

the class Issue36Test method testIssue.

@Test
public void testIssue() {
    final String css = "@media screen and (min-width: 768px) {.section {.\r\n" + "    padding: 40px\r\n" + "}\r\n" + "\r\n" + "}";
    final CSSReaderSettings aSettings = new CSSReaderSettings().setCSSVersion(ECSSVersion.LATEST).setBrowserCompliantMode(true).setCustomErrorHandler(new DoNothingCSSParseErrorHandler());
    final CascadingStyleSheet cascadingStyleSheet = CSSReader.readFromStringStream(css, aSettings);
    final CSSWriter writer = new CSSWriter(new CSSWriterSettings(ECSSVersion.LATEST, true));
    assertEquals("@media screen and (min-width:768px){.section{}}", writer.getCSSAsString(cascadingStyleSheet));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) DoNothingCSSParseErrorHandler(com.helger.css.reader.errorhandler.DoNothingCSSParseErrorHandler) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) Test(org.junit.Test)

Example 14 with CSSReaderSettings

use of com.helger.css.reader.CSSReaderSettings in project ph-css by phax.

the class Issue24Test method testIssue.

@Test
public void testIssue() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/bad_but_browsercompliant/issue24.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));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSWriter(com.helger.css.writer.CSSWriter) CSSReaderSettings(com.helger.css.reader.CSSReaderSettings) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Aggregations

CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)14 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)14 Test (org.junit.Test)12 CSSWriter (com.helger.css.writer.CSSWriter)11 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)9 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)6 IReadableResource (com.helger.commons.io.resource.IReadableResource)6 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)6 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 DoNothingCSSInterpretErrorHandler (com.helger.css.reader.errorhandler.DoNothingCSSInterpretErrorHandler)2 File (java.io.File)2 Charset (java.nio.charset.Charset)2 FileSystemRecursiveIterator (com.helger.commons.io.file.FileSystemRecursiveIterator)1 CSSDeclaration (com.helger.css.decl.CSSDeclaration)1 CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)1 CSSImportRule (com.helger.css.decl.CSSImportRule)1 ICSSTopLevelRule (com.helger.css.decl.ICSSTopLevelRule)1 DefaultCSSUrlVisitor (com.helger.css.decl.visit.DefaultCSSUrlVisitor)1 ICSSParseExceptionCallback (com.helger.css.handler.ICSSParseExceptionCallback)1 LoggingCSSParseExceptionCallback (com.helger.css.handler.LoggingCSSParseExceptionCallback)1