Search in sources :

Example 26 with CSSWriter

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

the class WikiCreateFontFaceRuleFuncTest method test.

@Test
public void test() {
    final CascadingStyleSheet aCSS = WikiCreateFontFaceRule.createFontFace("Your \"typeface\"", "local font name", "folder/", "myfont");
    final String sCSS = new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS);
    System.out.println(sCSS);
    final CascadingStyleSheet aCSS2 = CSSReader.readFromString(sCSS, ECSSVersion.CSS30);
    assertNotNull(aCSS2);
    assertEquals(aCSS, aCSS2);
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSWriter(com.helger.css.writer.CSSWriter) Test(org.junit.Test)

Example 27 with CSSWriter

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

the class MediaQueryToolsTest method testGetWrapped.

@Test
public void testGetWrapped() {
    // Read and arbitrary CSS
    final CascadingStyleSheet aBaseCSS = CSSReader.readFromString("p { color:red;}", s_eVersion);
    assertNotNull(aBaseCSS);
    // Create structured media queries
    final List<CSSMediaQuery> aMQs = MediaQueryTools.parseToMediaQuery("screen", s_eVersion);
    assertNotNull(aMQs);
    // Wrap the source CSS with the specified media queries
    final CascadingStyleSheet aWrappedCSS = MediaQueryTools.getWrappedInMediaQuery(aBaseCSS, aMQs, false);
    assertNotNull(aWrappedCSS);
    assertEquals("@media screen{p{color:red}}", new CSSWriter(s_eVersion, true).getCSSAsString(aWrappedCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) CSSMediaQuery(com.helger.css.decl.CSSMediaQuery) CSSWriter(com.helger.css.writer.CSSWriter) Test(org.junit.Test)

Example 28 with CSSWriter

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

the class IssueGC18Test method testIssue18.

@Test
public void testIssue18() {
    final IReadableResource aRes = new ClassPathResource("testfiles/css30/good/issue-gc-18.css");
    assertTrue(aRes.exists());
    final CascadingStyleSheet aCSS = CSSReader.readFromStream(aRes, StandardCharsets.UTF_8, ECSSVersion.CSS30, new LoggingCSSParseErrorHandler());
    assertNotNull(aCSS);
    if (false)
        System.out.println(new CSSWriter(ECSSVersion.CSS30).getCSSAsString(aCSS));
}
Also used : CascadingStyleSheet(com.helger.css.decl.CascadingStyleSheet) IReadableResource(com.helger.commons.io.resource.IReadableResource) CSSWriter(com.helger.css.writer.CSSWriter) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) LoggingCSSParseErrorHandler(com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler) Test(org.junit.Test)

Aggregations

CSSWriter (com.helger.css.writer.CSSWriter)28 CascadingStyleSheet (com.helger.css.decl.CascadingStyleSheet)25 Test (org.junit.Test)24 LoggingCSSParseErrorHandler (com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler)12 CSSReaderSettings (com.helger.css.reader.CSSReaderSettings)11 CSSWriterSettings (com.helger.css.writer.CSSWriterSettings)10 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)8 IReadableResource (com.helger.commons.io.resource.IReadableResource)8 File (java.io.File)8 Charset (java.nio.charset.Charset)7 ECSSVersion (com.helger.css.ECSSVersion)5 CSSDeclaration (com.helger.css.decl.CSSDeclaration)3 CSSExpressionMemberTermURI (com.helger.css.decl.CSSExpressionMemberTermURI)3 FileSystemRecursiveIterator (com.helger.commons.io.file.FileSystemRecursiveIterator)2 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)2 CSSExpressionMemberFunction (com.helger.css.decl.CSSExpressionMemberFunction)2 CSSExpressionMemberMath (com.helger.css.decl.CSSExpressionMemberMath)2 CSSExpressionMemberTermSimple (com.helger.css.decl.CSSExpressionMemberTermSimple)2 CSSStyleRule (com.helger.css.decl.CSSStyleRule)2 ICSSExpressionMember (com.helger.css.decl.ICSSExpressionMember)2