/** * `$indent` should set the rule indentation width. */ public function testIndent() { $css = <<<CSS .tag { prop: val; } CSS; $this->assertEquals($css, nl_writeCSS(array('tag' => array('prop' => 'val')), null, 4)); }
/** * Update the exhibit stylesheet with values from a specific record. For * example, if `styles` is: * * .tag { * fill-color: #111111; * stroke-color: #222222; * } * * And the record is tagged with `tag` has a `fill_color` of `#333333` and * a `stroke_color` of `#444444`, the stylesheet would be updated to: * * .tag { * fill-color: #333333; * stroke-color: #444444; * } * * @param NeatlineRecord $record The record to update from. */ public function pullStyles($record) { // Parse the stylesheet. $css = nl_readCSS($this->styles); // Explode record tags. $tags = nl_explode($record->tags); // Gather style columns. $valid = nl_getStyles(); foreach ($css as $selector => $rules) { // Is the record tagged with the selector? if (in_array($selector, $tags) || $selector == 'all') { // Scan valid rule definitions. foreach ($rules as $prop => $val) { // Is the property valid? if (in_array($prop, $valid)) { // Get the record value. $value = !is_null($record->{$prop}) ? $record->{$prop} : 'none'; // Update the CSS. $css[$selector][$prop] = $value; } } } } // Recompile the stylesheet. $this->styles = nl_writeCSS($css); }