Java Code Examples for com.helger.css.ECSSVersion#CSS30
The following examples show how to use
com.helger.css.ECSSVersion#CSS30 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WikiWriteCSS.java From ph-css with Apache License 2.0 | 6 votes |
/** * Write a CSS 3.0 declaration to a file using UTF-8 encoding. * * @param aCSS * The CSS to be written to a file. May not be <code>null</code>. * @param aFile * The file to be written. May not be <code>null</code>. * @return {@link ESuccess#SUCCESS} if everything went okay, and * {@link ESuccess#FAILURE} if an error occurred */ public ESuccess writeCSS30 (final CascadingStyleSheet aCSS, final File aFile) { // 1.param: version to write // 2.param: false== non-optimized output final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false); try { final CSSWriter aWriter = new CSSWriter (aSettings); // Write the @charset rule: (optional) aWriter.setContentCharset (StandardCharsets.UTF_8.name ()); // Write a nice file header aWriter.setHeaderText ("This file was generated by ph-css\nGrab a copy at https://github.com/phax/ph-css"); // Convert the CSS to a String final String sCSSCode = aWriter.getCSSAsString (aCSS); // Finally write the String to a file return SimpleFileIO.writeFile (aFile, sCSSCode, StandardCharsets.UTF_8); } catch (final Exception ex) { LOGGER.error ("Failed to write the CSS to a file", ex); return ESuccess.FAILURE; } }
Example 2
Source File: CSSReader30SpecialFuncTest.java From ph-css with Apache License 2.0 | 6 votes |
@Test public void testReadSingleLineComments () { final ECSSVersion eVersion = ECSSVersion.CSS30; final Charset aCharset = StandardCharsets.UTF_8; final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-singleline-comments.css"); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset, eVersion); assertNotNull (aCSS); assertEquals (13, aCSS.getRuleCount ()); assertEquals (13, aCSS.getStyleRuleCount ()); // #any1 - #any5 assertEquals (2, aCSS.getStyleRuleAtIndex (1).getDeclarationCount ()); assertEquals (1, aCSS.getStyleRuleAtIndex (2).getDeclarationCount ()); assertEquals (1, aCSS.getStyleRuleAtIndex (3).getDeclarationCount ()); assertEquals (0, aCSS.getStyleRuleAtIndex (4).getDeclarationCount ()); assertEquals (0, aCSS.getStyleRuleAtIndex (5).getDeclarationCount ()); // .test1 - .test7 assertEquals (2, aCSS.getStyleRuleAtIndex (6).getDeclarationCount ()); assertEquals (3, aCSS.getStyleRuleAtIndex (7).getDeclarationCount ()); assertEquals (1, aCSS.getStyleRuleAtIndex (8).getDeclarationCount ()); assertEquals (1, aCSS.getStyleRuleAtIndex (9).getDeclarationCount ()); assertEquals (2, aCSS.getStyleRuleAtIndex (10).getDeclarationCount ()); assertEquals (2, aCSS.getStyleRuleAtIndex (11).getDeclarationCount ()); assertEquals (1, aCSS.getStyleRuleAtIndex (12).getDeclarationCount ()); }
Example 3
Source File: CssUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static String stripEmbeddableStyles(CascadingStyleSheet styles, String mediaType, boolean prettyPrint) { if (styles == null) { return ""; } CSSWriterSettings settings = new CSSWriterSettings(ECSSVersion.CSS30); settings.setNewLineMode(ENewLineMode.UNIX); if (prettyPrint) { settings.setIndent(DEFAULT_INDENT); } else { settings.setOptimizedOutput(true); } stripEmbeddableRules(styles); if (isExactMediaType(mediaType)) { stripMediaType(styles, mediaType); } return toString(styles, settings); }
Example 4
Source File: CSSRGBATest.java From ph-css with Apache License 2.0 | 5 votes |
@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)); }
Example 5
Source File: CSSReader21SpecialFuncTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testReadSpecialGood () { final ECSSVersion eVersion = ECSSVersion.CSS30; final Charset aCharset = StandardCharsets.UTF_8; final File aFile = new File ("src/test/resources/testfiles/css21/good/artificial/test-url.css"); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset, eVersion); assertNotNull (aCSS); final String sCSS = new CSSWriter (eVersion, false).getCSSAsString (aCSS); assertNotNull (sCSS); if (false) LOGGER.info (sCSS); }
Example 6
Source File: ECSSColorTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testAll () { final CSSWriter aWriter = new CSSWriter (ECSSVersion.CSS30); for (final ECSSColor eColor : ECSSColor.values ()) { assertTrue (StringHelper.hasText (eColor.getName ())); assertTrue (CSSColorHelper.isColorValue (eColor.getName ())); final String sHex = eColor.getAsHexColorValue (); assertTrue (sHex, CSSColorHelper.isHexColorValue (sHex)); final String sRGB = eColor.getAsRGBColorValue (); assertTrue (sRGB, CSSColorHelper.isRGBColorValue (sRGB)); assertNotNull (eColor.getAsRGB ()); assertEquals (sRGB, aWriter.getCSSAsString (eColor.getAsRGB ())); final String sRGBA = eColor.getAsRGBAColorValue (1f); assertTrue (sRGBA, CSSColorHelper.isRGBAColorValue (sRGBA)); assertNotNull (eColor.getAsRGBA (1)); assertEquals (sRGBA, aWriter.getCSSAsString (eColor.getAsRGBA (1))); final String sHSL = eColor.getAsHSLColorValue (); assertTrue (sHSL, CSSColorHelper.isHSLColorValue (sHSL)); assertNotNull (eColor.getAsHSL ()); assertEquals (sHSL, aWriter.getCSSAsString (eColor.getAsHSL ())); final String sHSLA = eColor.getAsHSLAColorValue (1f); assertTrue (sHSLA, CSSColorHelper.isHSLAColorValue (sHSLA)); assertNotNull (eColor.getAsHSLA (1)); assertEquals (sHSLA, aWriter.getCSSAsString (eColor.getAsHSLA (1))); assertSame (eColor, ECSSColor.getFromNameCaseInsensitiveOrNull (eColor.getName ())); assertTrue (ECSSColor.isDefaultColorName (eColor.getName ())); } }
Example 7
Source File: CSSRGBTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testBasic () { final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false); final CSSRGB aColor = new CSSRGB (1, 2, 3); assertEquals ("rgb(1,2,3)", aColor.getAsCSSString (aSettings)); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSRGB (aColor)); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aColor, new CSSRGB (1, 2, 3)); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGB (0, 2, 3)); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGB (1, 0, 3)); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aColor, new CSSRGB (1, 2, 0)); }
Example 8
Source File: CSSHSLTest.java From ph-css with Apache License 2.0 | 5 votes |
@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)); }
Example 9
Source File: CSSURITest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testBasic () { final CSSURI aURI = new CSSURI ("a.gif"); assertEquals ("a.gif", aURI.getURI ()); final CSSWriterSettings aSettings = new CSSWriterSettings (ECSSVersion.CSS30, false); assertEquals ("url(a.gif)", aURI.getAsCSSString (aSettings)); aSettings.setQuoteURLs (true); assertEquals ("url('a.gif')", aURI.getAsCSSString (aSettings)); assertFalse (aURI.isDataURL ()); assertNull (aURI.getAsDataURL ()); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (aURI, new CSSURI ("a.gif")); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (aURI, new CSSURI ("b.gif")); }
Example 10
Source File: CSSReader30SpecialFuncTest.java From ph-css with Apache License 2.0 | 5 votes |
@Test public void testReadSpecialGood () { final ECSSVersion eVersion = ECSSVersion.CSS30; final Charset aCharset = StandardCharsets.UTF_8; final File aFile = new File ("src/test/resources/testfiles/css30/good/issue57.css"); final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset, eVersion); assertNotNull (aCSS); final String sCSS = new CSSWriter (eVersion, false).getCSSAsString (aCSS); assertNotNull (sCSS); if (false) LOGGER.info (sCSS); }
Example 11
Source File: CSSSupportsConditionNested.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 12
Source File: CSSSupportsRule.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 13
Source File: CSSPageMarginBlock.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 14
Source File: CSSExpressionMemberMath.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 15
Source File: CSSExpressionMemberMathUnitProduct.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 16
Source File: CSSMediaExpression.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 17
Source File: CSSSupportsConditionDeclaration.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 18
Source File: CSSWriterTest.java From ph-css with Apache License 2.0 | 4 votes |
@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)); }
Example 19
Source File: CSSExpressionMemberFunction.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }
Example 20
Source File: CSSFontFaceRule.java From ph-css with Apache License 2.0 | 4 votes |
@Nonnull public ECSSVersion getMinimumCSSVersion () { return ECSSVersion.CSS30; }