Search in sources :

Example 61 with CascadingStyleSheet

use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.

the class CSSWriterTest method testIndentationNested.

@Test
public void testIndentationNested() {
    final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS4, ECSSVersion.CSS30);
    assertNotNull(aCSS);
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);
    final CSSWriter aWriter = new CSSWriter(aSettings).setWriteHeaderText(false);
    assertEquals("@media print {\n" + "  h1 {\n" + "    color:red;\n" + "    margin:1px;\n" + "  }\n" + "\n" + "  h2 { color:rgb(1,2,3); }\n" + "\n" + "  h3 {}\n" + "\n" + "  @keyframes x {\n" + "    from {\n" + "      align:left;\n" + "      color:#123;\n" + "    }\n" + "    to { x:y; }\n" + "    50% {}\n" + "  }\n" + "\n" + "  @page {\n" + "    margin:1in;\n" + "    marks:none;\n" + "  }\n" + "\n" + "  @page :first { margin:2in; }\n" + "\n" + "  @font-face {\n" + "    font-family:'Soho';\n" + "    src:url(Soho.eot);\n" + "  }\n" + "\n" + "  @font-face { src:local('Soho Gothic Pro'); }\n" + "\n" + "  @font-face {}\n" + "}\n", aWriter.getCSSAsString(aCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) Test(org.junit.Test)

Example 62 with CascadingStyleSheet

use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.

the class CSSWriterTest method testHeaderText.

@Test
public void testHeaderText() {
    final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS5, ECSSVersion.CSS30);
    assertNotNull(aCSS);
    // Non-optimized version
    CSSWriter aWriter = new CSSWriter(ECSSVersion.CSS30, false).setWriteHeaderText(true).setHeaderText("Unit test");
    assertEquals("/*\n" + " * Unit test\n" + " */\n" + "h1 {\n" + "  color:red;\n" + "  margin:1px;\n" + "}\n" + "\n" + "h2 {\n" + "  color:red;\n" + "  margin:1px;\n" + "}\n", aWriter.getCSSAsString(aCSS));
    // Optimized version
    aWriter = new CSSWriter(ECSSVersion.CSS30, true).setWriteHeaderText(true).setHeaderText("Unit test2");
    assertEquals("/*\n" + " * Unit test2\n" + " */\n" + "h1{color:red;margin:1px}h2{color:red;margin:1px}", aWriter.getCSSAsString(aCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) Test(org.junit.Test)

Example 63 with CascadingStyleSheet

use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.

the class CSSWriterTest method testRemoveUnnecessaryCode2.

@Test
public void testRemoveUnnecessaryCode2() {
    final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS4, ECSSVersion.CSS30);
    assertNotNull(aCSS);
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false).setRemoveUnnecessaryCode(true);
    final CSSWriter aWriter = new CSSWriter(aSettings).setWriteHeaderText(false);
    assertEquals("@media print {\n" + "  h1 {\n" + "    color:red;\n" + "    margin:1px;\n" + "  }\n" + "\n" + "  h2 { color:rgb(1,2,3); }\n" + "\n" + "  @keyframes x {\n" + "    from {\n" + "      align:left;\n" + "      color:#123;\n" + "    }\n" + "    to { x:y; }\n" + "  }\n" + "\n" + "  @page {\n" + "    margin:1in;\n" + "    marks:none;\n" + "  }\n" + "\n" + "  @page :first { margin:2in; }\n" + "\n" + "  @font-face {\n" + "    font-family:'Soho';\n" + "    src:url(Soho.eot);\n" + "  }\n" + "\n" + "  @font-face { src:local('Soho Gothic Pro'); }\n" + "}\n", aWriter.getCSSAsString(aCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) Test(org.junit.Test)

Example 64 with CascadingStyleSheet

use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.

the class CSSWriterTest method testIndentation.

@Test
public void testIndentation() {
    final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS3, ECSSVersion.CSS30);
    assertNotNull(aCSS);
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);
    final CSSWriter aWriter = new CSSWriter(aSettings).setWriteHeaderText(false);
    assertEquals("h1 {\n" + "  color:red;\n" + "  margin:1px;\n" + "}\n" + "\n" + "h2 { color:rgb(1,2,3); }\n" + "\n" + "h3 {}\n" + "\n" + "@keyframes x {\n" + "  from {\n" + "    align:left;\n" + "    color:#123;\n" + "  }\n" + "  to { x:y; }\n" + "  50% {}\n" + "}\n" + "\n" + "@page {\n" + "  margin:1in;\n" + "  marks:none;\n" + "}\n" + "\n" + "@page :first { margin:2in; }\n" + "\n" + "@page :last {}\n" + "\n" + "@media print {\n" + "  div {\n" + "    width:100%;\n" + "    min-height:0;\n" + "  }\n" + "}\n" + "\n" + "@media all {\n" + "  div { width:90%; }\n" + "}\n" + "\n" + "@media tv {}\n" + "\n" + "@font-face {\n" + "  font-family:'Soho';\n" + "  src:url(Soho.eot);\n" + "}\n" + "\n" + "@font-face { src:local('Soho Gothic Pro'); }\n" + "\n" + "@font-face {}\n", aWriter.getCSSAsString(aCSS));
    // Change indentation
    aSettings.setIndent("\t");
    assertEquals("h1 {\n" + "\tcolor:red;\n" + "\tmargin:1px;\n" + "}\n" + "\n" + "h2 { color:rgb(1,2,3); }\n" + "\n" + "h3 {}\n" + "\n" + "@keyframes x {\n" + "\tfrom {\n" + "\t\talign:left;\n" + "\t\tcolor:#123;\n" + "\t}\n" + "\tto { x:y; }\n" + "\t50% {}\n" + "}\n" + "\n" + "@page {\n" + "\tmargin:1in;\n" + "\tmarks:none;\n" + "}\n" + "\n" + "@page :first { margin:2in; }\n" + "\n" + "@page :last {}\n" + "\n" + "@media print {\n" + "\tdiv {\n" + "\t\twidth:100%;\n" + "\t\tmin-height:0;\n" + "\t}\n" + "}\n" + "\n" + "@media all {\n" + "\tdiv { width:90%; }\n" + "}\n" + "\n" + "@media tv {}\n" + "\n" + "@font-face {\n" + "\tfont-family:'Soho';\n" + "\tsrc:url(Soho.eot);\n" + "}\n" + "\n" + "@font-face { src:local('Soho Gothic Pro'); }\n" + "\n" + "@font-face {}\n", aWriter.getCSSAsString(aCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) Test(org.junit.Test)

Aggregations

CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)64 Test (org.junit.Test)50 CSSWriter (com.helger.css.writer.CSSWriter)25 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)19 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)14 File (java.io.File)14 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)13 IReadableResource (com.helger.commons.io.resource.IReadableResource)12 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)10 Charset (java.nio.charset.Charset)10 ECSSVersion (com.helger.css.ECSSVersion)8 FileSystemRecursiveIterator (com.helger.commons.io.file.FileSystemRecursiveIterator)6 CSSDeclaration (com.helger.css.decl.CSSDeclaration)5 CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)5 ICSSTopLevelRule (com.helger.css.decl.ICSSTopLevelRule)5 CSSImportRule (com.helger.css.decl.CSSImportRule)4 CSSExpressionMemberFunction (com.helger.css.decl.CSSExpressionMemberFunction)3 CSSStyleRule (com.helger.css.decl.CSSStyleRule)3 DefaultCSSUrlVisitor (com.helger.css.decl.visit.DefaultCSSUrlVisitor)3 CollectingCSSParseErrorHandler (com.helger.css.reader.errorhandler.CollectingCSSParseErrorHandler)3