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

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