From dd651c0d9209ced63eb0c87740d23b263bef6e75 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 30 May 2013 17:13:33 -0400 Subject: Updated the option naming so the serializer and parser can share the same default option setup and have it still make sense. --- src/HTML5.php | 20 ++++++++++++++------ src/HTML5/Serializer/OutputRules.php | 4 ++-- src/HTML5/Serializer/Traverser.php | 8 ++++---- 3 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/HTML5.php b/src/HTML5.php index df552f4..a471c96 100644 --- a/src/HTML5.php +++ b/src/HTML5.php @@ -19,8 +19,12 @@ use HTML5\Serializer\Serializer; class HTML5 { public static $options = array( - 'encode' => FALSE, - 'rules' => '\HTML5\Serializer\OutputRules', + + // If the serializer should encode all entities. + 'encode_entities' => FALSE, + + // The class the serializer should use for the output rules. + 'output_rules' => '\HTML5\Serializer\OutputRules', ); /** @@ -89,15 +93,17 @@ class HTML5 { * The filename to be written. * @param array $options * Configuration options when serializing the DOM. These include: - * - rules: The class with the serializer writing rules. Defaults to + * - output_rules: The class with the serializer writing rules. Defaults to * \HTML5\Serializer\OutputRules. The standard rules are representative of the * original document. This can be replaced by alternatives that can * minify or make other alterations. - * - encode: Text written to the output is escaped by default and not all + * - encode_entities: Text written to the output is escaped by default and not all * entities are encoded. If this is set to TRUE all entities will be encoded. * Defaults to FALSE. */ public static function save($dom, $file, $options = array()) { + // Passing all the default options is intentional. This way a custom + // rule set can have default options passed in if needed. $options = $options + self::options(); $serializer = new \HTML5\Serializer\Serializer($dom, $options); return $serializer->save($file); @@ -110,11 +116,11 @@ class HTML5 { * The DOM to be serialized. * @param array $options * Configuration options when serializing the DOM. These include: - * - rules: The class with the serializer writing rules. Defaults to + * - output_rules: The class with the serializer writing rules. Defaults to * \HTML5\Serializer\OutputRules. The standard rules are representative of the * original document. This can be replaced by alternatives that can * minify or make other alterations. - * - encode: Text written to the output is escaped by default and not all + * - encode_entities: Text written to the output is escaped by default and not all * entities are encoded. If this is set to TRUE all entities will be encoded. * Defaults to FALSE. * @@ -122,6 +128,8 @@ class HTML5 { * A HTML5 documented generated from the DOM. */ public static function saveHTML($dom, $options = array()) { + // Passing all the default options is intentional. This way a custom + // rule set can have default options passed in if needed. $options = $options + self::options(); $serializer = new \HTML5\Serializer\Serializer($dom, $options); return $serializer->saveHTML(); diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 364f093..075c027 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -21,8 +21,8 @@ class OutputRules implements \HTML5\Serializer\RulesInterface { public function __construct($traverser, $output, $options = array()) { $this->traverser = $traverser; - if (isset($options['encode'])) { - $this->encode = $options['encode']; + if (isset($options['encode_entities'])) { + $this->encode = $options['encode_entities']; } $this->out = $output; diff --git a/src/HTML5/Serializer/Traverser.php b/src/HTML5/Serializer/Traverser.php index 65c5e2f..ae3c10f 100644 --- a/src/HTML5/Serializer/Traverser.php +++ b/src/HTML5/Serializer/Traverser.php @@ -35,19 +35,19 @@ class Traverser { * stream. * @param array $options * An array or options for the traverser as key/value pairs. These include: - * - encode: A bool to specify if full encding should happen for all named + * - encode_entities: A bool to specify if full encding should happen for all named * charachter references. Defaults to FALSE which escapes &'<>". - * - rules: The path to the class handling the output rules. + * - output_rules: The path to the class handling the output rules. */ public function __construct($dom, $out, $options = array()) { $this->dom = $dom; $this->out = $out; $this->options = $options; - if (!isset($this->options['rules'])) { + if (!isset($this->options['output_rules'])) { throw new \HTML5\Exception('No Rules specified for output generation.'); } - $rulesClass = $this->options['rules']; + $rulesClass = $this->options['output_rules']; $this->rules = new $rulesClass($this, $out, $this->options); } -- cgit v1.2.3