From f992d9315e72c12e8ff3c2f5a875c2af0ba8e34c Mon Sep 17 00:00:00 2001 From: XEdP3X Date: Mon, 19 Jan 2015 15:51:18 +0100 Subject: [PATCH] parse HAML by a given string --- src/HamlPHP/HamlPHP.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/HamlPHP/HamlPHP.php b/src/HamlPHP/HamlPHP.php index e3d4ec0..d80a6d2 100644 --- a/src/HamlPHP/HamlPHP.php +++ b/src/HamlPHP/HamlPHP.php @@ -188,6 +188,35 @@ public function parseFile($fileName) // not using cache return $this->_compiler->parseFile($fileName); } + + /** + * Parses a haml string and returns the compile result. + * + * @param string $string + */ + public function parseString($string) + { + if($this->_cacheEnabled) + { + if ($this->_storage === null) { + throw new Exception('Storage not set'); + } + + $fileId = $this->_storage->generateContentId(sha1($string)); + + if ($this->isCacheEnabled() + && $this->_storage->isFresh($fileId, sha1($string))) { + return $this->_storage->fetch($fileId); + } + + // file is not fresh, so compile and cache it + $this->_storage->cache($fileId, $this->_compiler->parseString($string)); + return $this->_storage->fetch($fileId); + } + + // not using cache + return $this->_compiler->parseString($string); + } public function evaluate($content, array $contentVariables = array()) {