Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/HamlPHP/HamlPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down