<commit_before><?php
/**
 * PHPFrame/Document/HTMLRenderer.php
 * 
 * PHP version 5
 * 
 * @category  PHPFrame
 * @package   Document
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009 The PHPFrame Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/phpframe/source/browse/PHPFrame
 */

/**
 * HTML Renderer Class
 * 
 * @category PHPFrame
 * @package  Document
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://code.google.com/p/phpframe/source/browse/PHPFrame
 * @see      PHPFrame_IRenderer
 * @since    1.0
 */
class PHPFrame_HTMLRenderer implements PHPFrame_IRenderer
{
	private $_views_path;
	
	public function __construct($views_path)
	{
		$this->_views_path = $views_path;
	}
	
    public function render($value)
    {
        $str = $value;
        
        if ($value instanceof PHPFrame_View) {
            $str = $this->renderView($value);
        }
        
        return $str;
    }
    
    /**
     * Render view and store in document's body
     * 
     * @param PHPFrame_View $view The view object to process.
     * 
     * @return void
     * @since  1.0
     */
    public function renderView(PHPFrame_View $view) 
    {
        $tmpl_path = $this->_views_path.DS.$view->getName().".php";
        
        if (is_file($tmpl_path)) {
            // Start buffering
            ob_start();
            // set view data as local array
            $data = $view->getData();
            // Include template file
            require_once $tmpl_path;
            // save buffer in body property
            $str = ob_get_contents();
            // clean output buffer
            ob_end_clean();
        } else {
            throw new RuntimeException("Layout template file ".$tmpl_path." not found.");
        }
        
        return $str;
    }
    
    /**
     * Render a partial view
     * 
     * @param string $name
     * 
     * @return void
     * @since  1.0
     */
    public function renderPartial($name)
    {
        $name = trim((string) $name);
        $path = $this->_views_path.DS."partials".DS.$name;
        
        if (!is_file($path)) {
            $path .= ".php";
            if (!is_file($path)) {
                return;
            }
        }
        
        // Start buffering
        ob_start();
        // Include partial file<commit_msg>Updated html renderer to allow a data array to be passed to partials.<commit_after><?php
/**
 * PHPFrame/Document/HTMLRenderer.php
 * 
 * PHP version 5
 * 
 * @category  PHPFrame
 * @package   Document
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009 The PHPFrame Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/phpframe/source/browse/PHPFrame
 */

/**
 * HTML Renderer Class
 * 
 * @category PHPFrame
 * @package  Document
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://code.google.com/p/phpframe/source/browse/PHPFrame
 * @see      PHPFrame_IRenderer
 * @since    1.0
 */
class PHPFrame_HTMLRenderer implements PHPFrame_IRenderer
{
	private $_views_path;
	
	public function __construct($views_path)
	{
		$this->_views_path = $views_path;
	}
	
    public function render($value)
    {
        $str = $value;
        
        if ($value instanceof PHPFrame_View) {
            $str = $this->renderView($value);
        }
        
        return $str;
    }
    
    /**
     * Render view and store in document's body
     * 
     * @param PHPFrame_View $view The view object to process.
     * 
     * @return void
     * @since  1.0
     */
    public function renderView(PHPFrame_View $view) 
    {
        $tmpl_path = $this->_views_path.DS.$view->getName().".php";
        
        if (is_file($tmpl_path)) {
            // Start buffering
            ob_start();
            // set view data as local array
            $data = $view->getData();
            // Include template file
            require_once $tmpl_path;
            // save buffer in body property
            $str = ob_get_contents();
            // clean output buffer
            ob_end_clean();
        } else {
            throw new RuntimeException("Layout template file ".$tmpl_path." not found.");
        }
        
        return $str;
    }
    
    /**
     * Render a partial view
     * 
     * @param string $name The partial name.
     * @param array  $data An associative array with data to be passed to the 
     *                     partial view.
     * 
     * @return void
     * @since  1.0
     */
    public function renderPartial($name, array $data=null)
    {
        $name = trim((string) $name);
        $path = $this->_views_path.DS."partials".DS.$name;
        
        if (!is_file($path)) {
            $path .= ".php";
            if (!is_file($path)) {
                return;
            }
        }
        
        // Start buffering
        ob_start();
        // Include partial file
{'fraction_non_alphanumeric': 0.12237762237762238, 'fraction_numerical': 0.004273504273504274, 'mean_word_length': 1.7653061224489797, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2123931', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1520, 'n_words': 369}