From: <gem...@li...> - 2012-02-02 17:01:38
|
Revision: 448 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=448&view=rev Author: matijsdejong Date: 2012-02-02 17:01:28 +0000 (Thu, 02 Feb 2012) Log Message: ----------- $html->snippet() adds a snippet to the content of the element Added documentation Modified Paths: -------------- branches/1.5.x/library/classes/Gems/Controller/BrowseEditAction.php branches/1.5.x/library/classes/MUtil/Controller/Action.php branches/1.5.x/library/classes/MUtil/Html/Creator.php branches/1.5.x/library/classes/MUtil/Html.php Modified: branches/1.5.x/library/classes/Gems/Controller/BrowseEditAction.php =================================================================== --- branches/1.5.x/library/classes/Gems/Controller/BrowseEditAction.php 2012-02-02 15:02:24 UTC (rev 447) +++ branches/1.5.x/library/classes/Gems/Controller/BrowseEditAction.php 2012-02-02 17:01:28 UTC (rev 448) @@ -310,7 +310,7 @@ $form->addElement($element); $form->addDisplayGroup(array('formLinks'), 'form_buttons'); } - } else { + } else { $table = new MUtil_Html_TableElement(array('class' => 'formTable')); $table->setAsFormLayout($form, true, true); $table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class. Modified: branches/1.5.x/library/classes/MUtil/Controller/Action.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Controller/Action.php 2012-02-02 15:02:24 UTC (rev 447) +++ branches/1.5.x/library/classes/MUtil/Controller/Action.php 2012-02-02 17:01:28 UTC (rev 448) @@ -397,6 +397,8 @@ public function initHtml($reset = false) { if ($reset || (! $this->html)) { + MUtil_Html::setSnippetLoader($this->getSnippetLoader()); + $this->html = new MUtil_Html_Sequence(); // Add this variable to the view. Modified: branches/1.5.x/library/classes/MUtil/Html/Creator.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Html/Creator.php 2012-02-02 15:02:24 UTC (rev 447) +++ branches/1.5.x/library/classes/MUtil/Html/Creator.php 2012-02-02 17:01:28 UTC (rev 448) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -26,27 +25,56 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @package MUtil + * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: Creator.php 362 2011-12-15 17:21:17Z matijsdejong $ */ /** - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * Class for storing references for creating html attributes, elements and other objects. + * + * Basically this class stores list of element and attributes names that should be treated + * in different from just creating the most basic of element types. + * + * @package MUtil * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Html_Creator { + /** + * + * @var MUtil_Util_LookupList + */ protected $_attributeFunctionList; + + /** + * + * @var MUtil_Util_LookupList + */ protected $_elementFunctionList; + /** + * + * @var array + */ protected $_initialAttributeFunctions = array( 'href' => 'MUtil_Html_HrefArrayAttribute::hrefAttribute', 'onclick' => 'MUtil_Html_OnClickArrayAttribute::onclickAttribute', 'style' => 'MUtil_Html_StyleArrayAttribute::styleAttribute', ); + /** + * + * @var array + */ protected $_initalElementFunctions = array( 'a' => 'MUtil_Html_AElement::a', 'array' => 'MUtil_Html_Sequence::createSequence', @@ -86,6 +114,7 @@ 'raw' => 'MUtil_Html_Raw::raw', 'seq' => 'MUtil_Html_Sequence::createSequence', 'sequence' => 'MUtil_Html_Sequence::createSequence', // A sequence can contain another sequence, so other function name used + 'snippet' => 'MUtil_Html::snippet', 'spaced' => 'MUtil_Html_Sequence::createSpaced', // A sequence can contain another sequence, so other function name used 'table' => 'MUtil_Html_TableElement::table', 'tbody' => 'MUtil_Html_TBodyElement::tbody', Modified: branches/1.5.x/library/classes/MUtil/Html.php =================================================================== --- branches/1.5.x/library/classes/MUtil/Html.php 2012-02-02 15:02:24 UTC (rev 447) +++ branches/1.5.x/library/classes/MUtil/Html.php 2012-02-02 17:01:28 UTC (rev 448) @@ -1,55 +1,69 @@ <?php - -/** - * Copyright (c) 2011, Erasmus MC - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Erasmus MC nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - /** - * - * @author Matijs de Jong - * @since 1.0 - * @version 1.1 - * @package MUtil + * Copyright (c) 2011, Erasmus MC + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Erasmus MC nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @package MUtil * @subpackage Html + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $id: Html.php 362 2011-12-15 17:21:17Z matijsdejong $ */ /** * Collections of static function for using the Html subpackage. - * - * @author Matijs de Jong - * @package MUtil + * + * @package MUtil * @subpackage Html + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 */ class MUtil_Html { + /** + * + * @var MUtil_Html_Creator + */ private static $_creator; + + /** + * + * @var MUtil_Html_Renderer + */ private static $_renderer; /** + * + * @var type MUtil_Snippets_SnippetLoader + */ + private static $_snippetLoader; + + /** * Static variable for debuggging purposes. Toggles the echoing of e.g. of sql * select statements, using MUtil_Echo. * @@ -65,9 +79,10 @@ */ public static $verbose = false; - public static function canRender($value) + public static function addUrl2Page(Zend_Navigation_Container $menu, $label, $arg_array = null) { - return self::getRenderer()->canRender($value); + $args = array_slice(func_get_args(), 2); + $menu->addPage(self::url($args)->toPage($label)); } public static function attrib($attributeName, $args_array = null) @@ -77,6 +92,11 @@ return self::getCreator()->createAttribute($attributeName, $args); } + public static function canRender($value) + { + return self::getRenderer()->canRender($value); + } + /** * * @param string $tagName Optional tag to create @@ -101,7 +121,7 @@ /** * Creates a new HtmlElement with the arguments specfied in a single array. - * + * * @param string $tagName (or a Lazy object) * @param array $args * @return MUtil_Html_ElementInterface @@ -118,17 +138,17 @@ /** * Creates a div element - * + * * @param mixed $arg_array Optional MUtil_Ra::args processed settings * @return MUtil_Html_HtmlElement (with div tagName) */ public static function div($arg_array = null) { $args = func_get_args(); - + return self::getCreator()->create('div', $args); } - + public static function element2id(Zend_Form_Element $element) { return self::name2id($element->getName(), $element->getBelongsTo()); @@ -152,6 +172,19 @@ return self::$_renderer; } + /** + * Get the snippet loader for use by self::snippet(). + * + * @return MUtil_Snippets_SnippetLoader + */ + public static function getSnippetLoader() + { + if (! self::$_snippetLoader) { + self::setSnippetLoader(new MUtil_Snippets_SnippetLoader()); + } + return self::$_snippetLoader; + } + public static function name2id($name, $belongsTo = null) { return preg_replace('/\[([^\]]+)\]/', '-$1', $name . '-' . $belongsTo); @@ -183,17 +216,17 @@ /** * Creates a table element - * + * * @param mixed $arg_array Optional MUtil_Ra::args processed settings * @return MUtil_Html_TableElement */ public static function table($arg_array = null) { $args = func_get_args(); - + return self::getCreator()->create('table', $args); } - + public static function setCreator(MUtil_Html_Creator $creator) { self::$_creator = $creator; @@ -206,15 +239,40 @@ return self::$_renderer; } + /** + * Set the snippet loader for use by self::snippet(). + * + * @param MUtil_Snippets_SnippetLoader $snippetLoader + * @return MUtil_Snippets_SnippetLoader + */ + public static function setSnippetLoader(MUtil_Snippets_SnippetLoader $snippetLoader) + { + self::$_snippetLoader = $snippetLoader; + return self::$_snippetLoader; + } + + /** + * + * @param string $name Snippet name + * @param MUtil_Ra::pairs $parameter_value_pairs Optional extra snippets + * @return + */ + public static function snippet($name, $parameter_value_pairs = null) + { + if (func_num_args() > 1) { + $extraSourceParameters = MUtil_Ra::pairs(func_get_args(), 1); + } else { + $extraSourceParameters = array(); + } + + $loader = self::getSnippetLoader(); + + return $loader->getSnippet($name, $extraSourceParameters); + } + public static function url($arg_array = null) { $args = func_get_args(); return new MUtil_Html_HrefArrayAttribute($args); } - - public static function addUrl2Page(Zend_Navigation_Container $menu, $label, $arg_array = null) - { - $args = array_slice(func_get_args(), 2); - $menu->addPage(self::url($args)->toPage($label)); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |