[Solar-svn] Revision 2877

pmjones at solarphp.com pmjones at solarphp.com
Sun Oct 14 09:40:11 CDT 2007


updated todo list, keeping previous JS helper libs in hold



Copied: hold/Js.php (from rev 2853, trunk/Solar/View/Helper/Js.php)
===================================================================
--- hold/Js.php	                        (rev 0)
+++ hold/Js.php	2007-10-14 14:40:10 UTC (rev 2877)
@@ -0,0 +1,308 @@
+<?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;
+    }
+}

Copied: hold/JsLibrary.php (from rev 2853, trunk/Solar/View/Helper/JsLibrary.php)
===================================================================
--- hold/JsLibrary.php	                        (rev 0)
+++ hold/JsLibrary.php	2007-10-14 14:40:10 UTC (rev 2877)
@@ -0,0 +1,161 @@
+<?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: todo/todo.txt
===================================================================
--- todo/todo.txt	2007-10-13 14:00:41 UTC (rev 2876)
+++ todo/todo.txt	2007-10-14 14:40:10 UTC (rev 2877)
@@ -3,8 +3,6 @@
 
 * Write up a graphic of request lifetime (per Clay)
 
-* Create separate MIME part class for use in mail and http?
-
 * Write up notes on when to use config keys for dependency injection, and when
   to use method-based injection (e.g., Page::setFrontController()).
 
@@ -31,7 +29,14 @@
   there. May want to add a 'top' link or something through out it so you can.
   It's been bugging me all day."
 
+* For `solar make-model`, add docblock tags on methods.
 
+* For version 1.0.0alpha1, remove MS-SQL.  Put MS-SQL and Oracle in a later
+  release.
+
+* Write up templates for SQL relations so that others can see what the 
+  queries are.
+
 By Class
 ========
 
@@ -68,10 +73,12 @@
     
 * Solar_Controller_Page
 
-    * Is _forward() switch/case a micro-optimization?
-    
     * Augment $_view_class with a search of the parents for Vendor_View?
     
+* Solar_Docs_Apiref
+
+    * Do better job finding summary lines; e.g., single line without period.
+    
 * Solar_Form
     
     * Add support for 'input type="image"' elements (foo.x, foo.y) ?
@@ -98,7 +105,7 @@
           [9:30am] moraes: $headers = str_replace("\r\n", "\n",
           $this->_headersToString($headers));
           
-           [09:30am] moraes: $body = str_replace("\r\n", "\n",
+          [09:30am] moraes: $body = str_replace("\r\n", "\n",
           $this->_mail->fetchContent());* Solar_Markdown
     
     * Add setReplyTo() method
@@ -129,6 +136,11 @@
     
     * Add Oracle adapter
     
+* Solar_Sql_Model
+
+    * Move fetchRelatedArray(), fetchRelatedObject(), and countPagesRelated()
+      to Solar_Sql_Model_Related
+      
 * Solar_View_Helper
     
     * hCard helper? <http://microformats.org/wiki/hcard>
@@ -141,13 +153,6 @@
     
     * Cycle/odd-even helper from Mike N.?
     
-    * Make style() helper work more like the js() one, with stacking and then
-      eventually a fetch() method?
-    
-    * Remove Protaculous helpers, per convo w/Clay and others, since we seem
-      to always go through JS instead of the PHP methods ... maybe have a way
-      to push JS directly to the head?
-    
     * Form and FormElement
         
         * Add support for disabled elements? Can we do this with CSS




More information about the Solar-svn mailing list