Skip to content
Browse files

Adding View class with template locator by jperras.

  • Loading branch information...
1 parent 63e3561 commit db33a484aa4ef01cf8d6ae9f060bacc675a235a6 @davidpersson davidpersson committed
Showing with 94 additions and 0 deletions.
  1. +26 −0 config/bootstrap.php
  2. +68 −0 extensions/View.php
View
26 config/bootstrap.php
@@ -0,0 +1,26 @@
+<?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;
+
+
+/**
+ * Register the design view as the default handler.
+ *
+ * @see li3_design\extensions\View
+ */
+Media::type('email', 'text/html', array());
+Media::type('default', null, array(
+ 'view' => '\li3_design\extensions\View',
+ 'paths' => array(
+ 'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
+ 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php',
+ )
+));
+
+?>
View
68 extensions/View.php
@@ -0,0 +1,68 @@
+<?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
+ */
+
+namespace li3_design\extensions;
+
+use \lithium\core\Libraries;
+use \lithium\core\Environment;
+use \lithium\util\String;
+
+/**
+ * This extended View class adds HTML comments to all rendered templates and
+ * elements, showing where each individual template file starts and ends. This
+ * is useful for designers and front-end integrators when cutting up or
+ * modifying designs.
+ */
+class View extends \lithium\template\View {
+
+ /**
+ * The 'element' render type handler.
+ *
+ * @param string $template Template to be rendered.
+ * @param array $data Template data.
+ * @param array $options Renderer options.
+ */
+ protected function _element($template, $data, array $options = array()) {
+ $options += array('controller' => 'elements', 'template' => $template);
+ $template = $this->_loader->template('template', $options);
+ $data = (array) $data + $this->outputFilters;
+ $data = $this->_renderer->render($template, $data, $options);
+ return $this->_pathized($data, $template);
+ }
+
+ /**
+ * The 'template' render type handler.
+ *
+ * @param string $template Template to be rendered.
+ * @param array $data Template data.
+ * @param array $options Renderer options.
+ */
+ protected function _template($template, $data, array $options = array()) {
+ $template = $this->_loader->template('template', $options);
+ $data = (array) $data + $this->outputFilters;
+ $data = $this->_renderer->render($template, $data, $options);
+ return $this->_pathized($data, $template);
+ }
+
+ /**
+ * Wrap the passed data with HTML comments.
+ *
+ * @param string $data The data to be wrapped.
+ * @param string $path The path to the template that corresponds to the data.
+ * @return string Data wrapped by HTML comments.
+ */
+ protected function _pathized($data, $path) {
+ if (Environment::is('production')) {
+ return $data;
+ }
+ $message = "<!-- START OF {:start} -->\n{$data}\n<!-- END OF {:stop} -->";
+ return String::insert($message, array('start' => $path, 'stop' => $path));
+ }
+}
+
+?>

0 comments on commit db33a48

Please sign in to comment.
Something went wrong with that request. Please try again.