[Solar-svn] Revision 2867
pmjones at solarphp.com
pmjones at solarphp.com
Sat Oct 13 08:38:40 CDT 2007
Solar_View_Helper changes
* [ADD] Solar_View_Helper_Head lets you compose styles, scripts, links, meta
keywords, etc. in a holding space, and then lets you fetch the entire <head>
block all at once. This means that views can add styles and scripts as
needed.
* [DEL] Removed Js and JsLibrary helpers; all script- and style-related
"add*()" and "needs*()" functionality is now in Solar_View_Helper_Head.
The selector-related pieces appear to have been Prototype-specific, and
since we don't ship with Prototype/Scriptaculous any more, they're no
longer strictly necessary.
* [BRK] Renamed InlineScript to ScriptInline.
Added: trunk/Solar/View/Helper/Head.php
===================================================================
--- trunk/Solar/View/Helper/Head.php (rev 0)
+++ trunk/Solar/View/Helper/Head.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -0,0 +1,428 @@
+<?php
+/**
+ *
+ * Helper to collect <head> elements and display them in the correct order.
+ *
+ * @category Solar
+ *
+ * @package Solar_View_Helper
+ *
+ * @author Clay Loveless <clay at killersoft.com>
+ *
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id$
+ *
+ */
+
+/**
+ *
+ * Helper to collect <head> elements and display them in the correct order.
+ *
+ * @category Solar
+ *
+ * @package Solar_View_Helper
+ *
+ */
+class Solar_View_Helper_Head extends Solar_View_Helper {
+
+ /**
+ *
+ * The indent string for each element; default is 4 spaces.
+ *
+ * @var string
+ *
+ */
+ protected $_indent = ' ';
+
+ /**
+ *
+ * The <title> value.
+ *
+ * @var string
+ *
+ */
+ protected $_title = null;
+
+ /**
+ *
+ * Array of <meta> values.
+ *
+ * @var array
+ *
+ */
+ protected $_meta = array();
+
+ /**
+ *
+ * The <base> value.
+ *
+ * @var string
+ *
+ */
+ protected $_base = null;
+
+ /**
+ *
+ * Array of <link> values.
+ *
+ * @var array
+ *
+ */
+ protected $_link = array();
+
+ /**
+ *
+ * Array of baseline <style> values that come before all other styles.
+ *
+ * @var array
+ *
+ */
+ protected $_style_base = array();
+
+ /**
+ *
+ * Array of additional <style> values that come after the baseline styles.
+ *
+ * @var array
+ *
+ */
+ protected $_style = array();
+
+ /**
+ *
+ * Array of baseline <script> values that come before all other scripts.
+ *
+ * @var array
+ *
+ */
+ protected $_script_base = array();
+
+ /**
+ *
+ * Array of additional <script> values that come after the baseline
+ * scripts.
+ *
+ * @var array
+ *
+ */
+ protected $_script = array();
+
+ /**
+ *
+ * Array of inline <script> code.
+ *
+ * @var array
+ *
+ */
+ protected $_script_inline = array();
+
+ /**
+ *
+ * Main helper method; fluent interface.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function head()
+ {
+ return $this;
+ }
+
+ /**
+ *
+ * Sets the indent string.
+ *
+ * @param string $indent The indent string.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function setIndent($indent)
+ {
+ $this->_indent = $indent;
+ return $this;
+ }
+
+ /**
+ *
+ * Sets the <title> string.
+ *
+ * @param string $title The title string.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function setTitle($title)
+ {
+ $this->_title = $title;
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <meta> tag.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addMeta($attribs)
+ {
+ $this->_meta[] = (array) $attribs;
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <meta> HTTP-Equivalent tag.
+ *
+ * @param string $http_equiv The equivalent HTTP header label.
+ *
+ * @param string $content The equivalent HTTP header value.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addMetaHttp($http_equiv, $content)
+ {
+ $this->_meta[] = array(
+ 'http-equiv' => $http_equiv,
+ 'content' => $content,
+ );
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <meta> name tag.
+ *
+ * @param string $name The meta "name" label.
+ *
+ * @param string $content The meta "name" value.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addMetaName($name, $content)
+ {
+ $this->_meta[] = array(
+ 'name' => $name,
+ 'content' => $content,
+ );
+ return $this;
+ }
+
+ /**
+ *
+ * Sets the <base> URI string.
+ *
+ * @param string $base The base URI string.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function setBase($spec)
+ {
+ $this->_base = $spec;
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <link> tag.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addLink($attribs)
+ {
+ $this->_link[] = (array) $attribs;
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <style> tag as part of the "baseline" (foundation) styles.
+ * Generally used by layouts, not views.
+ *
+ * @param string $href The file HREF for the style source.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addStyleBase($href, $attribs = null)
+ {
+ if (empty($this->_style_base[$href])) {
+ $this->_style_base[$href] = array($href, (array) $attribs);
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <style> tag as part of the "additional" (override) styles.
+ * Generally used by views, not layouts. If the file has already been
+ * added, it does not get added again.
+ *
+ * @param string $href The file HREF for the style source.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addStyle($href, $attribs = null)
+ {
+ if (empty($this->_style[$href])) {
+ $this->_style[$href] = array($href, (array) $attribs);
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <script> tag as part of the "baseline" (foundation) scripts.
+ * Generally used by layouts, not views. If the file has already been
+ * added, it does not get added again.
+ *
+ * @param string $href The file HREF for the script source.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addScriptBase($src, $attribs = null)
+ {
+ if (empty($this->_script_base[$src])) {
+ $this->_script_base[$src] = array($src, (array) $attribs);
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <script> tag as part of the "additional" (override) scripts.
+ * Generally used by views, not layouts. If the file has already been
+ * added, it does not get added again.
+ *
+ * @param string $href The file HREF for the script source.
+ *
+ * @param array $attribs Attributes for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addScript($src, $attribs = null)
+ {
+ if (empty($this->_script[$src])) {
+ $this->_script[$src] = array($src, (array) $attribs);
+ }
+ return $this;
+ }
+
+ /**
+ *
+ * Adds a <script> tag with inline code.
+ *
+ * @param string $code The inline code for the tag.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function addScriptInline($code)
+ {
+ $this->_script_inline[] = $code;
+ return $this;
+ }
+
+ /**
+ *
+ * Builds and returns all the tags for the <head> section.
+ *
+ * @return Solar_View_Helper_Head
+ *
+ */
+ public function fetch()
+ {
+ // array of lines for HTML output
+ $html = array();
+
+ // title
+ if (! empty($this->_title)) {
+ $html[] = $this->_view->title($this->_title);
+ }
+
+ // metas
+ foreach ((array) $this->_meta as $val) {
+ $html[] = $this->_view->meta($val);
+ }
+
+ // base
+ if (! empty($this->_base)) {
+ $html[] = $this->_view->base($this->_base);
+ }
+
+ // links
+ foreach ((array) $this->_link as $val) {
+ $html[] = $this->_view->link($val);
+ }
+
+ // baseline styles
+ foreach ((array) $this->_style_base as $val) {
+ $html[] = $this->_view->style($val[0], $val[1]);
+ }
+
+ // additional styles
+ foreach ((array) $this->_style as $val) {
+ $html[] = $this->_view->style($val[0], $val[1]);
+ }
+
+ // baseline scripts
+ foreach ((array) $this->_script_base as $val) {
+ $html[] = $this->_view->script($val[0], $val[1]);
+ }
+
+ // additional scripts (source)
+ foreach ((array) $this->_script as $val) {
+ $html[] = $this->_view->script($val[0], $val[1]);
+ }
+
+ // inline scripts collected into a single block
+ $code = $this->_fetchScriptInline();
+ if ($code) {
+ $html[] = $this->_view->scriptInline($code);
+ }
+
+ // concat with indents and newlines, and done!
+ return $this->_indent
+ . implode("\n{$this->_indent}", $html)
+ . "\n";
+ }
+
+ /**
+ *
+ * Support method to fetch inline scripts; child classes may wish to
+ * override this to wrap in a library-specific "when document is ready"
+ * logic.
+ *
+ * @return string The code for all inline scripts.
+ *
+ */
+ protected function _fetchScriptInline()
+ {
+ $code = null;
+ foreach ((array) $this->_script_inline as $val) {
+ $code .= $val . "\n\n";
+ }
+ return rtrim($code);
+ }
+}
\ No newline at end of file
Deleted: trunk/Solar/View/Helper/InlineScript.php
===================================================================
--- trunk/Solar/View/Helper/InlineScript.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/InlineScript.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -1,59 +0,0 @@
-<?php
-/**
- *
- * Helper for inline JavaScript blocks.
- *
- * @category Solar
- *
- * @package Solar_View
- *
- * @author Paul M. Jones <pmjones at solarphp.com>
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- * @version $Id$
- *
- */
-
-/**
- *
- * Helper for inline JavaScript blocks.
- *
- * @category Solar
- *
- * @package Solar_View
- *
- */
-class Solar_View_Helper_InlineScript extends Solar_View_Helper {
-
- /**
- *
- * Returns a <script></script> block that properly commented for inclusion
- * in XHTML documents.
- *
- * @param string $src The source of the script.
- *
- * @param array $attribs Additional attributes for the <script> tag.
- *
- * @return string The <script></script> tag.
- *
- * @see http://developer.mozilla.org/en/docs/Properly_Using_CSS_and_JavaScript_in_XHTML_Documents
- *
- */
- public function inlineScript($src, $attribs = null)
- {
- settype($attribs, 'array');
- unset($attribs['src']);
-
- if (empty($attribs['type'])) {
- $attribs['type'] = 'text/javascript';
- }
-
- return '<script'
- . $this->_view->attribs($attribs) . ">\n"
- . "//<![CDATA[\n"
- . trim($src)
- . "\n//]]>\n"
- . "</script>\n";
- }
-}
Deleted: trunk/Solar/View/Helper/Js.php
===================================================================
--- trunk/Solar/View/Helper/Js.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/Js.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -1,308 +0,0 @@
-<?php
-/**
- *
- * Helper for building JavaScript-powered applications.
- *
- * @category Solar
- *
- * @package Solar_View_Helper_Js
- *
- * @author Clay Loveless <clay at killersoft.com>
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- * @version $Id$
- *
- */
-
-/**
- *
- * Helper for building JavaScript-powered applications.
- *
- * This is a fluent class; all method calls except fetch() return
- * $this, which means you can chain method calls for easier readability.
- *
- * @category Solar
- *
- * @package Solar_View_Helper_Js
- *
- * @author Clay Loveless <clay at killersoft.com>
- *
- */
-class Solar_View_Helper_Js extends Solar_View_Helper_JsLibrary {
-
- /**
- *
- * User-provided configuration values.
- *
- * @var array
- *
- */
- protected $_Solar_View_Helper_Js = array(
- 'attribs' => array(),
- );
-
- /**
- *
- * Array of JavaScript files needed to provide specified functionality.
- *
- * @var array
- *
- */
- public $files;
-
- /**
- *
- * Array of CSS files required by a JavaScript class.
- *
- * @var array
- *
- */
- public $styles;
-
- /**
- *
- * Array of inline JavaScript needed to provide specified functionality.
- *
- * @var array
- *
- */
- public $scripts;
-
- /**
- *
- * Array of CSS selectors and their corresponding rules.
- *
- * @var array
- *
- */
- public $selectors;
-
- /**
- *
- * Array of JavaScript objects and their corresponding rules.
- *
- * @var array
- *
- */
- public $objects;
-
- /**
- *
- * Constructor.
- *
- * @param array $config User-provided configuration values.
- *
- */
- public function __construct($config = null)
- {
- parent::__construct($config);
- $this->reset();
- }
-
- /**
- *
- * Build and return JavaScript for page header.
- *
- * @return string Block of JavaScript with <script src ...> for view-defined
- * script requirements.
- *
- */
- public function fetchFiles()
- {
- $js = '';
-
- if (!empty($this->files)) {
- foreach ($this->files as $file) {
- $js .= ' ' . $this->_view->script($file) . "\n";
- }
- }
-
- return $js;
- }
-
- /**
- *
- * Build and return list of CSS files for page header.
- *
- * @return string Block of HTML with <style> tags for JavaScript-defined
- * style requirements.
- *
- */
- public function fetchStyles()
- {
- $str = '';
-
- if (!empty($this->styles)) {
- foreach ($this->styles as $style) {
- $str .= ' ' . $this->_view->style($style) . "\n";
- }
- }
-
- return $str;
- }
-
- /**
- *
- * Returns all defined inline scripts. This is a separate fetch method
- * so that any/all external (standalone JS file) scripts required by the
- * App or the View that the inline scripts depend on can be loaded prior to
- * the output of the inline script.
- *
- * @return string All inline JavaScripts
- *
- */
- public function fetchInline()
- {
- $js = '';
-
- // Loop through selectors for registered actions
- $f = '';
- if (!empty($this->selectors)) {
-
- foreach ($this->selectors as $selector => $actions) {
-
- // Wrap in selector loop
- $f .= " \$\$('$selector').each(function(el){\n";
-
- foreach ($actions as $a) {
- // add in loop with indent for easy reading
- $f .= ' '
- . trim($this->_view->getHelper($a['type'])->fetch($selector, $a))
- . "\n";
- }
-
- // Close off selector loop wrapper
- $f .= " });\n";
-
- }
-
- // Register window onload event to process CSS selector actions
- if ($f != '') {
- $f = "function() {\n" . rtrim($f) . "\n}";
- $this->_view->JsPrototype()->event->observeObject('window', 'load', $f);
- }
- }
-
- // Loop through registered object actions/observers
- if (!empty($this->objects)) {
- foreach ($this->objects as $object => $actions) {
- foreach ($actions as $a) {
- $this->scripts[] = $this->_view->getHelper($a['type'])->fetch($object, $a, true);
- }
- }
- }
-
- // Gather all registered scripts for output
- if (!empty($this->scripts)) {
- $scripts = implode("\n\n", $this->scripts);
- $scripts = trim($scripts);
- $js = $this->_view->inlineScript($scripts);
- }
-
- return $js;
- }
-
- /**
- *
- * Fluent interface.
- *
- * @return Solar_View_Helper_Js
- *
- */
- public function js()
- {
- return $this;
- }
-
- /**
- *
- * Add the specified JavaScript file to the Helper_Js file list
- * if it's not already present.
- *
- * Paths should be releative to the 'path' configuration value for the
- * corresponding Solar_View_Helper class.
- *
- * @param mixed $file Name of .js file to add to the header of the page, or
- * (optionally) an array of files to add.
- *
- * @return Solar_View_Helper_Js
- *
- */
- public function addFile($file)
- {
- if ($this->files === null) {
- $this->files = array();
- }
-
- if (is_array($file)) {
- $this->files = array_merge($this->files, $file);
- } elseif ($file !== null && !in_array($file, $this->files, true)) {
- $this->files[] = $file;
- }
-
- return $this;
- }
-
- /**
- *
- * Add the specified CSS file to the Helper_Js styles list
- * if it's not already present.
- *
- * Paths should be releative to the 'styles' configuration value for the
- * corresponding Solar_View_Helper class.
- *
- * @param mixed $file Name of .css file to add to the header of the page, or
- * (optionally) an array of files to add.
- *
- * @return Solar_View_Helper_Js
- *
- */
- public function addStyle($file)
- {
- if ($this->files === null) {
- $this->files = array();
- }
-
- if (is_array($file)) {
- $this->styles = array_merge($this->styles, $file);
- } elseif ($file !== null && !in_array($file, $this->styles, true)) {
- $this->styles[] = $file;
- }
-
- return $this;
- }
-
- /**
- *
- * Add the script defined in $src to the inline scripts array.
- *
- * @param string $src A snippet of JavaScript to be inserted in the head
- * of a document.
- *
- * @return Solar_View_Helper_Js
- */
- public function addInlineScript($src)
- {
- $this->scripts[] = $src;
- return $this;
- }
-
- /**
- *
- * Resets the helper entirely.
- *
- * @return object Solar_View_Helper_Js
- *
- */
- public function reset()
- {
- $this->selectors = array();
- $this->objects = array();
- $this->files = array();
- $this->scripts = array();
- $this->styles = array();
-
- return $this;
- }
-}
Deleted: trunk/Solar/View/Helper/JsLibrary.php
===================================================================
--- trunk/Solar/View/Helper/JsLibrary.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/JsLibrary.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -1,161 +0,0 @@
-<?php
-/**
- *
- * Abstract helper for JavaScript support.
- *
- * @category Solar
- *
- * @package Solar_View_Helper_Js
- *
- * @author Clay Loveless <clay at killersoft.com>
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- * @version $Id$
- *
- */
-
-/**
- *
- * Abstract helper for JavaScript support.
- *
- * @category Solar
- *
- * @package Solar_View_Helper_Js
- *
- */
-abstract class Solar_View_Helper_JsLibrary extends Solar_View_Helper {
-
- /**
- *
- * User-provided configuration values
- *
- * Keys are ...
- *
- * `events`
- * :_(array)_ An array of JavaScript events that the JavaScript
- * environment is aware of. Used to manage quoting of strings generated
- * by Solar_Json.
- *
- * @var array
- *
- */
- protected $_Solar_View_Helper_JsLibrary = array(
- 'events' => array(
- 'uninitialized',
- 'loading',
- 'loaded',
- 'interactive',
- 'complete',
- 'failure',
- 'success',
- ),
- );
-
- /**
- *
- * Valid events for JavaScript environment.
- *
- * @var array
- *
- */
- protected $_valid_events;
-
- /**
- *
- * Constructor.
- *
- * @param array $config User-defined configuration.
- *
- */
- public function __construct($config = null)
- {
- parent::__construct($config);
-
- // Event Callbacks are also valid on any HTTP response code
- $codes = range(100, 599);
- $this->_valid_events = array_merge($this->_config['events'], $codes);
- }
-
- /**
- *
- * Method interface.
- *
- * @return Child JsLibrary object
- */
- public function jsLibrary()
- {
- return $this;
- }
-
- /**
- *
- * Add the specified JavaScript file to the Helper_Js file list
- * if it's not already present.
- *
- * @param string $file Name of .js file needed by Helper class
- *
- * @return Child JsLibrary object
- *
- */
- protected function _needsFile($file = null)
- {
- // Add configured path
- $file = $this->_config['path'] . $file;
-
- $this->_view->js()->addFile($file);
- return $this;
- }
-
- /**
- *
- * Add the specified JavaScript file to the Helper_Js file list
- * if it's not already present.
- *
- * @param string $file Name of .js file needed by Helper class
- *
- * @return Child JsLibrary object
- *
- */
- protected function _needsStyle($file = null)
- {
- // Add configured path
- $file = $this->_config['styles'] . $file;
-
- $this->_view->js()->addStyle($file);
- return $this;
- }
-
- /**
- *
- * Returns options keys whose values should be dequoted, as the values are
- * expected to be `function() {...}` or names of pre-defined functions
- * elsewhere in the JavaScript environment.
- *
- * @param bool $expand Expand events into full 'onxxx' strings. 'success'
- * would become 'onSuccess'. Defaults to true
- *
- * @return array List of keys to dequote from a JSON string
- *
- */
- public function getFunctionKeys($expand = true)
- {
- $keys = $this->_valid_events;
- if ($expand) {
- foreach ($keys as $key => $val) {
- $keys[$key] = 'on' . ucfirst($val);
- }
- }
-
- // These callback hooks aren't true JavaScript events, but their values
- // will be a function
- $keys[] = 'callback';
- $keys[] = 'beforeStart';
- $keys[] = 'beforeUpdate';
- $keys[] = 'afterUpdate';
- $keys[] = 'afterFinish';
-
- return $keys;
- }
-
-}
Modified: trunk/Solar/View/Helper/Link.php
===================================================================
--- trunk/Solar/View/Helper/Link.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/Link.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -30,15 +30,15 @@
*
* Returns a <link ... /> tag.
*
- * @param string $spec The specification array, typically
+ * @param string $attribs The specification array, typically
* with keys 'rel' and 'href'.
*
* @return string The <link ... /> tag.
*
*/
- public function link($spec)
+ public function link($attribs)
{
- return '<link' . $this->_view->attribs($spec) . ' />';
+ return '<link' . $this->_view->attribs($attribs) . ' />';
}
}
Modified: trunk/Solar/View/Helper/Meta.php
===================================================================
--- trunk/Solar/View/Helper/Meta.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/Meta.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -32,15 +32,15 @@
*
* Returns a <meta ... /> tag.
*
- * @param string $spec The specification array, typically
+ * @param string $attribs The specification array, typically
* with keys 'name' or 'http-equiv', and 'content'.
*
* @return string The <meta ... /> tag.
*
*/
- public function meta($spec)
+ public function meta($attribs)
{
- return '<meta' . $this->_view->attribs($spec) . ' />';
+ return '<meta' . $this->_view->attribs($attribs) . ' />';
}
}
Modified: trunk/Solar/View/Helper/MetaHttp.php
===================================================================
--- trunk/Solar/View/Helper/MetaHttp.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/MetaHttp.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -30,18 +30,18 @@
*
* Returns a <meta http-equiv="" content="" /> tag.
*
- * @param string $key The http-equiv type.
+ * @param string $http_equiv The http-equiv type.
*
- * @param string $val The content value.
+ * @param string $content The content value.
*
* @return string The <meta http-equiv="" content="" /> tag.
*
*/
- public function metaHttp($key, $val)
+ public function metaHttp($http_equiv, $content)
{
$spec = array(
- 'http-equiv' => $key,
- 'content' => $val,
+ 'http-equiv' => $http_equiv,
+ 'content' => $content,
);
return '<meta' . $this->_view->attribs($spec) . ' />';
}
Modified: trunk/Solar/View/Helper/MetaName.php
===================================================================
--- trunk/Solar/View/Helper/MetaName.php 2007-10-13 03:38:57 UTC (rev 2866)
+++ trunk/Solar/View/Helper/MetaName.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -30,18 +30,18 @@
*
* Returns a <meta name="" content="" /> tag.
*
- * @param string $key The name value.
+ * @param string $name The name value.
*
- * @param string $val The content value.
+ * @param string $content The content value.
*
* @return string The <meta name="" content="" /> tag.
*
*/
- public function metaName($key, $val)
+ public function metaName($name, $content)
{
$spec = array(
- 'name' => $key,
- 'content' => $val,
+ 'name' => $name,
+ 'content' => $content,
);
return '<meta' . $this->_view->attribs($spec) . ' />';
}
Copied: trunk/Solar/View/Helper/ScriptInline.php (from rev 2853, trunk/Solar/View/Helper/InlineScript.php)
===================================================================
--- trunk/Solar/View/Helper/ScriptInline.php (rev 0)
+++ trunk/Solar/View/Helper/ScriptInline.php 2007-10-13 13:38:40 UTC (rev 2867)
@@ -0,0 +1,59 @@
+<?php
+/**
+ *
+ * Helper for inline JavaScript blocks.
+ *
+ * @category Solar
+ *
+ * @package Solar_View
+ *
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id$
+ *
+ */
+
+/**
+ *
+ * Helper for inline JavaScript blocks.
+ *
+ * @category Solar
+ *
+ * @package Solar_View
+ *
+ */
+class Solar_View_Helper_ScriptInline extends Solar_View_Helper {
+
+ /**
+ *
+ * Returns a <script></script> block that properly commented for inclusion
+ * in XHTML documents.
+ *
+ * @param string $code The source of the script.
+ *
+ * @param array $attribs Additional attributes for the <script> tag.
+ *
+ * @return string The <script></script> tag with the inline script.
+ *
+ * @see http://developer.mozilla.org/en/docs/Properly_Using_CSS_and_JavaScript_in_XHTML_Documents
+ *
+ */
+ public function scriptInline($code, $attribs = null)
+ {
+ settype($attribs, 'array');
+ unset($attribs['src']);
+
+ if (empty($attribs['type'])) {
+ $attribs['type'] = 'text/javascript';
+ }
+
+ return '<script'
+ . $this->_view->attribs($attribs) . ">\n"
+ . "//<![CDATA[\n"
+ . trim($code)
+ . "\n//]]>\n"
+ . "</script>\n";
+ }
+}
More information about the Solar-svn
mailing list