Packages

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

Classes

  • CacheMacro
  • CoreMacros
  • FormMacros
  • MacroSet
  • UIMacros
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 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:  * @package Nette\Latte\Macros
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Base IMacro implementation. Allows add multiple macros.
 17:  *
 18:  * @author     David Grudl
 19:  * @package Nette\Latte\Macros
 20:  */
 21: class MacroSet extends Object implements IMacro
 22: {
 23:     /** @var LatteCompiler */
 24:     private $compiler;
 25: 
 26:     /** @var array */
 27:     private $macros;
 28: 
 29: 
 30: 
 31:     public function __construct(LatteCompiler $compiler)
 32:     {
 33:         $this->compiler = $compiler;
 34:     }
 35: 
 36: 
 37: 
 38:     public function addMacro($name, $begin, $end = NULL, $attr = NULL)
 39:     {
 40:         $this->macros[$name] = array($begin, $end, $attr);
 41:         $this->compiler->addMacro($name, $this);
 42:         return $this;
 43:     }
 44: 
 45: 
 46: 
 47:     public static function install(LatteCompiler $compiler)
 48:     {
 49:         return new self($compiler);
 50:     }
 51: 
 52: 
 53: 
 54:     /**
 55:      * Initializes before template parsing.
 56:      * @return void
 57:      */
 58:     public function initialize()
 59:     {
 60:     }
 61: 
 62: 
 63: 
 64:     /**
 65:      * Finishes template parsing.
 66:      * @return array(prolog, epilog)
 67:      */
 68:     public function finalize()
 69:     {
 70:     }
 71: 
 72: 
 73: 
 74:     /**
 75:      * New node is found.
 76:      * @return bool
 77:      */
 78:     public function nodeOpened(MacroNode $node)
 79:     {
 80:         if ($this->macros[$node->name][2] && $node->htmlNode) {
 81:             $node->isEmpty = TRUE;
 82:             $this->compiler->setContext(LatteCompiler::CONTEXT_DOUBLE_QUOTED);
 83:             $res = $this->compile($node, $this->macros[$node->name][2]);
 84:             $this->compiler->setContext(NULL);
 85:             if (!$node->attrCode) {
 86:                 $node->attrCode = "<?php $res ?>";
 87:             }
 88:         } else {
 89:             $node->isEmpty = !isset($this->macros[$node->name][1]);
 90:             $res = $this->compile($node, $this->macros[$node->name][0]);
 91:             if (!$node->openingCode) {
 92:                 $node->openingCode = "<?php $res ?>";
 93:             }
 94:         }
 95:         return $res !== FALSE;
 96:     }
 97: 
 98: 
 99: 
100:     /**
101:      * Node is closed.
102:      * @return void
103:      */
104:     public function nodeClosed(MacroNode $node)
105:     {
106:         $res = $this->compile($node, $this->macros[$node->name][1]);
107:         if (!$node->closingCode) {
108:             $node->closingCode = "<?php $res ?>";
109:         }
110:     }
111: 
112: 
113: 
114:     /**
115:      * Generates code.
116:      * @return string
117:      */
118:     private function compile(MacroNode $node, $def)
119:     {
120:         $node->tokenizer->reset();
121:         $writer = PhpWriter::using($node, $this->compiler);
122:         if (is_string($def)&& substr($def, 0, 1) !== "\0") {
123:             return $writer->write($def);
124:         } else {
125:             return Callback::create($def)->invoke($node, $writer);
126:         }
127:     }
128: 
129: 
130: 
131:     /**
132:      * @return LatteCompiler
133:      */
134:     public function getCompiler()
135:     {
136:         return $this->compiler;
137:     }
138: 
139: }
140: 
Nette Framework 2.0.7 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0