Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Renderer options #642

Closed
wants to merge 2 commits into from

3 participants

@mehlah

This updates the way options are passed between the Renderer and the View classes.
Now, Renderer::_render() is aware of all rendering options accepted by View::render().

@see: http://lithify.me/bot/logs/li3-core/2012-09-14#3
@see: http://lithify.me/bot/logs/li3/2012-01-02#314

I'm not happy with the so-called unit test committed. Should be moved to integration tests if kept.
Any better idea to unit test this, without testing the actual params passed to _render()?

Related to #624

PS: Sorry for the delay nate ;)

@mehlah

Seems that something is wrong with Travis short_open_tag php.ini configuration (enabled by default for PHP 5.4)

@nateabele
Owner

@mehlah The code change looks good, but on the failing test, I'm not sure I follow. It looks like it failed on 5.3 and passed on 5.4. However, is there a way we could test this that didn't involve actual rendering? I think it would work better to add an accessor method for $_options on MockRenderer. What do you think?

@nateabele
Owner

Hey dude, need some help with this? Just let me know.

@mehlah

Hey Nate, it was a fast and furious week and sadly had no time to take care of it.
I haven't done yet any work to update the test case. If you have a free cycle, I'm buying a diff ;-)
I should be able to push it on Friday anyway.

@jails
Collaborator

Need some help for this PR @mehlah ? ;-)

@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails
Collaborator

Closed in flavor of #642.

@jails jails closed this
@jails jails referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@jails jails referenced this pull request from a commit
@jails jails Renderer options (close #642). 08a2433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
13 template/view/Renderer.php
@@ -133,6 +133,14 @@
protected $_vars = array();
/**
+ * Available options accepted by `template\View::render()`, used when rendering.
+ *
+ * @see lithium\template\View::render()
+ * @var array
+ */
+ protected $_options = array();
+
+ /**
* Render the template with given data. Abstract; must be added to subclasses.
*
* @param string $template
@@ -486,10 +494,7 @@ public function set(array $data = array()) {
* @return string Returns a the rendered template content as a string.
*/
protected function _render($type, $template, array $data = array(), array $options = array()) {
- if ($this->_request) {
- $library = $this->_request->library;
- $options += compact('library');
- }
+ $options += $this->_options;
return $this->_view->render($type, $data + $this->_data, compact('template') + $options);
}
}
View
2  template/view/adapter/File.php
@@ -102,6 +102,8 @@ public function render($template, $data = array(), array $options = array()) {
$this->_context = $options['context'] + $this->_context;
$this->_data = (array) $data + $this->_vars;
+ $this->_options = $options;
+
$template__ = $template;
unset($options, $template, $defaults, $data);
View
32 tests/cases/template/ViewTest.php
@@ -175,6 +175,38 @@ public function testNolayout() {
unset($renderData[0]['data']['h']);
$this->assertEqual($expected, $renderData);
}
+
+ public function testElementRendering() {
+ $view = new View(array(
+ 'loader' => 'lithium\tests\mocks\template\view\adapters\TestRenderer',
+ 'paths' => array(
+ 'template' => '{:library}/tests/mocks/template/view/adapters/{:template}.html.php',
+ 'element' => array(
+ '{:library}/tests/mocks/template/view/adapters/{:controller}/_{:template}.html.php',
+ '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'
+
+ ),
+ 'layout' => false
+ )
+ ));
+
+ $options = array(
+ 'template' => 'testElement',
+ 'library' => LITHIUM_LIBRARY_PATH . '/lithium'
+ );
+ $result = $view->render('all', array(), $options);
+ $expected = 'This is a rendered element';
+ $this->assertEqual($expected, $result);
+
+ $options = array(
+ 'template' => 'testElement',
+ 'library' => LITHIUM_LIBRARY_PATH . '/lithium',
+ 'controller' => 'posts'
+ );
+ $result = $view->render('all', array(), $options);
+ $expected = 'This is a rendered _element';
+ $this->assertEqual($expected, $result);
+ }
}
?>
View
1  tests/mocks/template/view/adapters/elementFile.html.php
@@ -0,0 +1 @@
+element
View
1  tests/mocks/template/view/adapters/posts/_elementFile.html.php
@@ -0,0 +1 @@
+_element
View
1  tests/mocks/template/view/adapters/testElement.html.php
@@ -0,0 +1 @@
+This is a rendered <?= $this->_render('element', 'elementFile'); ?>
Something went wrong with that request. Please try again.