Commit c417fe27 by seldaek

unify line endings to LF and set svn:eol-style to native on all files

git-svn-id: http://svn.dwoo.org/trunk@322 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent f65127b4
<?php <?php
App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php')); App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php'));
/** /**
* Dwoo adapter for CakePHP * Dwoo adapter for CakePHP
* *
* Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com> * Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com>
* *
* This software is provided 'as-is', without any express or implied warranty. * This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software. * In no event will the authors be held liable for any damages arising from the use of this software.
* *
* This file is released under the LGPL * This file is released under the LGPL
* "GNU Lesser General Public License" * "GNU Lesser General Public License"
* More information can be found here: * More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html} * {@link http://www.gnu.org/copyleft/lesser.html}
* *
* @author Mark John S. Buenconsejo <mjwork@simpleteq.com> * @author Mark John S. Buenconsejo <mjwork@simpleteq.com>
* @author Giangi <giangi@qwerg.com> * @author Giangi <giangi@qwerg.com>
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano * @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/ * @link http://dwoo.org/
* @version 1.1.0 * @version 1.1.0
* @date 2009-07-18 * @date 2009-07-18
* @package Dwoo * @package Dwoo
*/ */
class DwooView extends View class DwooView extends View
{ {
protected $_sv_template_dir; protected $_sv_template_dir;
protected $_sv_layout_dir; protected $_sv_layout_dir;
protected $_sv_compile_dir; protected $_sv_compile_dir;
protected $_sv_cache_dir; protected $_sv_cache_dir;
protected $_sv_compile_id; protected $_sv_compile_id;
protected $_dwoo; protected $_dwoo;
public $sv_processedTpl; public $sv_processedTpl;
public function __construct(&$controller) public function __construct(&$controller)
{ {
parent::__construct($controller); parent::__construct($controller);
$this->ext = '.tpl'; $this->ext = '.tpl';
$this->_sv_template_dir = array $this->_sv_template_dir = array
( (
VIEWS . $this->viewPath . DS . $this->subDir, VIEWS . $this->viewPath . DS . $this->subDir,
VIEWS . $this->viewPath, VIEWS . $this->viewPath,
VIEWS VIEWS
); );
$this->_sv_layout_dir = array $this->_sv_layout_dir = array
( (
LAYOUTS . $this->subDir, LAYOUTS . $this->subDir,
VIEWS VIEWS
); );
$this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile'; $this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile';
$this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache'; $this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache';
$this->_dwoo = new Dwoo($this->_sv_compile_dir, $this->_sv_cache_dir); $this->_dwoo = new Dwoo($this->_sv_compile_dir, $this->_sv_cache_dir);
$this->_sv_compile_id = $controller->name; $this->_sv_compile_id = $controller->name;
$this->_dwoo->sv_this = $this; $this->_dwoo->sv_this = $this;
$this->_dwoo->setSecurityPolicy(); $this->_dwoo->setSecurityPolicy();
return; return;
} }
/** /**
* changes the template directory * changes the template directory
*/ */
public function setTemplateDir($path = VIEW) { public function setTemplateDir($path = VIEW) {
$old = $this->_sv_template_dir; $old = $this->_sv_template_dir;
$this->_sv_template_dir = $path; $this->_sv_template_dir = $path;
return $old; return $old;
} }
public function getTemplateDir() { public function getTemplateDir() {
return $this->_sv_template_dir ; return $this->_sv_template_dir ;
} }
public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true) public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true)
{ {
// let's determine if this is a layout call or a template call // let's determine if this is a layout call or a template call
// and change the template dir accordingly // and change the template dir accordingly
$layout = false; $layout = false;
if(isset($___data_for_view['content_for_layout'])) { if(isset($___data_for_view['content_for_layout'])) {
$this->_sv_template_dir = $this->_sv_layout_dir; $this->_sv_template_dir = $this->_sv_layout_dir;
$layout = true; $layout = true;
} }
$tpl = new Dwoo_Template_File($___viewFn); $tpl = new Dwoo_Template_File($___viewFn);
$data = $___data_for_view; $data = $___data_for_view;
$data['view'] = $this; $data['view'] = $this;
if ($this->helpers != false && $loadHelpers === true) { if ($this->helpers != false && $loadHelpers === true) {
$loadedHelpers = array(); $loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach (array_keys($loadedHelpers) as $helper) { foreach (array_keys($loadedHelpers) as $helper) {
$camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1); $camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1);
${$camelBackedHelper} = $loadedHelpers[$helper]; ${$camelBackedHelper} = $loadedHelpers[$helper];
if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) { if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) {
$subHelpers = ${$camelBackedHelper}->helpers; $subHelpers = ${$camelBackedHelper}->helpers;
foreach ($subHelpers as $subHelper) { foreach ($subHelpers as $subHelper) {
${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper]; ${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper];
} }
} }
if(isset($this->passedArgs)) { if(isset($this->passedArgs)) {
${$camelBackedHelper}->passedArgs = $this->passedArgs; ${$camelBackedHelper}->passedArgs = $this->passedArgs;
} }
$this->loaded[$camelBackedHelper] = ${$camelBackedHelper}; $this->loaded[$camelBackedHelper] = ${$camelBackedHelper};
$data[$camelBackedHelper] = ${$camelBackedHelper}; $data[$camelBackedHelper] = ${$camelBackedHelper};
} }
} }
if ($this->helpers != false && $loadHelpers === true) { if ($this->helpers != false && $loadHelpers === true) {
foreach ($loadedHelpers as $helper) { foreach ($loadedHelpers as $helper) {
if (is_object($helper)) { if (is_object($helper)) {
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) { if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
$helper->beforeRender(); $helper->beforeRender();
} }
} }
} }
} }
return $this->_dwoo->get($tpl, $data); return $this->_dwoo->get($tpl, $data);
} }
public function get(){ public function get(){
return $this->_dwoo; return $this->_dwoo;
} }
} }
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php <?php
/** /**
* Defines a sub-template that can then be called (even recursively) with the defined arguments * Defines a sub-template that can then be called (even recursively) with the defined arguments
* <pre> * <pre>
* * name : template name * * name : template name
* * rest : list of arguments and optional default values * * rest : list of arguments and optional default values
* </pre> * </pre>
* This software is provided 'as-is', without any express or implied warranty. * This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software. * In no event will the authors be held liable for any damages arising from the use of this software.
* *
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano * @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License * @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/ * @link http://dwoo.org/
* @version 1.1.0 * @version 1.1.0
* @date 2009-07-18 * @date 2009-07-18
* @package Dwoo * @package Dwoo
*/ */
class Dwoo_Plugin_template extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block class Dwoo_Plugin_template extends Dwoo_Block_Plugin implements Dwoo_ICompilable_Block
{ {
public function init($name, array $rest = array()) public function init($name, array $rest = array())
{ {
} }
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type) public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
{ {
$params = $compiler->getCompiledParams($params); $params = $compiler->getCompiledParams($params);
$parsedParams = array(); $parsedParams = array();
if (!isset($params['*'])) if (!isset($params['*']))
$params['*'] = array(); $params['*'] = array();
foreach ($params['*'] as $param=>$defValue) { foreach ($params['*'] as $param=>$defValue) {
if (is_numeric($param)) { if (is_numeric($param)) {
$param = $defValue; $param = $defValue;
$defValue = null; $defValue = null;
} }
$param = trim($param, '\'"'); $param = trim($param, '\'"');
if (!preg_match('#^[a-z0-9_]+$#i', $param)) { if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _'); throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
} }
$parsedParams[$param] = $defValue; $parsedParams[$param] = $defValue;
} }
$params['name'] = substr($params['name'], 1, -1); $params['name'] = substr($params['name'], 1, -1);
$params['*'] = $parsedParams; $params['*'] = $parsedParams;
$params['uuid'] = uniqid(); $params['uuid'] = uniqid();
$compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']); $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
$currentBlock =& $compiler->getCurrentBlock(); $currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params'] = $params; $currentBlock['params'] = $params;
return ''; return '';
} }
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content) public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{ {
$paramstr = 'Dwoo $dwoo'; $paramstr = 'Dwoo $dwoo';
$init = 'static $_callCnt = 0;'."\n". $init = 'static $_callCnt = 0;'."\n".
'$dwoo->scope[\' '.$params['uuid'].'\'.$_callCnt] = array();'."\n". '$dwoo->scope[\' '.$params['uuid'].'\'.$_callCnt] = array();'."\n".
'$_scope = $dwoo->setScope(array(\' '.$params['uuid'].'\'.($_callCnt++)));'."\n"; '$_scope = $dwoo->setScope(array(\' '.$params['uuid'].'\'.($_callCnt++)));'."\n";
$cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);'; $cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);';
foreach ($params['*'] as $param=>$defValue) { foreach ($params['*'] as $param=>$defValue) {
if ($defValue === null) { if ($defValue === null) {
$paramstr.=', $'.$param; $paramstr.=', $'.$param;
} else { } else {
$paramstr.=', $'.$param.' = '.$defValue; $paramstr.=', $'.$param.' = '.$defValue;
} }
$init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n"; $init .= '$dwoo->scope[\''.$param.'\'] = $'.$param.";\n";
} }
$init .= '/* -- template start output */'; $init .= '/* -- template start output */';
$funcName = 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid']; $funcName = 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'];
$search = array( $search = array(
'$this->charset', '$this->charset',
'$this->', '$this->',
'$this,', '$this,',
); );
$replacement = array( $replacement = array(
'$dwoo->getCharset()', '$dwoo->getCharset()',
'$dwoo->', '$dwoo->',
'$dwoo,', '$dwoo,',
); );
$content = str_replace($search, $replacement, $content); $content = str_replace($search, $replacement, $content);
$body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE. $body = 'if (!function_exists(\''.$funcName."')) {\nfunction ".$funcName.'('.$paramstr.') {'."\n$init".Dwoo_Compiler::PHP_CLOSE.
$prepend.$content.$append. $prepend.$content.$append.
Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}"; Dwoo_Compiler::PHP_OPEN.$cleanup."\n}\n}";
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body); $compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment