-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from oat-sa/features/fragment-prefixes
Provides a way to client code to render PHP fragment with prefixes.
- Loading branch information
Showing
2 changed files
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,11 @@ | |
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* Copyright (c) 2013-2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
* @author Jérôme Bogaerts <[email protected]> | ||
* @license GPLv2 | ||
* | ||
* | ||
* | ||
*/ | ||
|
||
namespace qtism\runtime\rendering\markup; | ||
|
@@ -58,6 +56,13 @@ class MarkupPostRenderer implements Renderable | |
* @var array | ||
*/ | ||
private $fragments; | ||
|
||
/** | ||
* Template fragments path prefix. | ||
* | ||
* @var string | ||
*/ | ||
private $fragmentPrefix = ''; | ||
|
||
/** | ||
* Create a new MarkupPostRenderer object. | ||
|
@@ -160,6 +165,24 @@ protected function setFragments(array $fragments) | |
{ | ||
$this->fragments = $fragments; | ||
} | ||
|
||
/** | ||
* Set the prefix to be used for fragment file names. | ||
* | ||
* @param string $fragmentPrefix. | ||
*/ | ||
public function setFragmentPrefix($fragmentPrefix) | ||
{ | ||
$this->fragmentPrefix = $fragmentPrefix; | ||
} | ||
|
||
/** | ||
* Get the prefix to be used for fragment file names. | ||
*/ | ||
protected function getFragmentPrefix() | ||
{ | ||
return $this->fragmentPrefix; | ||
} | ||
|
||
public function render($document) | ||
{ | ||
|
@@ -187,7 +210,7 @@ public function render($document) | |
} | ||
|
||
/* | ||
* 2. Transform qtism-if, qtism-printVariable statements into PHP statements. | ||
* 2. Transform qtism-if, qtism-printVariable, qtism-include statements into PHP statements. | ||
*/ | ||
if ($this->isTemplateOriented() === true) { | ||
$output = preg_replace('/<!--\s+qtism-if\s*\((.+?)\)\s*:\s+-->/iu', '<?php if (\1): ?>', $output); | ||
|
@@ -198,12 +221,13 @@ public function render($document) | |
$output = preg_replace('/<!--\s+qtism-printVariable\((.+?)\)\s+-->/iu', $call, $output); | ||
|
||
$matches = array(); | ||
$fragmentPrefix = $this->getFragmentPrefix(); | ||
if (($c = preg_match_all('/<!--\s+(?:qtism-include)\s*\((?:(\$.+?), ([0-9]+), "(.+?)", ([0-9]+?))\)\s*:\s+-->(.+?)<!--\s+qtism-endinclude\s+-->/ius', $output, $matches)) > 0) { | ||
$fragments = $this->getFragments(); | ||
for ($i = 0; $i < $c; $i++) { | ||
$output = str_replace($matches[0][$i], '<?php include(dirname(__FILE__) . "/' . $matches[2][$i] . '-" . ' . $matches[1][$i] . '->getShuffledChoiceIdentifierAt(' . $matches[2][$i] . ', ' . $matches[4][$i] . ') . ".phtml"); ?>', $output); | ||
$output = str_replace($matches[0][$i], '<?php include(dirname(__FILE__) . "/' . $fragmentPrefix . $matches[2][$i] . '-" . ' . $matches[1][$i] . '->getShuffledChoiceIdentifierAt(' . $matches[2][$i] . ', ' . $matches[4][$i] . ') . ".phtml"); ?>', $output); | ||
$fragments[] = array( | ||
'path' => $matches[2][$i] . '-' . $matches[3][$i] . '.phtml', | ||
'path' => $fragmentPrefix . $matches[2][$i] . '-' . $matches[3][$i] . '.phtml', | ||
'content' => $matches[5][$i] | ||
); | ||
} | ||
|