cz.vutbr.web.css.RuleSet Java Examples
The following examples show how to use
cz.vutbr.web.css.RuleSet.
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: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testClass() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_CLASS, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createClass("fit")); assertArrayEquals("Rule contains one class selector .fit", cslist.toArray(), rule .getSelectors()); assertEquals("Rule contains one declaration { width: 80%;}", DeclarationsUtil.appendDeclaration(null, "width", tf .createPercent(80.0f)), rule.asList()); }
Example #2
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: #00aa85;}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(192, 64, 32)), rule.asList()); }
Example #3
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBFunction2() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION2, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: rgb(50%,40%,30%);}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(127, 102, 76)), rule.asList()); }
Example #4
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBFunctionInvalid() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBFUNCTION_INVALID, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration", 1, rule.size()); Term<?> value = rule.get(0).get(0); assertTrue("Assigned value is TermFunction (not TermColor)", value instanceof TermFunction); }
Example #5
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHSLFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HSLFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration with color", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(0, 255, 0)), rule.asList()); }
Example #6
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testRGBAFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_RGBAFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration with color", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(255, 0, 0, 51)), rule.asList()); }
Example #7
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHSLAFunction1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HSLAFUNCTION1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration with color", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(0, 0, 255, 102)), rule.asList()); }
Example #8
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHashColor1() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HASH_COLOR1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector BODY ", SelectorsUtil.createSelectors("BODY"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: #00aa85;}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(0, 170, 133)), rule.asList()); }
Example #9
Source File: SimpleTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testHashColor2() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_HASH_COLOR2, null); assertEquals("One rule is set", 1, ss.size()); final RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains two selectors DIV, P", SelectorsUtil.createSelectors("DIV", "P"), rule.getSelectors()); assertEquals("Rule contains one declaration {color: #CCC;}", DeclarationsUtil.appendDeclaration(null, "color", tf.createColor(204,204,204)), rule.asList()); }
Example #10
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testDescendant() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_DESCENDANT, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "H1", null); SelectorsUtil.appendDescendant(cslist, "P"); assertArrayEquals("Rule contains one combined selectors H1 P ", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration {display:inline;}", DeclarationsUtil.appendDeclaration(null, "display", tf .createIdent("inline")), rule.asList()); }
Example #11
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAdjacent() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ADJACENT, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "DIV", null); SelectorsUtil.appendAdjacent(cslist, "P"); assertArrayEquals("Rule contains one combined selectors DIV+P ", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration {color:blue;}", DeclarationsUtil.appendDeclaration(null, "color", tf .createColor(0, 0, 255)), rule.asList()); }
Example #12
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPreceding() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PRECEDING, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "DIV", null); SelectorsUtil.appendPreceding(cslist, "P"); assertArrayEquals("Rule contains one combined selectors DIV~P ", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration {color:blue;}", DeclarationsUtil.appendDeclaration(null, "color", tf .createColor(0, 0, 255)), rule.asList()); }
Example #13
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
/** * Extract all the media queries from a {@code styles} stylesheet, resolve relative URIs (if any) in a CSS rules. * @param styles a stylesheet to process. * @return a list of entities that represent media queries. */ private static List<RuleMedia> getMediaQueries(StyleSheet styles) { List<RuleMedia> rules = new ArrayList<>(); if (styles != null) { for (RuleBlock<?> ruleBlock : styles) { if (ruleBlock instanceof RuleMedia) { RuleMedia block = (RuleMedia) ruleBlock; for (RuleSet set : block) { set.forEach(HtmlUtils::resolveUris); } rules.add(block); } } } return rules; }
Example #14
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testID() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ID, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createID("krysa")); assertArrayEquals("Rule contains one ID selector #krysa", cslist.toArray(), rule .getSelectors()); assertEquals("Rule contains one declaration { font-size: 100px;}", DeclarationsUtil.appendDeclaration(null, "font-size", tf .createLength(100.0f).setUnit(TermNumeric.Unit.px)), rule.asList()); }
Example #15
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testEscapedID() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ESCAPED_ID, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createID("1krysa")); assertArrayEquals("Rule contains one ID selector #1krysa", cslist.toArray(), rule .getSelectors()); assertEquals("Rule contains one declaration { font-size: 100px;}", DeclarationsUtil.appendDeclaration(null, "font-size", tf .createLength(100.0f).setUnit(TermNumeric.Unit.px)), rule.asList()); }
Example #16
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testIDAttrib() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_IDATTRIB, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf .createID("krysa"), rf.createAttribute("krysa", true, Selector.Operator.EQUALS, "id")); assertArrayEquals("Rule contains one ID selector #krysa[id='krysa']", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration { text-align: right }", DeclarationsUtil.appendDeclaration(null, "text-align", tf .createIdent("right")), rule.asList()); }
Example #17
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAttribute() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ATTRIB, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "A", null, rf .createAttribute("fit.vutbr.cz", true, Selector.Operator.EQUALS, "href"), rf.createAttribute( "fit", false, Selector.Operator.DASHMATCH, "id")); assertArrayEquals( "Rule contains one ID attributed selector A[href='fit.vutbr.cz'][id|=fit]", cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration { text-align: left; }", DeclarationsUtil.appendDeclaration(null, "text-align", tf .createIdent("left")), rule.asList()); }
Example #18
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPseudo() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PSEUDO, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf.createPseudoClass("hover")); assertArrayEquals("Rule contains one pseudoselector :hover", cslist.toArray(), rule .getSelectors()); assertEquals( "Rule contains one declaration { text-decoration: underline; }", DeclarationsUtil.appendDeclaration(null, "text-decoration", tf .createIdent("underline")), rule.asList()); }
Example #19
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testPseudoFunc() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PSEUDO_FUNC, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, null, null, rf.createPseudoClass("lang", "fr")); SelectorsUtil.appendChild(cslist, "Q"); assertArrayEquals("Rule contains one combined pseudoselector :lang(fr)>Q", cslist.toArray(), rule.getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createString("« ")); DeclarationsUtil.appendSpaceTerm(terms, tf.createString(" »")); assertEquals("Rule contains one declaration { quotes: '« ' ' »' }", DeclarationsUtil.appendDeclaration(null, "quotes", terms), rule .asList()); }
Example #20
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAsterisk() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ASTERISK, null); assertEquals("One rule is set", 1, ss.size()); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "*", null, rf .createClass("home")); assertArrayEquals("Rule 1 contains one combined selector *.home", cslist.toArray(), ((RuleSet) ss.get(0)).getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createIdent("Verdana")); DeclarationsUtil.appendCommaTerm(terms, tf.createIdent("monospace")); assertEquals( "Rule contains one declaration { font-family: Verdana, monospace }", DeclarationsUtil.appendDeclaration(null, "font-family", terms), ((RuleSet) ss.get(0)).asList()); }
Example #21
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testAttributePresence() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_ATTRIB_PRESENCE, null); assertEquals("One rule is set", 1, ss.size()); List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "*", null, rf .createAttribute(null, false, Selector.Operator.NO_OPERATOR, "href")); assertArrayEquals("Rule 1 contains one combined selector *[href]", cslist.toArray(), ((RuleSet) ss.get(0)).getSelectors()); List<Term<?>> terms = DeclarationsUtil.appendTerm(null, null, tf .createIdent("Verdana")); DeclarationsUtil.appendCommaTerm(terms, tf.createIdent("monospace")); assertEquals( "Rule contains one declaration { text-decoration: underline }", DeclarationsUtil.appendDeclaration(null, "text-decoration", tf .createIdent("underline")), ((RuleSet) ss.get(0)) .asList()); }
Example #22
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void legacyPseudoElementSupport() throws CSSException, IOException { StyleSheet style = CSSFactory.parseString(TEST_PSEUDO_1, null); assertEquals("There are 4 rules", 4, style.size()); List<CombinedSelector> sel1 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-line")); List<CombinedSelector> sel2 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-letter")); List<CombinedSelector> sel3 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("before")); List<CombinedSelector> sel4 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("after")); RuleSet rule1 = (RuleSet) style.get(0); assertArrayEquals("Rule contains one selector p::first-line", sel1.toArray(), rule1.getSelectors()); assertEquals("Rule contains one declaration", 1, rule1.size()); RuleSet rule2 = (RuleSet) style.get(1); assertArrayEquals("Rule contains one selector p::first-letter", sel2.toArray(), rule2.getSelectors()); assertEquals("Rule contains one declaration", 1, rule2.size()); RuleSet rule3 = (RuleSet) style.get(2); assertArrayEquals("Rule contains one selector p::before", sel3.toArray(), rule3.getSelectors()); assertEquals("Rule contains one declaration", 1, rule3.size()); RuleSet rule4 = (RuleSet) style.get(3); assertArrayEquals("Rule contains one selector p::after", sel4.toArray(), rule4.getSelectors()); assertEquals("Rule contains one declaration", 1, rule4.size()); }
Example #23
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void nonlegacyPseudoElementSupport() throws CSSException, IOException { StyleSheet style = CSSFactory.parseString(TEST_PSEUDO_2, null); assertEquals("There are 4 rules", 4, style.size()); List<CombinedSelector> sel1 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-line")); List<CombinedSelector> sel2 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("first-letter")); List<CombinedSelector> sel3 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("before")); List<CombinedSelector> sel4 = SelectorsUtil.appendSimpleSelector(null, "p", null, rf.createPseudoElement("after")); RuleSet rule1 = (RuleSet) style.get(0); assertArrayEquals("Rule contains one selector p::first-line", sel1.toArray(), rule1.getSelectors()); assertEquals("Rule contains one declaration", 1, rule1.size()); RuleSet rule2 = (RuleSet) style.get(1); assertArrayEquals("Rule contains one selector p::first-letter", sel2.toArray(), rule2.getSelectors()); assertEquals("Rule contains one declaration", 1, rule2.size()); RuleSet rule3 = (RuleSet) style.get(2); assertArrayEquals("Rule contains one selector p::before", sel3.toArray(), rule3.getSelectors()); assertEquals("Rule contains one declaration", 1, rule3.size()); RuleSet rule4 = (RuleSet) style.get(3); assertArrayEquals("Rule contains one selector p::after", sel4.toArray(), rule4.getSelectors()); assertEquals("Rule contains one declaration", 1, rule4.size()); }
Example #24
Source File: PseudoClassTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void rangeInputPseudoElements() throws CSSException, IOException { StyleSheet style = CSSFactory.parseString(TEST_RANGE, null); assertEquals("There are 6 rules", 6, style.size()); for (int i = 0; i < TEST_RANGE_ELEMENTS.length; i++) { List<CombinedSelector> cslist = SelectorsUtil.appendSimpleSelector(null, "input", null, rf.createAttribute("range", false, Selector.Operator.EQUALS, "type"), rf.createPseudoElement(TEST_RANGE_ELEMENTS[i])); RuleSet rule = (RuleSet) style.get(i); assertArrayEquals("Rule contains one selector input[type=range]::" + TEST_RANGE_ELEMENTS[i], cslist.toArray(), rule.getSelectors()); assertEquals("Rule contains one declaration", 1, rule.size()); } }
Example #25
Source File: GradientTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testSampleGradients() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(SAMPLE_LINEAR_GRADIENT_1, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule1 = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector div ", SelectorsUtil.createSelectors("div"), rule1.getSelectors()); assertEquals("Rule contains one declaration for background ", "background", rule1.get(0).getProperty()); assertEquals("Rule contains one term ", 1, rule1.get(0).size()); assertTrue("Rule contains a TermFunction ", rule1.get(0).get(0) instanceof TermFunction); TermFunction func = (TermFunction) rule1.get(0).get(0); assertEquals("Function name is linear-gradient ", "linear-gradient", func.getFunctionName()); List<List<Term<?>>> separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("There are 3 comma-separated arguments ", 3, separatedArguments.size()); assertEquals("The first argument is to bottom ", Arrays.asList(tf.createIdent("to"), tf.createIdent("bottom")), separatedArguments.get(0)); assertEquals("The first argument is pretty-printed as \"to bottom\" ", "linear-gradient(to bottom,", func.toString().substring(0, "linear-gradient(to bottom,".length())); assertEquals("The second argument is rgba(245,245,245,1) 0% ", Arrays.asList(tf.createColor(245, 245, 245, 255), tf.createPercent(0f)), separatedArguments.get(1)); assertEquals("The second argument is rgba(221,221,221,1) 100% ", Arrays.asList(tf.createColor(221, 221, 221, 255), tf.createPercent(100f)), separatedArguments.get(2)); }
Example #26
Source File: GradientTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testMultipleGradients() throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(TEST_LINEAR_GRADIENT_MULTIPLE, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertArrayEquals("Rule contains one selector div ", SelectorsUtil.createSelectors("div"), rule.getSelectors()); assertEquals("Rule contains one declaration for background ", "background", rule.get(0).getProperty()); assertEquals("Rule contains two terms ", 2, rule.get(0).size()); TermFunction func = (TermFunction) rule.get(0).get(0); List<List<Term<?>>> separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("First function name is linear-gradient ", "linear-gradient", func.getFunctionName()); assertEquals("First function has 2 comma-separated arguments ", 2, separatedArguments.size()); assertEquals("The first argument is red ", Arrays.asList(tf.createColor(tf.createIdent("red"))), separatedArguments.get(0)); assertEquals("The second argument is blue ", Arrays.asList(tf.createColor(tf.createIdent("blue"))), separatedArguments.get(1)); func = (TermFunction) rule.get(0).get(1); separatedArguments = func.getSeparatedArgs(tf.createOperator(',')); assertEquals("Second function name is linear-gradient ", "linear-gradient", func.getFunctionName()); assertEquals("Second function has 3 comma-separated arguments ", 3, separatedArguments.size()); assertEquals("The first argument is to right ", Arrays.asList(tf.createIdent("to"), tf.createIdent("right")), separatedArguments.get(0)); assertEquals("The second argument is yellow ", Arrays.asList(tf.createColor(tf.createIdent("yellow"))), separatedArguments.get(1)); assertEquals("The third argument is green ", Arrays.asList(tf.createColor(tf.createIdent("green"))), separatedArguments.get(2)); }
Example #27
Source File: HtmlUtils.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private static List<RuleBlock<?>> getAtRuleBlocks(StyleSheet styles, StylesEmbeddingOptions options) { List<RuleBlock<?>> rules = new ArrayList<>(); if (styles != null) { for (RuleBlock<?> ruleBlock : styles) { if (ruleBlock instanceof RuleMedia) { RuleMedia block = (RuleMedia) ruleBlock; for (RuleSet set : block) { set.forEach(HtmlUtils::resolveUris); } resolveMediaType(block.getMediaQueries(), options.getMediaType()); rules.add(block); } else if (ruleBlock instanceof RuleFontFace) { rules.add(ruleBlock); } } } return rules; }
Example #28
Source File: SimplePreparator.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
public RuleBlock<?> prepareRuleMedia(List<RuleSet> rules, List<MediaQuery> media) { if (rules == null || rules.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Empty RuleMedia was ommited"); } return null; } // create media at position of mark RuleMedia rm = rf.createMedia(); rm.replaceAll(rules); if (media != null && !media.isEmpty()) rm.setMediaQueries(media); log.info("Create @media as with:\n{}", rm); return (RuleBlock<?>) rm; }
Example #29
Source File: EscapingTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
private void assertSingleId(String input, String className) throws IOException, CSSException { StyleSheet ss = CSSFactory.parseString(input, null); assertEquals("One rule is set", 1, ss.size()); RuleSet rule = (RuleSet) ss.get(0); assertEquals("One combined selector", rule.getSelectors().length, 1); CombinedSelector cs = rule.getSelectors()[0]; assertEquals("One selector", cs.size(), 1); assertEquals("The class name is correct", className, cs.get(0).getIDName()); }
Example #30
Source File: SelectorTest.java From jStyleParser with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testPSpecial() throws CSSException, IOException { StyleSheet ss = CSSFactory.parseString(TEST_PSPECIAL, null); assertEquals("Two rules are set", 2, ss.size()); // test first rule List<CombinedSelector> cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "P", null, rf.createClass("special"), rf.createPseudoElement("before")); assertArrayEquals("Rule 1 contains one combined selector P.special:before", cslist.toArray(), ((RuleSet) ss.get(0)).getSelectors()); assertEquals( "Rule 2 contains one declaration { content: \"Special! \"}", DeclarationsUtil.appendDeclaration(null, "content", tf .createString("Special! ")), ((RuleSet) ss.get(0)) .asList()); // test second rule cslist = SelectorsUtil.appendCS(null); SelectorsUtil.appendSimpleSelector(cslist, "P", null, rf.createClass("special"), rf.createPseudoElement("first-letter")); assertArrayEquals( "Rule 2 contains one combined selector P.special:first-letter", cslist.toArray(), ((RuleSet) ss.get(1)).getSelectors()); assertEquals("Rule 2 contains one declaration { color: #ffd800}", DeclarationsUtil.appendDeclaration(null, "color", tf .createColor(255, 216, 0)), ((RuleSet) ss.get(1)) .asList()); }