Namespaces

  • 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
  • Namespace
  • Class
  • Tree
  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:  */
 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\Compiler */
 28:     private $compiler;
 29: 
 30:     /** @var array */
 31:     private $macros;
 32: 
 33: 
 34: 
 35:     public function __construct(Latte\Compiler $compiler)
 36:     {
 37:         $this->compiler = $compiler;
 38:     }
 39: 
 40: 
 41: 
 42:     public function addMacro($name, $begin, $end = NULL, $attr = NULL)
 43:     {
 44:         $this->macros[$name] = array($begin, $end, $attr);
 45:         $this->compiler->addMacro($name, $this);
 46:         return $this;
 47:     }
 48: 
 49: 
 50: 
 51:     public static function install(Latte\Compiler $compiler)
 52:     {
 53:         return new static($compiler);
 54:     }
 55: 
 56: 
 57: 
 58:     /**
 59:      * Initializes before template parsing.
 60:      * @return void
 61:      */
 62:     public function initialize()
 63:     {
 64:     }
 65: 
 66: 
 67: 
 68:     /**
 69:      * Finishes template parsing.
 70:      * @return array(prolog, epilog)
 71:      */
 72:     public function finalize()
 73:     {
 74:     }
 75: 
 76: 
 77: 
 78:     /**
 79:      * New node is found.
 80:      * @return bool
 81:      */
 82:     public function nodeOpened(MacroNode $node)
 83:     {
 84:         if ($this->macros[$node->name][2] && $node->htmlNode) {
 85:             $node->isEmpty = TRUE;
 86:             $this->compiler->setContext(Latte\Compiler::CONTEXT_DOUBLE_QUOTED);
 87:             $res = $this->compile($node, $this->macros[$node->name][2]);
 88:             $this->compiler->setContext(NULL);
 89:             if (!$node->attrCode) {
 90:                 $node->attrCode = "<?php $res ?>";
 91:             }
 92:         } else {
 93:             $node->isEmpty = !isset($this->macros[$node->name][1]);
 94:             $res = $this->compile($node, $this->macros[$node->name][0]);
 95:             if (!$node->openingCode) {
 96:                 $node->openingCode = "<?php $res ?>";
 97:             }
 98:         }
 99:         return $res !== FALSE;
100:     }
101: 
102: 
103: 
104:     /**
105:      * Node is closed.
106:      * @return void
107:      */
108:     public function nodeClosed(MacroNode $node)
109:     {
110:         $res = $this->compile($node, $this->macros[$node->name][1]);
111:         if (!$node->closingCode) {
112:             $node->closingCode = "<?php $res ?>";
113:         }
114:     }
115: 
116: 
117: 
118:     /**
119:      * Generates code.
120:      * @return string
121:      */
122:     private function compile(MacroNode $node, $def)
123:     {
124:         $node->tokenizer->reset();
125:         $writer = Latte\PhpWriter::using($node, $this->compiler);
126:         if (is_string($def)) {
127:             return $writer->write($def);
128:         } else {
129:             return callback($def)->invoke($node, $writer);
130:             }
131:         }
132: 
133: 
134: 
135:     /**
136:      * @return Latte\Compiler
137:      */
138:     public function getCompiler()
139:     {
140:         return $this->compiler;
141:     }
142: 
143: }
144: 
Nette Framework 2.0.0 API API documentation generated by ApiGen 2.7.0