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

Classes

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