use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSWriterTest method testRemoveUnnecessaryCode1.
@Test
public void testRemoveUnnecessaryCode1() {
final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS3, ECSSVersion.CSS30);
assertNotNull(aCSS);
final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false).setRemoveUnnecessaryCode(true);
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" + "@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" + "@media print {\n" + " div {\n" + " width:100%;\n" + " min-height:0;\n" + " }\n" + "}\n" + "\n" + "@media all {\n" + " div { width:90%; }\n" + "}\n" + "\n" + "@font-face {\n" + " font-family:'Soho';\n" + " src:url(Soho.eot);\n" + "}\n" + "\n" + "@font-face { src:local('Soho Gothic Pro'); }\n", aWriter.getCSSAsString(aCSS));
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSWriterTest method testNewLineModeMac.
@Test
public void testNewLineModeMac() {
final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS5, ECSSVersion.CSS30);
assertNotNull(aCSS);
// Non-optimized version
CSSWriter aWriter = new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(false).setNewLineMode(ENewLineMode.MAC)).setWriteHeaderText(true).setHeaderText("Unit test");
assertEquals("/*\r" + " * Unit test\r" + " */\r" + "h1 {\r" + " color:red;\r" + " margin:1px;\r" + "}\r" + "\r" + "h2 {\r" + " color:red;\r" + " margin:1px;\r" + "}\r", aWriter.getCSSAsString(aCSS));
// Optimized version
aWriter = new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true).setNewLineMode(ENewLineMode.MAC)).setWriteHeaderText(true).setHeaderText("Unit test2");
assertEquals("/*\r" + " * Unit test2\r" + " */\r" + "h1{color:red;margin:1px}h2{color:red;margin:1px}", aWriter.getCSSAsString(aCSS));
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSWriterTest method testWriteCertainRules.
@Test
public void testWriteCertainRules() {
final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, true);
aSettings.setWriteFontFaceRules(false);
aSettings.setWriteKeyframesRules(false);
aSettings.setWriteMediaRules(false);
aSettings.setWritePageRules(false);
final CSSWriter aWriter = new CSSWriter(aSettings).setWriteHeaderText(false);
// Some non-special rules
CascadingStyleSheet aCSS = CSSReader.readFromString(CSS3, ECSSVersion.CSS30);
assertNotNull(aCSS);
assertEquals("h1{color:red;margin:1px}h2{color:rgb(1,2,3)}h3{}", aWriter.getCSSAsString(aCSS));
// Only @media rule
aCSS = CSSReader.readFromString(CSS4, ECSSVersion.CSS30);
assertNotNull(aCSS);
assertEquals("", aWriter.getCSSAsString(aCSS));
// Nothing special
aCSS = CSSReader.readFromString(CSS5, ECSSVersion.CSS30);
assertNotNull(aCSS);
assertEquals("h1{color:red;margin:1px}h2{color:red;margin:1px}", aWriter.getCSSAsString(aCSS));
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class CSSWriterTest method testNewLineModeWindows.
@Test
public void testNewLineModeWindows() {
final CascadingStyleSheet aCSS = CSSReader.readFromString(CSS5, ECSSVersion.CSS30);
assertNotNull(aCSS);
// Non-optimized version
CSSWriter aWriter = new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(false).setNewLineMode(ENewLineMode.WINDOWS)).setWriteHeaderText(true).setHeaderText("Unit test");
assertEquals("/*\r\n" + " * Unit test\r\n" + " */\r\n" + "h1 {\r\n" + " color:red;\r\n" + " margin:1px;\r\n" + "}\r\n" + "\r\n" + "h2 {\r\n" + " color:red;\r\n" + " margin:1px;\r\n" + "}\r\n", aWriter.getCSSAsString(aCSS));
// Optimized version
aWriter = new CSSWriter(new CSSWriterSettings(ECSSVersion.CSS30).setOptimizedOutput(true).setNewLineMode(ENewLineMode.WINDOWS)).setWriteHeaderText(true).setHeaderText("Unit test2");
assertEquals("/*\r\n" + " * Unit test2\r\n" + " */\r\n" + "h1{color:red;margin:1px}h2{color:red;margin:1px}", aWriter.getCSSAsString(aCSS));
}
use of com.helger.css.decl.CascadingStyleSheet in project ph-css by phax.
the class WikiVisitUrls method readFromStyleAttributeWithAPI.
public void readFromStyleAttributeWithAPI() {
final String sStyle = "@import 'foobar.css';\n" + "div{background:fixed url(a.gif) !important;}\n" + "span { background-image:url('/my/folder/b.gif');}";
final CascadingStyleSheet aCSS = CSSReader.readFromString(sStyle, ECSSVersion.CSS30);
CSSVisitor.visitCSSUrl(aCSS, new DefaultCSSUrlVisitor() {
// Called for each import
@Override
public void onImport(@Nonnull final CSSImportRule aImportRule) {
System.out.println("Import: " + aImportRule.getLocationString() + " - " + getSourceLocationString(aImportRule.getSourceLocation()));
}
// Call for URLs outside of URLs
@Override
public void onUrlDeclaration(@Nullable final ICSSTopLevelRule aTopLevelRule, @Nonnull final CSSDeclaration aDeclaration, @Nonnull final CSSExpressionMemberTermURI aURITerm) {
System.out.println(aDeclaration.getProperty() + " - references: " + aURITerm.getURIString() + " - " + getSourceLocationString(aURITerm.getSourceLocation()));
}
});
}
Aggregations