|
Erebot
latest
A modular IRC bot for PHP 5.3+
|
Provides styling (formatting) features. More...
Inheritance diagram for Erebot\Styling:Public Member Functions | |
| _ ($template, array $vars=array()) | |
| __construct (\Erebot\IntlInterface $translator) | |
| getClass ($type) | |
| getTranslator () | |
| render ($template, array $vars=array()) | |
| setClass ($type, $cls) | |
Protected Member Functions | |
| parseNode ($node, &$attributes, $vars) | |
| wrapScalar ($var, $name) | |
Static Protected Member Functions | |
| static | checkVariableName ($var) |
| static | parseTemplate ($source) |
Protected Attributes | |
| $cls | |
| Maps some scalar types to a typed variable. | |
| $translator | |
| Translator to use to improve rendering. | |
Private Member Functions | |
| parseChildren ($node, &$attributes, $vars) | |
Provides styling (formatting) features.
Given a format string (a template), this class can perform styling on that template to produce complex messages.
A template is composed of a single string, which may contain special markup to insert dynamic content, add formatting attributes to the text (like bold, underline, colors), etc.
| Markup | Role |
|---|---|
| <b>...</b> | The text is rendered in bold |
| <u>...</u> | The text is rendered underlined |
| <var name="..."/> | This markup gets replaced by the content of the given variable |
| <color fg="..." bg="..."> ... </color> | The text is rendered with the given foreground (fg) and background (bg) colors. The value of the fg and bg attributes may be either an integer (see the COLOR_* constants in this class) or the name of the color (again, supported colors are named after the COLOR_* constants). |
| <for from="..." item="..." key="..." sep=", " last=" & "> ... </for> | This markup loops over the associative array in from. The key for each entry in that array is stored in the temporary variable named by the key attribute if given, while the associated value is stored in the temporary variable named by item. The value of sep (alias separator) is appended automatically between each entry of the array, except between the last two entries. The value of last (alias last_separator) is used to separate the last two entries. By default, no temporary variable is created for the key, ", " is used as the main separator and " & " is used as the last_separator. |
| <plural var="..."> <case form="..."> ... </case> </plural> | Handles plurals. Depending on the value of the variable pointed by var, one of the cases will be used. The page at http://unicode.org/cldr/data/charts/supplemental/language_plural_rules.html references every available form per language. |
Definition at line 113 of file Styling.php.
| Erebot\Styling::__construct | ( | \Erebot\IntlInterface | $translator | ) |
Construct a new styling object.
| Erebot::IntlInterface | $translator | A translator object, used to determine the correct pluralization rules. |
Implements Erebot\StylingInterface.
Definition at line 128 of file Styling.php.
| Erebot\Styling::_ | ( | $template, | |
| array | $vars = array() |
||
| ) |
Alias for Erebot::StylingInterface::render(), compatible with internationalization tools such as xgettext.
| string | $template | A template to render. |
| array | $vars | (optional) An array of variables that can be used to change the way the template will be rendered. |
| string | The formatted result for this template. |
Implements Erebot\StylingInterface.
Definition at line 216 of file Styling.php.
|
staticprotected |
Checks whether the given variable name is valid and throws an exception if its not.
| string | $var | Variable name to test. |
| ::InvalidArgumentException | The given variable name is invalid. |
Definition at line 204 of file Styling.php.
| Erebot\Styling::getClass | ( | $type | ) |
Returns the class used to wrap scalar types.
| string | $type | Name of a scalar type that can be wrapped by this class automatically. Must be one of "int", "string" or "float". |
| string | Name of the class that can be used to wrap variables of the given type. |
Definition at line 150 of file Styling.php.
| Erebot\Styling::getTranslator | ( | ) |
Returns the translator associated with this formatter.
| Erebot::IntlInterface | Translator associated with this formatter. |
Implements Erebot\StylingInterface.
Definition at line 265 of file Styling.php.
|
private |
This method is used to apply the parsing method to children of an XML node.
| DOMNode | $node | The node being parsed. |
| array | $attributes | Array of styling attributes. |
| array | $vars | Template variables that can be injected in the result. |
| string | Parsing result, with styles applied as appropriate. |
Definition at line 652 of file Styling.php.
|
protected |
This is the main parsing method.
| DOMNode | $node | The node being parsed. |
| array | $attributes | Array of styling attributes. |
| array | $vars | Template variables that can be injected in the return. |
| string | Parsing result, with styles applied as appropriate. |
Definition at line 401 of file Styling.php.
|
staticprotected |
Parses a template into a DOM.
| string | $source | Template to parse. |
| Erebot::DOM | DOM object constructed from the template. |
| ::InvalidArgumentException | The template was malformed or invalid. |
Definition at line 353 of file Styling.php.
| Erebot\Styling::render | ( | $template, | |
| array | $vars = array() |
||
| ) |
Renders a template using the given variables.
| string | $template | A template to render. |
| array | $vars | (optional) An array of variables that can be used to change the way the template will be rendered. |
| string | The formatted result for this template. |
Implements Erebot\StylingInterface.
Definition at line 223 of file Styling.php.
| Erebot\Styling::setClass | ( | $type, | |
| $cls | |||
| ) |
Sets the class to use to wrap a certain scalar type.
| string | $type | Name of a scalar type that can be wrapped by this class automatically. Must be one of "int", "string" or "float". |
| string | $cls | Name of the class that can be used to wrap variables of the given type. |
Definition at line 170 of file Styling.php.
|
protected |
Wraps a scalar into the appropriate styling object.
| mixed | $var | Either a scalar, an array or an object implementing the Erebot::Styling::VariableInterface interface. Scalar values will be wrapped with the appropriate object while arrays and objects are returned untouched. |
| string | $name | Name of given variable. |
| array | If $var referred to an array, it is returned without any modification. |
| ::Erebot::Styling::VariableInterface_Variable | Objects that implement Erebot::Styling::VariableInterface are returned without any modification. Scalar values are wrapped into the appropriate object implementing the Erebot::Styling::VariableInterface interface and the resulting object is returned. |
| ::InvalidArgumentException | Either the given name is invalid, or the given value was not a scalar. |
Definition at line 304 of file Styling.php.