biz.gabrys.maven.plugins.css.splitter.steadystate.converter.StyleRuleConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of css-splitter-maven-plugin
Show all versions of css-splitter-maven-plugin
Splits CSS stylesheets to smaller files ("parts") which contain maximum X rules.
/*
* CSS Splitter Maven Plugin
* http://css-splitter-maven-plugin.projects.gabrys.biz/
*
* Copyright (c) 2015 Adam Gabryś
*
* This file is licensed under the BSD 3-Clause (the "License").
* You may not use this file except in compliance with the License.
* You may obtain:
* - a copy of the License at project page
* - a template of the License at https://opensource.org/licenses/BSD-3-Clause
*/
package biz.gabrys.maven.plugins.css.splitter.steadystate.converter;
import java.util.LinkedList;
import java.util.List;
import com.steadystate.css.dom.CSSStyleDeclarationImpl;
import com.steadystate.css.dom.CSSStyleRuleImpl;
import com.steadystate.css.dom.Property;
import com.steadystate.css.parser.SelectorListImpl;
import biz.gabrys.maven.plugins.css.splitter.css.type.StyleProperty;
import biz.gabrys.maven.plugins.css.splitter.css.type.StyleRule;
class StyleRuleConverter extends AbstractRuleConverter {
StyleRuleConverter() {
super(CSSStyleRuleImpl.class);
}
@Override
protected StyleRule convert2(final CSSStyleRuleImpl rule) {
final List selectors = new LinkedList();
final SelectorListImpl selectorsList = (SelectorListImpl) rule.getSelectors();
for (int i = 0; i < selectorsList.getLength(); ++i) {
selectors.add(selectorsList.item(i).toString());
}
final CSSStyleDeclarationImpl style = (CSSStyleDeclarationImpl) rule.getStyle();
final List properties = new LinkedList();
for (final Property property : style.getProperties()) {
properties.add(new StyleProperty(property.getName(), property.getValue().getCssText()));
}
return new StyleRule(selectors, properties);
}
}