Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • CacheMacro
  • CoreMacros
  • FormMacros
  • MacroSet
  • UIMacros
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Latte\Macros;
 13: 
 14: use Nette,
 15:     Nette\Latte,
 16:     Nette\Latte\MacroNode;
 17: 
 18: 
 19: 
 20: /**
 21:  * Base IMacro implementation. Allowes add multiple macros.
 22:  *
 23:  * @author     David Grudl
 24:  */
 25: class MacroSet extends Nette\Object implements Latte\IMacro
 26: {
 27:     /** @var Latte\Parser */
 28:     public $parser;
 29: 
 30:     /** @var array */
 31:     private $macros;
 32: 
 33: 
 34: 
 35:     public function __construct(Latte\Parser $parser)
 36:     {
 37:         $this->parser = $parser;
 38:     }
 39: 
 40: 
 41: 
 42:     public function addMacro($name, $begin, $end = NULL)
 43:     {
 44:         $this->macros[$name] = array($begin, $end);
 45:         $this->parser->addMacro($name, $this);
 46:     }
 47: 
 48: 
 49: 
 50:     public static function install(Latte\Parser $parser)
 51:     {
 52:         return new static($parser);
 53:     }
 54: 
 55: 
 56: 
 57:     /**
 58:      * Initializes before template parsing.
 59:      * @return void
 60:      */
 61:     public function initialize()
 62:     {
 63:     }
 64: 
 65: 
 66: 
 67:     /**
 68:      * Finishes template parsing.
 69:      * @return array(prolog, epilog)
 70:      */
 71:     public function finalize()
 72:     {
 73:     }
 74: 
 75: 
 76: 
 77:     /**
 78:      * New node is found.
 79:      * @return bool|string
 80:      */
 81:     public function nodeOpened(MacroNode $node)
 82:     {
 83:         $node->isEmpty = !isset($this->macros[$node->name][1]);
 84:         return $this->compile($node, $this->macros[$node->name][0]);
 85:     }
 86: 
 87: 
 88: 
 89:     /**
 90:      * Node is closed.
 91:      * @return string
 92:      */
 93:     public function nodeClosed(MacroNode $node)
 94:     {
 95:         return $this->compile($node, $this->macros[$node->name][1]);
 96:     }
 97: 
 98: 
 99: 
100:     /**
101:      * Generates code.
102:      * @return string
103:      */
104:     private function compile(MacroNode $node, $def)
105:     {
106:         $writer = Latte\PhpWriter::using($node, $this->parser->context);
107:         if (is_string($def)) {
108:             $code = $writer->write($def);
109:         } else {
110:             $code = callback($def)->invoke($node, $writer);
111:             if ($code === FALSE) {
112:                 return FALSE;
113:             }
114:         }
115:         return "<?php $code ?>";
116:     }
117: 
118: }
119: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0