Commit: 4bdff54df89ef43706f4e08fe7382ed5f11aaa97

Author: Joël Perras | Date: 2010-03-05 16:43:59 -0500
Adding JSON, XML and text types to paste view output.
diff --git a/config/bootstrap.php b/config/bootstrap.php index 09a7504..c112d51 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -85,9 +85,14 @@ Session::config(array( * return $posts->to('json'); * }}} */ -// use \lithium\util\Collection; -// -// Collection::formats('\lithium\net\http\Media'); +use \lithium\util\Collection; + +Collection::formats('\lithium\net\http\Media'); + +/** + * Include Media handling of addtional render types. + */ +require __DIR__ . '/bootstrap/media.php'; ?> \ No newline at end of file diff --git a/config/bootstrap/media.php b/config/bootstrap/media.php new file mode 100644 index 0000000..b950278 --- /dev/null +++ b/config/bootstrap/media.php @@ -0,0 +1,17 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +use \lithium\net\http\Media; + +$default = Media::type('default'); +$text = Media::type('text'); + +Media::type('xml', null, $default['options']); +Media::type('txt', null, $text['options']); + +?> \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 7ea4da8..fb0010e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -20,6 +20,8 @@ Router::connect('/latest/page:{:page}/limit:{:limit}', array( Router::connect('/add/{:args}', array('controller' => 'pastes', 'action' => 'add')); Router::connect('/edit/{:args}', array('controller' => 'pastes', 'action' => 'edit')); + +Router::connect('/view/{:args}.{:type}', array('controller' => 'pastes', 'action' => 'view')); Router::connect('/view/{:args}', array('controller' => 'pastes', 'action' => 'view')); Router::connect('/test/{:args}', array('controller' => '\lithium\test\Controller')); diff --git a/controllers/PastesController.php b/controllers/PastesController.php index d34f2ff..326c038 100644 --- a/controllers/PastesController.php +++ b/controllers/PastesController.php @@ -61,6 +61,13 @@ class PastesController extends \lithium\action\Controller { if ($paste->rewind() == 'not_found') { $this->redirect(array('controller' => 'pastes', 'action' => 'index')); } + + if ($this->request->type === 'json') { + return $paste->to('json'); + } + if ($this->request->type === 'txt') { + return $paste->content; + } return compact('paste'); } diff --git a/views/layouts/default.xml.php b/views/layouts/default.xml.php new file mode 100644 index 0000000..1e5130a --- /dev/null +++ b/views/layouts/default.xml.php @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<?php echo $this->content; ?> \ No newline at end of file diff --git a/views/pastes/view.txt.php b/views/pastes/view.txt.php new file mode 100644 index 0000000..fa625fa --- /dev/null +++ b/views/pastes/view.txt.php @@ -0,0 +1 @@ +<?php echo 'here'; ?> \ No newline at end of file diff --git a/views/pastes/view.xml.php b/views/pastes/view.xml.php new file mode 100644 index 0000000..919b993 --- /dev/null +++ b/views/pastes/view.xml.php @@ -0,0 +1,9 @@ +<paste> + <id><?=$paste->id; ?></id> +<?php if ($paste->author): ?> + <author><?=$paste->author; ?></author> +<?php endif; ?> + <created><?=$paste->created; ?></created> + <language><?=$paste->language; ?></language> + <content><?=$paste->content; ?></content> +</paste> \ No newline at end of file