Skip to content

Commit

Permalink
Split up NativeView::render functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Jordan <krisjordan@gmail.com>(cherry picked from commit 993098d)
  • Loading branch information
midnightmonster authored and KrisJordan committed Apr 27, 2009
1 parent bc9cbc8 commit bf22ad1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
47 changes: 27 additions & 20 deletions recess/recess/framework/views/NativeView.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,37 @@ class NativeView extends AbstractView {
* @abstract
*/
protected function render(Response $response) {
$this->renderFormats($response);
extract($response->data);
$viewsDir = $response->meta->app->getViewsDir();

include($response->meta->viewDir . $response->meta->viewName . '.php');
}

protected function renderFormats(Response $response) {
switch($response->request->format) {
case Formats::JSON:
foreach($response->data as $key => $value) {
if($value instanceof ModelSet) {
$response->data[$key] = $value->toArray();
}
if($value instanceof Form) {
unset($response->data[$key]);
}
if(substr($key,0,1) == '_') {
unset($response->data[$key]);
}
}
if(isset($response->data['application'])) unset ($response->data['application']);
if(isset($response->data['controller'])) unset ($response->data['controller']);
print json_encode($response->data);
exit;
$this->render_JSON($response);
default:
}

extract($response->data);
$viewsDir = $response->meta->app->getViewsDir();

include_once($response->meta->viewDir . $response->meta->viewName . '.php');
}

protected function render_JSON(Response $response) {
foreach($response->data as $key => $value) {
if($value instanceof ModelSet) {
$response->data[$key] = $value->toArray();
}
if($value instanceof Form) {
unset($response->data[$key]);
}
if(substr($key,0,1) == '_') {
unset($response->data[$key]);
}
}
if(isset($response->data['application'])) unset ($response->data['application']);
if(isset($response->data['controller'])) unset ($response->data['controller']);
print json_encode($response->data);
exit;
}
}
?>
1 change: 1 addition & 0 deletions recess/recess/framework/views/RecessView.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RecessView extends NativeView {
* @abstract
*/
protected function render(Response $response) {
$this->renderFormats($response);
$this->loadHelper(
'recess.framework.helpers.Layout',
'recess.framework.helpers.Part',
Expand Down

0 comments on commit bf22ad1

Please sign in to comment.