Permalink
Browse files

Allow StringTemplate::__construct() to take templates.

This saves a line of code when using templates that have already been
loaded.
  • Loading branch information...
1 parent a62438f commit 3489cd23aba3d64ec632622080e280ada2593781 @markstory markstory committed Jan 15, 2014
Showing with 24 additions and 0 deletions.
  1. +11 −0 src/View/StringTemplate.php
  2. +13 −0 tests/TestCase/View/StringTemplateTest.php
@@ -49,6 +49,17 @@ class StringTemplate {
];
/**
+ * Constructor.
+ *
+ * @param array $templates A set of templates to add.
+ */
+ public function __construct(array $templates = null) {
+ if ($templates) {
+ $this->add($templates);
+ }
+ }
+
+/**
* Load a config file containing templates.
*
* Template files should define a `$config` variable containing
@@ -31,6 +31,19 @@ public function setUp() {
}
/**
+ * Test adding templates through the constructor.
+ *
+ * @return void
+ */
+ public function testConstructorAdd() {
+ $templates = [
+ 'link' => '<a href="{{url}}">{{text}}</a>'
+ ];
+ $template = new StringTemplate($templates);
+ $this->assertEquals($templates['link'], $template->get('link'));
+ }
+
+/**
* test adding templates.
*
* @return void

0 comments on commit 3489cd2

Please sign in to comment.