-
Notifications
You must be signed in to change notification settings - Fork 11
HTML Inliner
This document provides information about how HTML inliner utility works and what its expected behavior is.
The HTML inliner class is HtmlAttributeInliner. It is a simple utility class that can create HTML attributes when certain CSS selectors are present and targeted by his specific configuration (HtmlInlinerConfiguration).
It exposes only one public method, process, which takes the following parameters:
- element: the HTML element currently processed
- styleToken: the element-related final (i.e. merged from current element style and stylesheet) StyleToken
- htmlInlinerConfiguration: the related HtmlInlinerConfiguration. This method will processes the HTML element and, if all criteria has been met, creates a new HTML attribute.
This configuration can be customized in "Styles inliner configuration" OSGi config. It is possible to create multiple configurations for HTML inliner, so the related property ("HTML inliner configuration") is a list of object.
The HTML inliner configuration is used for its execution to:
- Select whether an HTML element is suitable for HTML inliner execution;
- Select (with a regular expression) which CSS property should be used to create a new HTML attribute;
- Extract (with a regular expression) the value of the CSS property;
- Specify the name to be used for the creation of the new HTML attribute;
- Select whether an existing HTML attribute should be overridden with the HTML inliner result.
To create a new HTML inliner configuration, user must create a new JSON object with the following structure:
{ "elementType":"ELEMENT_TYPE", "cssPropertyRegEx":"CSS_PROPERTY_REGEX", "cssPropertyOutputRegEx":"CSS_PROPERTY_OUTPUT_REGEX", "htmlAttributeName":"HTML_ATTRIBUTE_NAME", "overrideIfAlreadyExisting":OVERRIDE_IF_ALREADY_EXISTING }
Where:
- CSS_PROPERTY_REGEX (string) is the target HTML element;
- CSS_PROPERTY_REGEX (string) is the regular expression to select the proper CSS property;
- CSS_PROPERTY_OUTPUT_REGEX (string) is the regular expression to select the value of the CSS property. It will be applied to the value part of the CSS property (for example, for the property "width: 500px", CSS_PROPERTY_OUTPUT_REGEX will be applied to the string "500px"). To get the full value of the CSS property, just use the regular expression ".*";
- HTML_ATTRIBUTE_NAME (string) is the name of the new HTML attribute to be created;
- OVERRIDE_IF_ALREADY_EXISTING (boolean) is true if already existing HTML attributes should be overridden with HTML inliner results, false otherwise.
Its execution is embedded in StylesInlinerServiceImpl.
The class HtmlAttributeInlinerTest is the JUnit test class. Tests that cover the features required for this utility are defined here. The code coverage (retrieved from Intellij Idea Coverage window) is:
- Class: 100%
- Method: 100%
- Lines: 93%