Show
Ignore:
Timestamp:
07/30/08 06:12:53 (4 years ago)
Author:
john
Message:

added content_for() to AC simulating code blocks in ruby

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_controller.php

    r292 r299  
    294294     */ 
    295295    public $keep_flash = false; 
     296 
     297    /** 
     298     *  Keeps track of open blocks when calling content_for() 
     299     *  @var array 
     300     */ 
     301    public $content_for_open_blocks = array(); 
    296302 
    297303    /** 
     
    12601266 
    12611267    /** 
     1268     *  Sets content passed in or echoed after calling this function and sets it  
     1269     *  to a variable named $content_for_"$name" to be used in the layout. 
     1270     *  Example: 
     1271     *  View: 
     1272     *  <? $this->content_for("navigation") ?> 
     1273     *      <li><?= link_to('Login', array(":action" => 'login')) ?></li> 
     1274     *  <? $this->end_content_for() ?> 
     1275     *  Layout: 
     1276     *  <?= $content_for_navigation ?> 
     1277     * 
     1278     *  @param string $name variable name to be set for use in layout 
     1279     *  @param string $content (optional) content for the variable to be set 
     1280     */ 
     1281    function content_for($name, $content = null) { 
     1282        array_push($this->content_for_open_blocks, $name); 
     1283        ob_start(); 
     1284        if($content) { 
     1285            echo $content; 
     1286        } 
     1287    } 
     1288 
     1289    /** 
     1290     *  Ends an open block call by content_for() and sets the content of the buffer 
     1291     *  to the variable $content_for_"name" 
     1292     */  
     1293    function end_content_for() {     
     1294        if(count($this->content_for_open_blocks)) {      
     1295            if($name = array_pop($this->content_for_open_blocks)) { 
     1296                $content = ob_get_contents(); 
     1297                ob_end_clean(); 
     1298                $this->{"content_for_".$name} = $content; 
     1299            } else { 
     1300                ob_end_clean(); 
     1301            } 
     1302        }  
     1303    } 
     1304 
     1305    /** 
    12621306     *  Raise an ActionControllerError exception 
    12631307     *