Packages

  • Nette
    • Application
      • Application\Diagnostics
      • Application\Responses
      • Application\Routers
      • Application\UI
    • Caching
      • Caching\Storages
    • ComponentModel
    • Config
    • Database
      • Database\Diagnostics
      • Database\Drivers
      • Database\Reflection
      • Database\Table
    • DI
    • Diagnostics
    • Forms
      • Forms\Controls
      • Forms\Rendering
    • Http
    • Iterators
    • Latte
      • Latte\Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • 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, 2011 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 NParser */
 24:     public $parser;
 25: 
 26:     /** @var array */
 27:     private $macros;
 28: 
 29: 
 30: 
 31:     public function __construct(NParser $parser)
 32:     {
 33:         $this->parser = $parser;
 34:     }
 35: 
 36: 
 37: 
 38:     public function addMacro($name, $begin, $end = NULL)
 39:     {
 40:         $this->macros[$name] = array($begin, $end);
 41:         $this->parser->addMacro($name, $this);
 42:     }
 43: 
 44: 
 45: 
 46:     public static function install(NParser $parser)
 47:     {
 48:         return new self($parser);
 49:     }
 50: 
 51: 
 52: 
 53:     /**
 54:      * Initializes before template parsing.
 55:      * @return void
 56:      */
 57:     public function initialize()
 58:     {
 59:     }
 60: 
 61: 
 62: 
 63:     /**
 64:      * Finishes template parsing.
 65:      * @return array(prolog, epilog)
 66:      */
 67:     public function finalize()
 68:     {
 69:     }
 70: 
 71: 
 72: 
 73:     /**
 74:      * New node is found.
 75:      * @return bool|string
 76:      */
 77:     public function nodeOpened(NMacroNode $node)
 78:     {
 79:         $node->isEmpty = !isset($this->macros[$node->name][1]);
 80:         return $this->compile($node, $this->macros[$node->name][0]);
 81:     }
 82: 
 83: 
 84: 
 85:     /**
 86:      * Node is closed.
 87:      * @return string
 88:      */
 89:     public function nodeClosed(NMacroNode $node)
 90:     {
 91:         return $this->compile($node, $this->macros[$node->name][1]);
 92:     }
 93: 
 94: 
 95: 
 96:     /**
 97:      * Generates code.
 98:      * @return string
 99:      */
100:     private function compile(NMacroNode $node, $def)
101:     {
102:         $writer = NPhpWriter::using($node, $this->parser->context);
103:         if (is_string($def)&& substr($def, 0, 1) !== "\0") {
104:             $code = $writer->write($def);
105:         } else {
106:             $code = callback($def)->invoke($node, $writer);
107:             if ($code === FALSE) {
108:                 return FALSE;
109:             }
110:         }
111:         return "<?php $code ?>";
112:     }
113: 
114: }
115: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0