From 98ec8ea11a8df6f3593b0836bcfce6fb769b9a23 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 22 Jun 2010 07:11:33 -0400 Subject: [PATCH 1/9] Fixed protected property in PragmaEscaped example (should be public) --- examples/pragma_unescaped/PragmaUnescaped.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pragma_unescaped/PragmaUnescaped.php b/examples/pragma_unescaped/PragmaUnescaped.php index 59681a8..b4e0e21 100644 --- a/examples/pragma_unescaped/PragmaUnescaped.php +++ b/examples/pragma_unescaped/PragmaUnescaped.php @@ -1,5 +1,5 @@ Shark'; + public $vs = 'Bear > Shark'; } \ No newline at end of file From b096cb108d856b570fdc1bad234da0103ae17d9d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 22 Jun 2010 07:13:17 -0400 Subject: [PATCH 2/9] fix for PHPUnit 3.5.0 - no longer including PHPUnit/Framework.php in tests. --- test/MustachePragmaDotNotationTest.php | 1 - test/MustachePragmaTest.php | 1 - test/MustachePragmaUnescapedTest.php | 1 - test/MustacheTest.php | 1 - 4 files changed, 4 deletions(-) diff --git a/test/MustachePragmaDotNotationTest.php b/test/MustachePragmaDotNotationTest.php index 65195b6..488962b 100644 --- a/test/MustachePragmaDotNotationTest.php +++ b/test/MustachePragmaDotNotationTest.php @@ -1,7 +1,6 @@ Date: Mon, 5 Jul 2010 23:29:28 -0400 Subject: [PATCH 3/9] Fix for examples directory iterator in PHP 5.2. Future-proof things a bit by actually checking for file extension before accessing that index. --- test/MustacheTest.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index c05b15b..bd055f7 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -262,22 +262,24 @@ class MustacheTest extends PHPUnit_Framework_TestCase { foreach ($children as $file) { if (!$file->isFile()) continue; - $filename = $file->getPathInfo(); + $filename = $file->getPathname(); $info = pathinfo($filename); - switch($info['extension']) { - case 'php': - $class = $info['filename']; - include_once($filename); - break; + if (isset($info['extension'])) { + switch($info['extension']) { + case 'php': + $class = $info['filename']; + include_once($filename); + break; - case 'mustache': - $template = file_get_contents($filename); - break; + case 'mustache': + $template = file_get_contents($filename); + break; - case 'txt': - $output = file_get_contents($filename); - break; + case 'txt': + $output = file_get_contents($filename); + break; + } } } From 6084a37a3ce9e79386b099a34119d6d394dab3e0 Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Mon, 5 Jul 2010 17:50:41 -0500 Subject: [PATCH 4/9] Adding examples for object sections --- .../Sections_Iterable_Object.php | 17 +++++++++++ .../sections.mustache | 6 ++++ .../sections_iterable_object/sections.txt | 4 +++ .../Sections_Noniterable_Object.php | 29 +++++++++++++++++++ .../sections.mustache | 6 ++++ .../sections_noniterable_object/sections.txt | 4 +++ 6 files changed, 66 insertions(+) create mode 100644 examples/sections_iterable_object/Sections_Iterable_Object.php create mode 100644 examples/sections_iterable_object/sections.mustache create mode 100644 examples/sections_iterable_object/sections.txt create mode 100644 examples/sections_noniterable_object/Sections_Noniterable_Object.php create mode 100644 examples/sections_noniterable_object/sections.mustache create mode 100644 examples/sections_noniterable_object/sections.txt diff --git a/examples/sections_iterable_object/Sections_Iterable_Object.php b/examples/sections_iterable_object/Sections_Iterable_Object.php new file mode 100644 index 0000000..ee2f661 --- /dev/null +++ b/examples/sections_iterable_object/Sections_Iterable_Object.php @@ -0,0 +1,17 @@ + 'And it worked the second time.', + 'bar' => 'As well as the third.' + ); + + public function __get($key) + { + return isset($this->_data[$key]) ? $this->_data[$key] : NULL; + } + + public function __isset($key) + { + return isset($this->_data[$key]); + } +} \ No newline at end of file diff --git a/examples/sections_noniterable_object/sections.mustache b/examples/sections_noniterable_object/sections.mustache new file mode 100644 index 0000000..9119608 --- /dev/null +++ b/examples/sections_noniterable_object/sections.mustache @@ -0,0 +1,6 @@ +* {{ start }} +{{# middle }} +* {{ foo }} +* {{ bar }} +{{/ middle }} +* {{ final }} \ No newline at end of file diff --git a/examples/sections_noniterable_object/sections.txt b/examples/sections_noniterable_object/sections.txt new file mode 100644 index 0000000..e6b2d7a --- /dev/null +++ b/examples/sections_noniterable_object/sections.txt @@ -0,0 +1,4 @@ +* It worked the first time. +* And it worked the second time. +* As well as the third. +* Then, surprisingly, it worked the final time. \ No newline at end of file From c45550e9e5924da6471781d267a06b26d66cd064 Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Mon, 5 Jul 2010 20:20:41 -0500 Subject: [PATCH 5/9] Fixing #3, Transversable objects should be iterated over. --- Mustache.php | 2 +- .../Sections_Iterator_Object.php | 41 +++++++++++++++++++ .../sections.mustache | 5 +++ .../sections_iterator_object/sections.txt | 4 ++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/sections_iterator_object/Sections_Iterator_Object.php create mode 100644 examples/sections_iterator_object/sections.mustache create mode 100644 examples/sections_iterator_object/sections.txt diff --git a/Mustache.php b/Mustache.php index 88727c5..f06edca 100644 --- a/Mustache.php +++ b/Mustache.php @@ -597,7 +597,7 @@ class Mustache { * @return bool */ protected function _varIsIterable($var) { - return is_object($var) || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var)))); + return $var instanceof Traversable || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var)))); } } diff --git a/examples/sections_iterator_object/Sections_Iterator_Object.php b/examples/sections_iterator_object/Sections_Iterator_Object.php new file mode 100644 index 0000000..e517fe0 --- /dev/null +++ b/examples/sections_iterator_object/Sections_Iterator_Object.php @@ -0,0 +1,41 @@ + 'And it worked the second time.'), + array('item' => 'As well as the third.'), + ); + + public function rewind() { + $this->_position = 0; + } + + public function current() { + return $this->_data[$this->_position]; + } + + public function key() { + return $this->_position; + } + + public function next() { + ++$this->_position; + } + + public function valid() { + return isset($this->_data[$this->_position]); + } +} \ No newline at end of file diff --git a/examples/sections_iterator_object/sections.mustache b/examples/sections_iterator_object/sections.mustache new file mode 100644 index 0000000..44dfce4 --- /dev/null +++ b/examples/sections_iterator_object/sections.mustache @@ -0,0 +1,5 @@ +* {{ start }} +{{# middle }} +* {{ item }} +{{/ middle }} +* {{ final }} \ No newline at end of file diff --git a/examples/sections_iterator_object/sections.txt b/examples/sections_iterator_object/sections.txt new file mode 100644 index 0000000..e6b2d7a --- /dev/null +++ b/examples/sections_iterator_object/sections.txt @@ -0,0 +1,4 @@ +* It worked the first time. +* And it worked the second time. +* As well as the third. +* Then, surprisingly, it worked the final time. \ No newline at end of file From 5186d0bc18dede6ea0c7022046dc7842dc370f5d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Mon, 5 Jul 2010 21:13:08 -0400 Subject: [PATCH 6/9] Test case for #3 (_varIsIterable issues). --- test/MustacheObjectSectionTest.php | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/MustacheObjectSectionTest.php diff --git a/test/MustacheObjectSectionTest.php b/test/MustacheObjectSectionTest.php new file mode 100644 index 0000000..58d4286 --- /dev/null +++ b/test/MustacheObjectSectionTest.php @@ -0,0 +1,56 @@ +assertEquals('Foo', $alpha->render('{{#foo}}{{name}}{{/foo}}')); + } + + public function testObjectWithGet() { + $beta = new Beta(); + $this->assertEquals('Foo', $beta->render('{{#foo}}{{name}}{{/foo}}')); + } + + public function testSectionObjectWithGet() { + $gamma = new Gamma(); + $this->assertEquals('Foo', $gamma->render('{{#bar}}{{#foo}}{{name}}{{/foo}}{{/bar}}')); + } +} + +class Alpha extends Mustache { + public $foo; + + public function __construct() { + $this->foo = new StdClass(); + $this->foo->name = 'Foo'; + $this->foo->number = 1; + } +} + +class Beta extends Mustache { + protected $_data = array(); + + public function __construct() { + $this->_data['foo'] = new StdClass(); + $this->_data['foo']->name = 'Foo'; + $this->_data['foo']->number = 1; + } + + public function __isset($name) { + return array_key_exists($name, $this->_data); + } + + public function __get($name) { + return $this->_data[$name]; + } +} + +class Gamma extends Mustache { + public $bar; + + public function __construct() { + $this->bar = new Beta(); + } +} \ No newline at end of file From c2c01cf964536b9c3ffdd30eaf1073980812449f Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 6 Jul 2010 10:09:00 -0400 Subject: [PATCH 7/9] only test examples which find a php class. --- test/MustacheTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index bd055f7..a877c03 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -283,7 +283,9 @@ class MustacheTest extends PHPUnit_Framework_TestCase { } } - $ret[$example] = array($class, $template, $output); + if (!empty($class)) { + $ret[$example] = array($class, $template, $output); + } } $files->next(); From 2cfb8aefc107c38293c822a1e2175561254e4cb8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 6 Jul 2010 10:17:04 -0400 Subject: [PATCH 8/9] Rename section object tests to work with upcoming autoload-template feature. Clean up code to match style. --- .../SectionIteratorObject.php} | 7 +++---- .../section_iterator_object.mustache} | 0 .../section_iterator_object.txt} | 0 .../SectionMagicObject.php} | 13 +++++-------- .../section_magic_object.mustache} | 0 .../section_magic_object.txt} | 0 .../SectionObjects.php} | 7 +++---- .../section_objects.mustache} | 0 .../section_objects.txt} | 0 9 files changed, 11 insertions(+), 16 deletions(-) rename examples/{sections_iterator_object/Sections_Iterator_Object.php => section_iterator_objects/SectionIteratorObject.php} (83%) rename examples/{sections_iterator_object/sections.mustache => section_iterator_objects/section_iterator_object.mustache} (100%) rename examples/{sections_iterable_object/sections.txt => section_iterator_objects/section_iterator_object.txt} (100%) rename examples/{sections_noniterable_object/Sections_Noniterable_Object.php => section_magic_objects/SectionMagicObject.php} (67%) rename examples/{sections_iterable_object/sections.mustache => section_magic_objects/section_magic_object.mustache} (100%) rename examples/{sections_iterator_object/sections.txt => section_magic_objects/section_magic_object.txt} (100%) rename examples/{sections_iterable_object/Sections_Iterable_Object.php => section_objects/SectionObjects.php} (70%) rename examples/{sections_noniterable_object/sections.mustache => section_objects/section_objects.mustache} (100%) rename examples/{sections_noniterable_object/sections.txt => section_objects/section_objects.txt} (100%) diff --git a/examples/sections_iterator_object/Sections_Iterator_Object.php b/examples/section_iterator_objects/SectionIteratorObject.php similarity index 83% rename from examples/sections_iterator_object/Sections_Iterator_Object.php rename to examples/section_iterator_objects/SectionIteratorObject.php index e517fe0..5a592ab 100644 --- a/examples/sections_iterator_object/Sections_Iterator_Object.php +++ b/examples/section_iterator_objects/SectionIteratorObject.php @@ -1,17 +1,16 @@ 'And it worked the second time.', 'bar' => 'As well as the third.' ); - public function __get($key) - { + public function __get($key) { return isset($this->_data[$key]) ? $this->_data[$key] : NULL; } - public function __isset($key) - { + public function __isset($key) { return isset($this->_data[$key]); } } \ No newline at end of file diff --git a/examples/sections_iterable_object/sections.mustache b/examples/section_magic_objects/section_magic_object.mustache similarity index 100% rename from examples/sections_iterable_object/sections.mustache rename to examples/section_magic_objects/section_magic_object.mustache diff --git a/examples/sections_iterator_object/sections.txt b/examples/section_magic_objects/section_magic_object.txt similarity index 100% rename from examples/sections_iterator_object/sections.txt rename to examples/section_magic_objects/section_magic_object.txt diff --git a/examples/sections_iterable_object/Sections_Iterable_Object.php b/examples/section_objects/SectionObjects.php similarity index 70% rename from examples/sections_iterable_object/Sections_Iterable_Object.php rename to examples/section_objects/SectionObjects.php index ee2f661..41b7d84 100644 --- a/examples/sections_iterable_object/Sections_Iterable_Object.php +++ b/examples/section_objects/SectionObjects.php @@ -1,17 +1,16 @@ Date: Tue, 6 Jul 2010 10:19:49 -0400 Subject: [PATCH 9/9] whitespace cleanup. --- test/MustacheObjectSectionTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/MustacheObjectSectionTest.php b/test/MustacheObjectSectionTest.php index 58d4286..f9ae45b 100644 --- a/test/MustacheObjectSectionTest.php +++ b/test/MustacheObjectSectionTest.php @@ -21,7 +21,7 @@ class MustacheObjectSectionTest extends PHPUnit_Framework_TestCase { class Alpha extends Mustache { public $foo; - + public function __construct() { $this->foo = new StdClass(); $this->foo->name = 'Foo'; @@ -31,17 +31,17 @@ class Alpha extends Mustache { class Beta extends Mustache { protected $_data = array(); - + public function __construct() { $this->_data['foo'] = new StdClass(); $this->_data['foo']->name = 'Foo'; $this->_data['foo']->number = 1; } - + public function __isset($name) { return array_key_exists($name, $this->_data); } - + public function __get($name) { return $this->_data[$name]; }