Packages

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

Classes

  • NCacheMacro
  • NCoreMacros
  • NFormMacros
  • NMacroSet
  • NUIMacros
  • Overview
  • Package
  • 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:  * @package Nette\Latte\Macros
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Base IMacro implementation. Allowes 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: 
 31:     public function __construct(NLatteCompiler $compiler)
 32:     {
 33:         $this->compiler = $compiler;
 34:     }
 35: 
 36: 
 37: 
 38:     public function addMacro($name, $begin, $end = NULL)
 39:     {
 40:         $this->macros[$name] = array($begin, $end);
 41:         $this->compiler->addMacro($name, $this);
 42:         return $this;
 43:     }
 44: 
 45: 
 46: 
 47:     public static function install(NLatteCompiler $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|string
 77:      */
 78:     public function nodeOpened(NMacroNode $node)
 79:     {
 80:         $node->isEmpty = !isset($this->macros[$node->name][1]);
 81:         return $this->compile($node, $this->macros[$node->name][0]);
 82:     }
 83: 
 84: 
 85: 
 86:     /**
 87:      * Node is closed.
 88:      * @return string
 89:      */
 90:     public function nodeClosed(NMacroNode $node)
 91:     {
 92:         return $this->compile($node, $this->macros[$node->name][1]);
 93:     }
 94: 
 95: 
 96: 
 97:     /**
 98:      * Generates code.
 99:      * @return string
100:      */
101:     private function compile(NMacroNode $node, $def)
102:     {
103:         $node->tokenizer->reset();
104:         $writer = NPhpWriter::using($node, $this->compiler);
105:         if (is_string($def)&& substr($def, 0, 1) !== "\0") {
106:             $code = $writer->write($def);
107:         } else {
108:             $code = callback($def)->invoke($node, $writer);
109:             if ($code === FALSE) {
110:                 return FALSE;
111:             }
112:         }
113:         return "<?php $code ?>";
114:     }
115: 
116: 
117: 
118:     /**
119:      * @return NLatteCompiler
120:      */
121:     public function getCompiler()
122:     {
123:         return $this->compiler;
124:     }
125: 
126: }
127: 
Nette Framework 2.0beta2 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0