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