You are here

private function HamlParser::parseDoctype in Sassy 7

* Parse a doctype declaration *

Parameters

array line to parse: * @param HamlNode parent node * @return HamlDoctypeNode

1 call to HamlParser::parseDoctype()
HamlParser::parseLine in phamlp/haml/HamlParser.php
* Parse a line of Haml into a HamlNode for the document tree *

File

phamlp/haml/HamlParser.php, line 1125

Class

HamlParser
HamlParser class. Parses {@link http://haml-lang.com/ Haml} view files. @package PHamlP @subpackage Haml

Code

private function parseDoctype($line, $parent) {
  $content = explode(' ', $line[self::HAML_CONTENT]);
  if (!empty($content)) {
    if ($content[0] === self::IS_XML_PROLOG) {
      $encoding = isset($content[1]) ? $content[1] : self::DEFAULT_XML_ENCODING;
      $output = str_replace(self::XML_ENCODING, $encoding, self::XML_PROLOG);
    }
    elseif (empty($content[0])) {
      $output = $this->doctypes[$this->format][0];
    }
    elseif (array_key_exists($content[0], $this->doctypes[$this->format])) {
      $output = $this->doctypes[$this->format][$content[0]];
    }
    elseif (!empty($this->doctype)) {
      $output = $this->doctype;
    }
    else {
      $_doctypes = array_keys($this->doctypes[$this->format]);
      array_shift($_doctypes);
      throw new HamlException('Invalid {what} ({value}); must be one of "{options}"', array(
        '{what}' => 'doctype',
        '{value}' => $content[0],
        '{options}' => join(', ', $_doctypes) . ' or empty',
      ), $this);
    }
  }
  return new HamlDoctypeNode($output, $parent);
}