Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function render($viewName, Model $model, NotificationCenter $notificationCenter, $output = true)
 {
     Profile::start('Renderer', 'Generate HTML');
     $templateName = $viewName . '.' . static::$templateFileExtension;
     $dwoo = new Dwoo($this->compiledPath, $this->cachePath);
     $dwoo->getLoader()->addDirectory($this->functionsPath);
     Profile::start('Renderer', 'Create template file.');
     $template = new Dwoo_Template_File($templateName);
     $template->setIncludePath($this->getTemplatesPath());
     Profile::stop();
     Profile::start('Renderer', 'Render');
     $dwooData = new Dwoo_Data();
     $dwooData->setData($model->getData());
     $dwooData->assign('errorMessages', $notificationCenter->getErrors());
     $dwooData->assign('successMessages', $notificationCenter->getSuccesses());
     $this->setHeader('Content-type: text/html', $output);
     // I do never output directly from dwoo to have the possibility to show an error page if there was a render error.
     $result = $rendered = $dwoo->get($template, $dwooData, null, false);
     if ($output) {
         echo $result;
     }
     Profile::stop();
     Profile::stop();
     return $output ? null : $rendered;
 }
Esempio n. 2
0
 public function testSetMergeAndClear()
 {
     $data = new Dwoo_Data();
     $data->setData(array('foo'));
     $this->assertEquals(array('foo'), $data->getData());
     $data->mergeData(array('baz'), array('bar', 'boo' => 'moo'));
     $this->assertEquals(array('foo', 'baz', 'bar', 'boo' => 'moo'), $data->getData());
     $data->clear();
     $this->assertEquals(array(), $data->getData());
 }
Esempio n. 3
0
    /**
     *  Parse
     *
     * Parses pseudo-variables contained in the specified template,
     * replacing them with the data in the second param
     *
     * @access	public
     * @param	string
     * @param	array
     * @param	bool
     * @param	string
     * @return	string
     */
    public function _parse_compiled($string, $data, $return = FALSE, $cache_id = NULL)
    {
        // Start benchmark
        $this->_ci->benchmark->mark('dwoo_parse_start');
        // Convert from object to array
        if (!is_array($data)) {
            $data = (array) $data;
        }
        $data = array_merge($this->_ci->load->get_vars(), $data);
        foreach ($this->_parser_assign_refs as $ref) {
            $data[$ref] =& $this->_ci->{$ref};
        }
        // Object containing data
        $dwoo_data = new Dwoo_Data();
        $dwoo_data->setData($data);
        $parsed_string = '';
        try {
            // Object of the template
            $tpl = new Dwoo_Template_String($string, NULL, $cache_id, NULL);
            $dwoo = !isset($this->_dwoo) ? self::spawn() : $this->_dwoo;
            // check for existence of dwoo object... may not be there if folder is not writable
            // added by David McReynolds @ Daylight Studio 1/20/11
            if (!empty($dwoo)) {
                // Create the compiler instance
                $compiler = new Dwoo_Compiler();
                // added by David McReynolds @ Daylight Studio 1/22/12
                $compiler->setDelimiters($this->l_delim, $this->r_delim);
                //Add a pre-processor to help fix javascript {}
                // added by David McReynolds @ Daylight Studio 11/04/10
                $callback = create_function('$compiler', '
					$string = $compiler->getTemplateSource();
					
					$callback = create_function(\'$matches\',
						\'if (isset($matches[1]))
						{
							$str = "<script";
							$str .= preg_replace("#\\' . $this->l_delim . '([^s])#ms", "' . $this->l_delim . ' $1", $matches[1]);
							$str .= "</script>";
							return $str;
						}
						else
						{
							return $matches[0];
						}
						\'
						);

					$string = preg_replace_callback("#<script(.+)</script>#Ums", $callback, $string);
					$compiler->setTemplateSource($string);
					return $string;
				');
                $compiler->addPreProcessor($callback);
                // render the template
                $parsed_string = $dwoo->get($tpl, $dwoo_data, $compiler);
            } else {
                // load FUEL language file because it has the proper error
                // added by David McReynolds @ Daylight Studio 1/20/11
                $this->_ci->load->module_language(FUEL_FOLDER, 'fuel');
                throw new Exception(lang('error_folder_not_writable', $this->_ci->config->item('cache_path')));
            }
        } catch (Exception $e) {
            if (strtolower(get_class($e)) == 'dwoo_exception') {
                echo '<div class="error">' . $e->getMessage() . '</div>';
            } else {
                show_error($e->getMessage());
            }
        }
        // Finish benchmark
        $this->_ci->benchmark->mark('dwoo_parse_end');
        // Return results or not ?
        if (!$return) {
            $this->_ci->output->append_output($parsed_string);
            return;
        }
        return $parsed_string;
    }
Esempio n. 4
0
 /**
  *  Parse
  *
  * Parses pseudo-variables contained in the specified template,
  * replacing them with the data in the second param
  *
  * @access	public
  * @param	string
  * @param	array
  * @param	bool
  * @return	string
  */
 function _parse($string, $data, $return = FALSE, $is_include = FALSE)
 {
     // Start benchmark
     $this->_ci->benchmark->mark('dwoo_parse_start');
     // Convert from object to array
     if (!is_array($data)) {
         $data = (array) $data;
     }
     $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
     foreach ($this->_parser_assign_refs as $ref) {
         $data[$ref] =& $this->_ci->{$ref};
     }
     // Object containing data
     $dwoo_data = new Dwoo_Data();
     $dwoo_data->setData($data);
     try {
         // Object of the template
         $tpl = new Dwoo_Template_String($string);
         $dwoo = $is_include ? self::spawn() : $this->_dwoo;
         // render the template
         $parsed_string = $dwoo->get($tpl, $dwoo_data);
     } catch (Exception $e) {
         show_error($e);
     }
     // Finish benchmark
     $this->_ci->benchmark->mark('dwoo_parse_end');
     // Return results or not ?
     if (!$return) {
         $this->_ci->output->append_output($parsed_string);
         return;
     }
     return $parsed_string;
 }
Esempio n. 5
0
 /**
  *  Parse
  *
  * Parses pseudo-variables contained in the specified template,
  * replacing them with the data in the second param
  *
  * @access	public
  * @param	string
  * @param	array
  * @param	bool
  * @return	string
  */
 function _parse($string, $data, $return = FALSE)
 {
     // Start benchmark
     $this->ci->benchmark->mark('dwoo_parse_start');
     // Compatibility with PyroCMS v0.9.7 style links
     // TODO: Remove this for v1.0
     $string = preg_replace('/\\{page_url\\[([0-9]+)\\]\\}/', '{page_url($1)}', $string);
     // Convert from object to array
     if (!is_array($data)) {
         $data = (array) $data;
     }
     $data = array_merge($data, $this->ci->load->_ci_cached_vars);
     $data['ci'] =& $this->ci;
     // Object containing data
     $dwoo_data = new Dwoo_Data();
     $dwoo_data->setData($data);
     try {
         // Object of the template
         $tpl = new Dwoo_Template_String($string);
         // render the template
         $parsed_string = $this->dwoo->get($tpl, $dwoo_data);
     } catch (Dwoo_Compilation_Exception $e) {
         show_error($e);
     }
     // Finish benchmark
     $this->ci->benchmark->mark('dwoo_parse_end');
     // Return results or not ?
     if (!$return) {
         $this->ci->output->append_output($parsed_string);
         return;
     }
     return $parsed_string;
 }
Esempio n. 6
0
 /**
  *  Parse
  *
  * Parses pseudo-variables contained in the specified template,
  * replacing them with the data in the second param
  *
  * @access	public
  * @param	string
  * @param	array
  * @param	bool
  * @return	string
  */
 function _parse($string, $data, $return = FALSE, $is_include = FALSE)
 {
     // Start benchmark
     $this->_ci->benchmark->mark('dwoo_parse_start');
     // Convert from object to array
     if (!is_array($data)) {
         $data = (array) $data;
     }
     $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
     // TAG SUPPORT
     $this->_ci->load->library('tags');
     $this->_ci->tags->set_trigger('pyro:');
     $parsed = $this->_ci->tags->parse($string, $data, array($this, 'parser_callback'));
     // END TAG SUPPORT
     foreach ($this->_parser_assign_refs as $ref) {
         $data[$ref] =& $this->_ci->{$ref};
     }
     // --------------------------------------------------------------------
     // Parse out the elapsed time and memory usage,
     // then swap the pseudo-variables with the data
     $elapsed = $this->_ci->benchmark->elapsed_time('total_execution_time_start', 'total_execution_time_end');
     if (CI_VERSION < 2 or $this->_ci->output->parse_exec_vars === TRUE) {
         $memory = !function_exists('memory_get_usage') ? '0' : round(memory_get_usage() / 1024 / 1024, 2) . 'MB';
         $parsed['content'] = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsed, $memory), $parsed['content']);
     }
     // --------------------------------------------------------------------
     // Object containing data
     $dwoo_data = new Dwoo_Data();
     $dwoo_data->setData($data);
     try {
         // Object of the template
         $tpl = new Dwoo_Template_String($parsed['content']);
         $dwoo = $is_include ? self::spawn() : $this->_dwoo;
         // render the template
         $parsed_string = $dwoo->get($tpl, $dwoo_data);
     } catch (Exception $e) {
         show_error($e);
     }
     // Finish benchmark
     $this->_ci->benchmark->mark('dwoo_parse_end');
     // Return results or not ?
     if (!$return) {
         $this->_ci->output->append_output($parsed_string);
         return;
     }
     return $parsed_string;
 }
Esempio n. 7
0
    /**
     *  Parse
     *
     * Parses pseudo-variables contained in the specified template,
     * replacing them with the data in the second param
     *
     * @access	public
     * @param	string
     * @param	array
     * @param	bool
     * @return	string
     */
    function _parse($string, $data, $return = FALSE, $is_include = FALSE)
    {
        // Start benchmark
        $this->_ci->benchmark->mark('dwoo_parse_start');
        // Convert from object to array
        if (!is_array($data)) {
            $data = (array) $data;
        }
        $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
        foreach ($this->_parser_assign_refs as $ref) {
            $data[$ref] =& $this->_ci->{$ref};
        }
        // Object containing data
        $dwoo_data = new Dwoo_Data();
        $dwoo_data->setData($data);
        try {
            // Object of the template
            $tpl = new Dwoo_Template_String($string);
            $dwoo = $is_include ? self::spawn() : $this->_dwoo;
            // Create the compiler instance
            $compiler = new Dwoo_Compiler();
            //Add a pre-processor to help fix javascript {}
            // added by David McReynolds @ Daylight Studio 11/04/10 to prevent problems of axing the entire directory
            $callback = create_function('$compiler', '
				$string = $compiler->getTemplateSource();
				$string = preg_replace("#{\\s*}#", "{\\n}", $string); 
				$compiler->setTemplateSource($string);
				return $string;
			');
            $compiler->addPreProcessor($callback);
            // render the template
            $parsed_string = $dwoo->get($tpl, $dwoo_data, $compiler);
        } catch (Exception $e) {
            show_error($e);
        }
        // Finish benchmark
        $this->_ci->benchmark->mark('dwoo_parse_end');
        // Return results or not ?
        if (!$return) {
            $this->_ci->output->append_output($parsed_string);
            return;
        }
        return $parsed_string;
    }