Search in sources :

Example 16 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings in project ph-css by phax.

the class CSSImportRuleTest method testCreate.

@Test
public void testCreate() {
    final CSSImportRule aImportRule = new CSSImportRule("a.gif");
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);
    assertEquals("@import url(a.gif);\n", aImportRule.getAsCSSString(aSettings));
    aSettings.setQuoteURLs(true);
    assertEquals("@import url('a.gif');\n", aImportRule.getAsCSSString(aSettings));
}
Also used : CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) Test(org.junit.Test)

Example 17 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings in project ph-css by phax.

the class CSSRGBATest method testBasic.

@Test
public void testBasic() {
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);
    final CSSRGBA aColor = new CSSRGBA(1, 2, 3, 0.5f);
    assertEquals("rgba(1,2,3,0.5)", aColor.getAsCSSString(aSettings));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aColor, new CSSRGBA(aColor));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aColor, new CSSRGBA(1, 2, 3, 0.5f));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSRGBA(0, 2, 3, 0.5f));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSRGBA(1, 0, 3, 0.5f));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSRGBA(1, 2, 0, 0.5f));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSRGBA(1, 2, 3, 0f));
}
Also used : CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) Test(org.junit.Test)

Example 18 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings in project ph-css by phax.

the class CSSHSLTest method testBasic.

@Test
public void testBasic() {
    final CSSWriterSettings aSettings = new CSSWriterSettings(ECSSVersion.CSS30, false);
    final CSSHSL aColor = new CSSHSL(1, 2, 3);
    assertEquals("hsl(1,2%,3%)", aColor.getAsCSSString(aSettings));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aColor, new CSSHSL(aColor));
    CommonsTestHelper.testDefaultImplementationWithEqualContentObject(aColor, new CSSHSL(1, 2, 3));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSHSL(0, 2, 3));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSHSL(1, 0, 3));
    CommonsTestHelper.testDefaultImplementationWithDifferentContentObject(aColor, new CSSHSL(1, 2, 0));
}
Also used : CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) Test(org.junit.Test)

Example 19 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings in project ph-css by phax.

the class WikiVisitSelectors method readAllSelectors.

public void readAllSelectors() {
    final String sStyle = "blockquote p,\r\n" + "blockquote ul,\r\n" + "blockquote ol {\r\n" + "  line-height:normal;\r\n" + "  font-style:italic;\r\n" + "}\r\n" + "\r\n" + "a { color:#FFEA6F; }\r\n" + "\r\n" + "a:hover { text-decoration:none; }\r\n" + "\r\n" + "img { border:none; }";
    final CascadingStyleSheet aCSS = CSSReader.readFromString(sStyle, ECSSVersion.CSS30);
    final ICommonsList<String> aAllSelectors = new CommonsArrayList<>();
    CSSVisitor.visitCSS(aCSS, new DefaultCSSVisitor() {

        @Override
        public void onStyleRuleSelector(@Nonnull final CSSSelector aSelector) {
            aAllSelectors.add(aSelector.getAsCSSString(new CSSWriterSettings(ECSSVersion.CSS30)));
        }
    });
    System.out.println(aAllSelectors);
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) DefaultCSSVisitor(com.helger.css.decl.visit.DefaultCSSVisitor) CSSSelector(com.helger.css.decl.CSSSelector) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 20 with CSSWriterSettings

use of com.helger.css.writer.CSSWriterSettings in project ph-css by phax.

the class WikiVisitFromHtml method readFromStyleAttributeWithAPI.

public static void readFromStyleAttributeWithAPI() {
    final String sStyle = "color:red; background:fixed !important";
    final CSSDeclarationList aDeclList = CSSReaderDeclarationList.readFromString(sStyle, ECSSVersion.CSS30);
    if (aDeclList == null)
        throw new IllegalStateException("Failed to parse CSS: " + sStyle);
    // For all contained declarations
    for (final CSSDeclaration aDeclaration : aDeclList.getAllDeclarations()) System.out.println(aDeclaration.getProperty() + ": " + aDeclaration.getExpression().getAsCSSString(new CSSWriterSettings(ECSSVersion.CSS30)) + (aDeclaration.isImportant() ? " (important)" : " (not important)"));
}
Also used : CSSWriterSettings(com.helger.css.writer.CSSWriterSettings) CSSDeclaration(com.helger.css.decl.CSSDeclaration) CSSDeclarationList(com.helger.css.decl.CSSDeclarationList)

Aggregations

CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)21 Test (org.junit.Test)14 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)10 CSSWriter (com.helger.css.writer.CSSWriter)10 CSSDeclaration (com.helger.css.decl.CSSDeclaration)6 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)6 CSSDeclarationList (com.helger.css.decl.CSSDeclarationList)3 CSSExpressionMemberTermSimple (com.helger.css.decl.CSSExpressionMemberTermSimple)3 ICSSExpressionMember (com.helger.css.decl.ICSSExpressionMember)3 File (java.io.File)3 Charset (java.nio.charset.Charset)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 ECSSVersion (com.helger.css.ECSSVersion)2 CSSExpressionMemberFunction (com.helger.css.decl.CSSExpressionMemberFunction)2 CSSExpressionMemberMath (com.helger.css.decl.CSSExpressionMemberMath)2 CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)2 CSSStyleRule (com.helger.css.decl.CSSStyleRule)2 DefaultCSSVisitor (com.helger.css.decl.visit.DefaultCSSVisitor)2 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)2