[Cs-content-commits] SF.net SVN: cs-content:[356] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2009-02-04 17:31:25
|
Revision: 356
http://cs-content.svn.sourceforge.net/cs-content/?rev=356&view=rev
Author: crazedsanity
Date: 2009-02-04 17:31:19 +0000 (Wed, 04 Feb 2009)
Log Message:
-----------
Changes for stripping undefined template vars.
NOTE::: these changes are mostly for ease in processing when returning parsed
templates via ajax (CS-Project does this).
/cs_genericPage.class.php:
* strip_undef_template_vars():
-- ARG CHANGE: RENAMED ARG: #1 (now is "$templateContents")
-- template contents must be fed to it instead of specifying a section
to retrieve template contents.
* strip_undef_template_vars_from_section() [NEW]:
-- similar to what strip_undef_template_vars() was previously, except it
this one applies changes to that section before returning the new value.
/tests/testOfCSContent.php:
* test_genericPage():
-- updated tests to handle change in the two methods listed above.
Modified Paths:
--------------
trunk/1.0/cs_genericPage.class.php
trunk/1.0/tests/testOfCSContent.php
Modified: trunk/1.0/cs_genericPage.class.php
===================================================================
--- trunk/1.0/cs_genericPage.class.php 2009-02-04 17:04:36 UTC (rev 355)
+++ trunk/1.0/cs_genericPage.class.php 2009-02-04 17:31:19 UTC (rev 356)
@@ -640,32 +640,40 @@
//-------------------------------------------------------------------------
- public function strip_undef_template_vars($section='content') {
+ public function strip_undef_template_vars($templateContents) {
$numLoops = 0;
- if(isset($this->templateVars[$section])) {
- $templateContents = $this->templateVars[$section];
- while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) {
- $tags = $tags[0];
-
- //TODO: figure out why this works when running it twice.
- foreach($tags as $key=>$str) {
- $str2 = str_replace("{", "", $str);
- $str2 = str_replace("}", "", $str2);
- if(!$this->templateVars[$str2]) {
- //TODO: set an internal pointer or something to use here, so they can see what was missed.
- $templateContents = str_replace($str, '', $templateContents);
- }
+ while(preg_match_all('/\{.\S+?\}/', $templateContents, $tags) && $numLoops < 50) {
+ $tags = $tags[0];
+
+ //TODO: figure out why this works when running it twice.
+ foreach($tags as $key=>$str) {
+ $str2 = str_replace("{", "", $str);
+ $str2 = str_replace("}", "", $str2);
+ if(!$this->templateVars[$str2]) {
+ //TODO: set an internal pointer or something to use here, so they can see what was missed.
+ $templateContents = str_replace($str, '', $templateContents);
}
- $this->templateObj->parse("out", "out");
- $numLoops++;
}
+ $numLoops++;
}
+ return($templateContents);
+ }//end strip_undef_template_vars()
+ //-------------------------------------------------------------------------
+
+
+
+ //-------------------------------------------------------------------------
+ public function strip_undef_template_vars_from_section($section='content') {
+ if(isset($this->templateVars[$section])) {
+ $this->templateVars[$section] = $this->strip_undef_template_vars($this->templateVars[$section]);
+ }
else {
throw new exception(__METHOD__ .": section (". $section .") does not exist");
}
- return($templateContents);
+
+ return($this->templateVars[$section]);
+ }//strip_undef_template_vars_from_section()
//-------------------------------------------------------------------------
- }
}//end cs_genericPage{}
?>
Modified: trunk/1.0/tests/testOfCSContent.php
===================================================================
--- trunk/1.0/tests/testOfCSContent.php 2009-02-04 17:04:36 UTC (rev 355)
+++ trunk/1.0/tests/testOfCSContent.php 2009-02-04 17:31:19 UTC (rev 356)
@@ -293,9 +293,9 @@
$this->assertNotEqual($page->templateVars, $page2->templateVars);
$page2 = clone $page;
- $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content'));
- $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars('content'));
- $page2->templateVars['content'] = $page2->strip_undef_template_vars('content');
+ $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content']));
+ $this->assertNotEqual($page2->templateVars['content'], $page2->strip_undef_template_vars($page2->templateVars['content']));
+ $page2->templateVars['content'] = $page2->strip_undef_template_vars($page2->templateVars['content']);
$this->assertEqual($page->return_printed_page(1), $page2->return_printed_page(1));
}//end test_genericPage
//-------------------------------------------------------------------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|