However, Processors need not be restricted to validating or simple conversions.
Processors could also greatly expand from input.
For example, the following Processor, named "Expander",
would expand "mp" to generate both "margin" and "padding".
import org.groocss.*
class Expander implements Processor< StyleGroup > {
Optional process(StyleGroup sg, Phase phase) {
if (phase == Phase.PRE_VALIDATE) {
def style = sg.styleList.find{ it.name == 'mp' }
if (style) {
style.name = "padding"
sg.add(new Style('margin', style.value))
}
}
return Optional.empty();
}
}
-Note that the generic type (StyleGroup in this class) determines
what type will be processed by your Processor.
This allows the input to use those shortcuts in GrooCSS such as the following:
table {
add style('mp', 10.px)
}
Which will become the following CSS:
table {
margin: 10px;
padding: 10px;
}
This example demonstrates how Processors can modify and add to generated CSS.