Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature/parser driver - Issue #217 Parser becomes a driver #2158

Open
wants to merge 1 commit into from

8 participants

ragboyjr Andrey Andreev Malte N William Knauss Andre Castro Michael Instructor, Computer Systems Technology Kabir Hossain
ragboyjr

Hola brochachos! If this meets CI specs, then we just need to update the userguide src, and we be good.

RJ

ragboyjr

K, It seems my last commit isn't running through travis, but I finally installed phpunit (not so easy on mac 10.8.2), and ran the tests myself, and the Parser_test passed. So I think all that is left is the user guide src, but I'd rather wait until this last commit gets approved.

Andrey Andreev
Owner

I don't have the time at the moment to properly review this, but the relevant documentation must be updated together with every feature change/addition.

On the current diff from a quick look I can only tell this - you must not use the private keyword for anything as it makes classes harder to extend, which is not our intent. Change those occurences to protected.

I'm also not sure if a config file is needed.

ragboyjr

K, I've updated the userguide and changelog, I pretty much modeled the parser driver after the session driver.

Andrey Andreev narfbg referenced this pull request
Closed

If-Statement in a View #2184

Malte N

This definitly has to be in the next release! But could you also include some custom drivers, like smarty?

ragboyjr

Yeah, I've already created a few third party drivers for this: smarty, dwoo, mustache, raintpl (my personal favorite), and twig. I don't know exactly where we will put these third party drivers. Once/if this feature gets pushed through into CI 3.0, I think I'll contact each third party tpl maker and have them host each driver and instructions on how to install and whatnot.

If you aren't sold on smarty as a driver, I'd suggest looking at raintpl, it's very lightweigh especially compared to smarty which is a monolith.
http://www.raintpl.com

Malte N

If you aren't sold on smarty as a driver, I'd suggest looking at raintpl, it's very lightweigh especially compared to smarty which is a monolith.

RainTPL seems to be exactly want I want, thanks ...
But I think it will be to complicated to implement it in my current project, I'll wait until this PR comes out with CI 3.0.

I don't know exactly where we will put these third party drivers.

If you mean the driver classes, you could simply create a folder /system/core/driver/.
If you mean the core/system classes of each template engine, I would force the user to upload a folder to the /application/third_party/<template_name> folder.

... , I think I'll contact each third party tpl maker and have them host each driver and instructions on how to install and whatnot.

Do you mean the authors of the template engines? I think you shouldnt force them to create some code, the simpliest way would be to create a page in the user guide to show the people how to integrate a custom template engine.
Anyway, this is the feature I have searched the most in CI, please merge this branch to the official.

PS: Could you upload your drivers for the few template engines? I would really like to merge your CI branch with my project, so I can use this function before 3.0 releases.

ragboyjr

Is there anything I need to do to get this feature going?

Malte N

Is there anything I need to do to get this feature going?

Hopefull, but anyway, could you please open the library and custom template engine drivers for download?

William Knauss

I agree with @hice3000 would @ragboyjr be so kind as to release the custom drivers under a separate repository?

ragboyjr

If you go to my CI repo brach third_party_parsers I have a really rough version of those parser drivers. I can do some more work on them later today or tomorrow

Malte N

OK I copied new files from your repo to my project, and there are 2 things that sticked out:

  1. NetBeans said that there is an error in The Dwoo Driver
  2. It works with the simple driver, but not with the RainTPL driver: Fatal error: Cannot call constructor in C:\xampp\htdocs\application\libraries\Parser\drivers\Parser_raintpl.php on line 60
ragboyjr

In regards to the third party parsers, I created a repo where we can hammer everything out and make issues accordingly - ragboyjr/Codeigniter-third_party_parsers@cd37224

Andre Castro

Will this be implemented in v3?

Instructor, Computer Systems Technology
Owner

This looks like a bit of a can of worms! Unless someone is willing to dive into the issue and PR, this should wait until post V3

RJ Garcia Converting the parser library to a driver
Signed-off-by: RJ Garcia <rjgarcia@Whits-MacBook-Air.local>

Adding Mock library class for Parser_simple driver
Signed-off-by: RJ garcia <rj@bighead.net>
04749de
ragboyjr

I'm not going to be able to finish this feature due to other work; however, I just rebased this branch on top of develop, and squashed everything into 1 commit. So that should help somebody else if they want to finish development on this feature.

Kabir Hossain

When CodeIgniter alpha_numeric is used to validated a user name like kabir12 or kabir_sd
then if I put like 123 then It takes my input because alpha_numeric try alpha or numeric.

So I hope codeigniter v3 will be added to validated a good scope to validated a user name so that the user can not put down 123 but he can kabir123.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 11, 2014
  1. ragboyjr

    Converting the parser library to a driver

    RJ Garcia authored ragboyjr committed
    Signed-off-by: RJ Garcia <rjgarcia@Whits-MacBook-Air.local>
    
    Adding Mock library class for Parser_simple driver
    Signed-off-by: RJ garcia <rj@bighead.net>
This page is out of date. Refresh to see the latest.
11 application/config/config.php
View
@@ -491,6 +491,17 @@
*/
$config['rewrite_short_tags'] = FALSE;
+/*
+|--------------------------------------------------------------------------
+| Parser Variables
+|--------------------------------------------------------------------------
+|
+| 'parser_driver' = The driver to load: simple driver (default)
+| 'parser_valid_drivers' = additional valid drivers which may be loaded
+|
+*/
+$config['parser_driver'] = 'simple';
+$config['parser_valid_drivers'] = array();
/*
|--------------------------------------------------------------------------
2  system/libraries/Driver.php
View
@@ -181,7 +181,7 @@ public function load_driver($child)
show_error($msg);
}
}
-
+
// Instantiate, decorate and add child
$obj = new $class_name();
$obj->decorate($this);
277 system/libraries/Parser/Parser.php
View
@@ -0,0 +1,277 @@
+<?php
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+defined('BASEPATH') OR exit('No direct script access allowed');
+
+/**
+ * Parser Class
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category Parser
+ * @author EllisLab Dev Team
+ * @link http://codeigniter.com/user_guide/libraries/parser.html
+ */
+class CI_Parser extends CI_Driver_Library {
+
+ /**
+ * Initialization parameters
+ *
+ * @var array
+ */
+ public $params = array();
+
+ /**
+ * Valid parser drivers
+ *
+ * @var array
+ */
+ protected $valid_drivers = array(
+ 'simple'
+ );
+
+ /**
+ * Reference to the driver
+ *
+ * @var mixed
+ */
+ protected $driver;
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Class constructor
+ *
+ * @return void
+ */
+ public function __construct(array $params = array())
+ {
+ $CI = &get_instance();
+
+ $tmp_vdrivers = array_map('strtolower', $this->valid_drivers);
+
+ // load up the valid drivers
+ $drivers = isset($params['parser_valid_drivers']) ? $params['parser_valid_drivers'] : $CI->config->item('parser_valid_drivers');
+ if ($drivers)
+ {
+ // Add driver names to valid list
+ foreach ((array) $drivers as $driver)
+ {
+ if ( ! in_array(strtolower($driver), $tmp_vdrivers))
+ {
+ $this->valid_drivers[] = $driver;
+ }
+ }
+ }
+
+ // Get driver to load
+ $driver = isset($params['parser_driver']) ? $params['parser_driver'] : $CI->config->item('parser_driver');
+ if ( ! $driver)
+ {
+ $driver = 'simple';
+ }
+
+ // if the driver isn't already in the valid_drivers then we add it here
+ if ( ! in_array(strtolower($driver), array_map('strtolower', $tmp_vdrivers)))
+ {
+ $this->valid_drivers[] = $driver;
+ }
+
+ // Save a copy of parameters in case drivers need access
+ $this->params = $params;
+
+ // Load driver and get array reference
+ $this->driver = $this->load_driver($driver);
+ }
+
+ /**
+ * Parse a template
+ *
+ * Parses pseudo-variables contained in the specified template view,
+ * replacing them with the data in the second param. Returns the loaded view
+ * as string
+ *
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ public function parse($template, $data = array(), $return = FALSE)
+ {
+ return $this->driver->parse($template, $data, $return);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Parse a String
+ *
+ * Parses pseudo-variables contained in the specified string,
+ * replacing them with the data in the second param
+ *
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ public function parse_string($template, $data = array(), $return = FALSE)
+ {
+ return $this->driver->parse_string($template, $data, $return);
+ }
+
+ /**
+ * __get magic method
+ *
+ * Any property references to the parser driver will default to calling the specified
+ * adapter
+ *
+ * @param string
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ if (property_exists($this->driver, $name))
+ {
+ return $this->driver->{$name};
+ }
+
+ return NULL;
+ }
+
+ /**
+ * __call magic method
+ *
+ * Any call to the parser driver will default to calling the specified adapter
+ *
+ * @param string
+ * @param array
+ * @return mixed
+ */
+ public function __call($method, $args = array())
+ {
+ if (method_exists($this->driver, $method))
+ {
+ return call_user_func_array(array($this->driver, $method), $args);
+ }
+
+ return NULL;
+ }
+}
+
+/**
+ * CI_Parser_driver Class
+ *
+ * Extend this class to make a new CI_Parser driver
+ * Making a new driver is fairly simple, the only two methods required are parse and parse_string.
+ *
+ * The parse method will parse the specified file with the given data and will either
+ * return the parsed data or output data to the browser (using echo, print, printf, by appending
+ * the output to the CI output class, etc...)
+ *
+ * The parse_string method does the same thing the parse method does except that it parses
+ * a given string and not a file.
+ *
+ * Due to the nature of how CI drivers are loaded, you can't access the "parent" drivers
+ * properties in the constructor of your driver. However, if you overload the initialize
+ * method then you can init your class AND use the "parent" drivers properties.
+ *
+ * Parse and parse_string MUST be defined in the new driver or else a php fatal error will be
+ * thrown due to the nature of abstract methods. If it's not feasible for your parser driver
+ * to support this functionality, then define each method to return true.
+ * e.g.
+ * public function parse($template, $data = array(), $return = FALSE){return TRUE;}
+ * public function parse_string($template, $data = array(), $return = FALSE){return TRUE;}
+ *
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+abstract class CI_Parser_driver extends CI_Driver {
+
+ /**
+ * Parse a template file
+ *
+ * Parses pseudo-variables contained in the specified template view,
+ * replacing them with the data in the second param. Thrid param specifies
+ * wheter or not to return data or echo for output.
+ *
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ abstract public function parse($template, $data = array(), $return = FALSE);
+
+ /**
+ * Parse a template string
+ *
+ * Parses pseudo-variables contained in the specified template string,
+ * replacing them with the data in the second param. Thrid param specifies
+ * wheter or not to return data or echo for output. Can be very useful for templates
+ * stored in a database
+ *
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ abstract public function parse_string($template, $data = array(), $return = FALSE);
+
+ /**
+ * Initialize driver
+ *
+ * @return void
+ */
+ protected function initialize()
+ {
+ // Overload this method to implement initialization
+ }
+
+ /**
+ * Decorate
+ *
+ * Decorates the child with the parent driver lib's methods and properties
+ *
+ * @param object Parent library object
+ * @return void
+ */
+ public function decorate($parent)
+ {
+ // Call base class decorate first
+ parent::decorate($parent);
+
+ // Call initialize method now that driver has access to $this->_parent
+ $this->initialize();
+ }
+}
+
+/* End of file Parser.php */
+/* Location: ./system/libraries/Parser/Parser.php */
127 system/libraries/Parser.php → system/libraries/Parser/drivers/Parser_simple.php 100644 → 100755
View
@@ -4,35 +4,24 @@
*
* An open source application development framework for PHP 5.2.4 or newer
*
- * This content is released under the MIT License (MIT)
+ * NOTICE OF LICENSE
*
- * Copyright (c) 2014, British Columbia Institute of Technology
+ * Licensed under the Open Software License version 3.0
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
*
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * @package CodeIgniter
- * @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
- * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/)
- * @license http://opensource.org/licenses/MIT MIT License
- * @link http://codeigniter.com
- * @since Version 1.0.0
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
+ * @link http://codeigniter.com
+ * @since Version 1.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
@@ -46,17 +35,17 @@
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/libraries/parser.html
*/
-class CI_Parser {
+class CI_Parser_simple extends CI_Parser_driver {
/**
- * Left delimiter character for pseudo vars
+ * Left delimeter character for psuedo vars
*
* @var string
*/
public $l_delim = '{';
/**
- * Right delimiter character for pseudo vars
+ * Right delimeter character for psuedo vars
*
* @var string
*/
@@ -94,7 +83,7 @@ public function __construct()
* @param bool
* @return string
*/
- public function parse($template, $data, $return = FALSE)
+ public function parse($template, $data = array(), $return = FALSE)
{
$template = $this->CI->load->view($template, $data, TRUE);
@@ -114,7 +103,7 @@ public function parse($template, $data, $return = FALSE)
* @param bool
* @return string
*/
- public function parse_string($template, $data, $return = FALSE)
+ public function parse_string($template, $data = array(), $return = FALSE)
{
return $this->_parse($template, $data, $return);
}
@@ -139,20 +128,13 @@ protected function _parse($template, $data, $return = FALSE)
return FALSE;
}
- $replace = array();
foreach ($data as $key => $val)
{
- $replace = array_merge(
- $replace,
- is_array($val)
+ $template = is_array($val)
? $this->_parse_pair($key, $val, $template)
- : $this->_parse_single($key, (string) $val, $template)
- );
+ : $template = $this->_parse_single($key, (string) $val, $template);
}
- unset($data);
- $template = strtr($template, $replace);
-
if ($return === FALSE)
{
$this->CI->output->append_output($template);
@@ -188,7 +170,7 @@ public function set_delimiters($l = '{', $r = '}')
*/
protected function _parse_single($key, $val, $string)
{
- return array($this->l_delim.$key.$this->r_delim => (string) $val);
+ return str_replace($this->l_delim.$key.$this->r_delim, (string) $val, $string);
}
// --------------------------------------------------------------------
@@ -205,46 +187,45 @@ protected function _parse_single($key, $val, $string)
*/
protected function _parse_pair($variable, $data, $string)
{
- $replace = array();
- preg_match_all(
- '#'.preg_quote($this->l_delim.$variable.$this->r_delim).'(.+?)'.preg_quote($this->l_delim.'/'.$variable.$this->r_delim).'#s',
- $string,
- $matches,
- PREG_SET_ORDER
- );
-
- foreach ($matches as $match)
+ if (FALSE === ($match = $this->_match_pair($string, $variable)))
{
- $str = '';
- foreach ($data as $row)
+ return $string;
+ }
+
+ $str = '';
+ foreach ($data as $row)
+ {
+ $temp = $match[1];
+ foreach ($row as $key => $val)
{
- $temp = array();
- foreach ($row as $key => $val)
- {
- if (is_array($val))
- {
- $pair = $this->_parse_pair($key, $val, $match[1]);
- if ( ! empty($pair))
- {
- $temp = array_merge($temp, $pair);
- }
-
- continue;
- }
-
- $temp[$this->l_delim.$key.$this->r_delim] = $val;
- }
-
- $str .= strtr($match[1], $temp);
+ $temp = is_array($val)
+ ? $this->_parse_pair($key, $val, $temp)
+ : $this->_parse_single($key, $val, $temp);
}
- $replace[$match[0]] = $str;
+ $str .= $temp;
}
- return $replace;
+ return str_replace($match[0], $str, $string);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Matches a variable pair
+ *
+ * @param string
+ * @param string
+ * @return mixed
+ */
+ protected function _match_pair($string, $variable)
+ {
+ return preg_match('|'.preg_quote($this->l_delim).$variable.preg_quote($this->r_delim).'(.+?)'.preg_quote($this->l_delim).'/'.$variable.preg_quote($this->r_delim).'|s',
+ $string, $match)
+ ? $match : FALSE;
}
}
/* End of file Parser.php */
-/* Location: ./system/libraries/Parser.php */
+/* Location: ./system/libraries/Parser/drivers/Parser_simple.php */
10 system/libraries/Parser/index.html
View
@@ -0,0 +1,10 @@
+<html>
+<head>
+ <title>403 Forbidden</title>
+</head>
+<body>
+
+<p>Directory access is forbidden.</p>
+
+</body>
+</html>
16 tests/codeigniter/libraries/Parser_test.php
View
@@ -4,8 +4,20 @@ class Parser_test extends CI_TestCase {
public function set_up()
{
- $this->parser = new CI_Parser();
+ // Set our subclass prefix
+ $this->subclass = 'Mock_Libraries_';
+ $this->ci_set_config('subclass_prefix', $this->subclass);
+
+ // Establish necessary support classes
+ $ci = $this->ci_instance();
+ $ldr = $this->ci_core_class('load');
+ $ci->load = new $ldr();
+
+ // pass in a useless array to bypass loading from config file
+ $config = array('tmp' => 'no_val');
+ $this->parser = new Mock_Libraries_Parser($config);
$this->ci_instance_var('parser', $this->parser);
+
}
// --------------------------------------------------------------------
@@ -92,4 +104,4 @@ private function _mismatched_var_pair()
$this->assertEquals($result, $this->parser->parse_string($template, $data, TRUE));
}
-}
+}
4 tests/mocks/autoloader.php
View
@@ -56,7 +56,7 @@ function autoload($class)
'Zip'
);
- $ci_drivers = array('Session', 'Cache');
+ $ci_drivers = array('Session', 'Cache', 'Parser');
if (strpos($class, 'Mock_') === 0)
{
@@ -116,4 +116,4 @@ function autoload($class)
}
include_once($file);
-}
+}
5 tests/mocks/libraries/parser.php
View
@@ -0,0 +1,5 @@
+<?php
+
+class Mock_Libraries_Parser extends CI_Parser {}
+
+class Mock_Libraries_Parser_simple extends CI_Parser_simple {}
5 user_guide_src/source/changelog.rst
View
@@ -422,6 +422,11 @@ Release Date: Not Released
- :doc:`Zip Library <libraries/zip>` method ``read_file()`` can now also alter the original file path/name while adding files to an archive.
- :doc:`Trackback Library <libraries/trackback>` method ``receive()`` will now utilize ``iconv()`` if it is available but ``mb_convert_encoding()`` is not.
+ - :doc:`Parser Library <libraries/parsers>` changes include:
+ - Library changed to :doc:`Driver <general/drivers>` with classic Simple driver as default.
+ - Added default ``$config['parser_driver']`` and ``$config['parser_valid_drivers']`` items to *config.php* file.
+ - Added ability for any undefined method/property called to parser to run to the parser driver
+
- Core
- :doc:`Routing <general/routing>` changes include:
113 user_guide_src/source/libraries/parser.rst
View
@@ -1,9 +1,43 @@
-#####################
-Template Parser Class
-#####################
+######################
+Template Parser Driver
+######################
-The Template Parser Class enables you to parse pseudo-variables
-contained within your view files. It can parse simple variables or
+The Template Parser Driver enables you to parse pseudo-variables
+contained within your view files. CodeIgniter offers one driver
+out of the box called `Simple Driver`_ which is the same as the
+Parser class in older versions of CodeIgniter.
+
+.. note:: CodeIgniter does **not** require you to use this class since
+ using pure PHP in your view pages lets them run a little faster.
+ However, some developers prefer to use a template engine if they work
+ with designers who they feel would find some confusion working with PHP.
+
+.. important:: The Template Parser Class is **not** a full-blown
+ template parsing solution. We've kept it very lean on purpose in order
+ to maintain maximum performance.
+
+
+Initializing the Class
+======================
+
+Like most other drivers in CodeIgniter, the Parser class is initialized
+in your controller using the $this->load->driver function::
+
+ $this->load->driver('parser');
+
+Once loaded, the Parser driver object will be available using:
+$this->parser
+
+Parser Drivers
+==============
+
+The only driver available through CodeIgniter is the `Simple Driver`_. However, adding
+drivers is a relatively easy and is explained further down on this page.
+
+Simple Driver
+-------------
+
+The simple parser can parse simple variables or
variable tag pairs. If you've never used a template engine,
pseudo-variables look like this::
@@ -79,8 +113,14 @@ third parameter::
$string = $this->parser->parse('blog_template', $data, TRUE);
+$this->parser->parse_string()
+-----------------------------
+
+This method works exactly like parse(), only accepts a string as the
+first parameter in place of a view file.
+
Variable Pairs
-==============
+--------------
The above example code allows simple variables to be replaced. What if
you would like an entire block of variables to be repeated, with each
@@ -176,4 +216,63 @@ Class Reference
:param string $r: Right delimiter
:rtype: void
- Sets the delimiters (opening and closing) for a value "tag" in a template.
+ Sets the delimiters (opening and closing) for a value "tag" in a template.
+
+Custom Drivers
+==============
+
+You may also :doc:`create your own <../general/creating_drivers>` custom
+parser drivers. A parser driver is basically just a template engine like: smarty, dwoo,
+raintpl, and mustache.
+
+To make a new driver, extend CI_Parser_driver. Overload the initialize()
+method (instead of using a constructor) and be able to parse templates.
+Each driver needs to be able to parse a template file and parse a template string.
+
+Your initial class might look like::
+
+ class CI_Parser_custom extends CI_Parser_driver {
+ // optional
+ protected function initialize()
+ {
+ // Initialize variables from $this->_parent->params
+ // create a reference to the template engine object
+ // etc...
+ }
+
+ // required
+ public function parse($template, $data = array(), $return = FALSE)
+ {
+ // parse a template file
+ }
+
+ // required
+ public function parse_string($template, $data = array(), $return = FALSE)
+ {
+ // parse a string
+ }
+ }
+
+Put your driver in the libraries/Parser/drivers folder anywhere in your
+package paths. This includes the application directory, the system directory,
+or any path you add with $CI->load->add_package_path(). Your driver must be
+named CI_Parser_<name>, and your filename must be Parser_<name>.php,
+preferably also capitalized, such as::
+
+ CI_Parser_foo in libraries/Parser/drivers/Parser_foo.php
+
+Then specify the driver by setting 'parser_driver' in your config.php file or as a
+parameter when loading the CI_Parser object::
+
+ $config['parser_driver'] = 'foo';
+
+OR::
+
+ $CI->load->driver('parser', array('parser_driver' => 'foo'));
+
+The driver specified by 'parser_driver' is automatically included as a valid
+driver. However, if you want to make a custom driver available as an option
+without making it the initially loaded driver, set 'parser_valid_drivers' in
+your config.php file to an array including your driver name::
+
+ $config['parser_valid_drivers'] = array('parser_driver');
Something went wrong with that request. Please try again.