addMacro() публичный Метод

public addMacro ( $name, $begin, $end = NULL, $attr = NULL, $flags = NULL )
Пример #1
0
 /**
  * Register in base presenter.
  * When registered it will provide url for assets belonging to 
  * compiler extension class which has implemented IAssetsProvider.
  * 
  * @param Template $template
  * @param string $name Name of the macro used in templates.
  * @param string $extensionClass Compiler extension class
  */
 public function register(Template $template, $name, $extensionClass)
 {
     $latte = $template->getLatte();
     $template->_echo511_assetlocator = $this->extensionsData;
     $set = new MacroSet($latte->getCompiler());
     $set->addMacro($name, function ($node, $writer) use($extensionClass) {
         return $writer->write('echo $_echo511_assetlocator->getFilesystem(\'' . $extensionClass . '\')->getUrl(\'' . trim($node->args, '"\'') . '\');');
     });
 }
Пример #2
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('secured', [$this, 'macroSecured'], '}');
 }
Пример #3
0
function default_macros(MacroSet $set)
{
    $set->addMacro('url', 'echo \\url(%node.args);');
}
Пример #4
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('icon', [$this, 'macroIcon']);
 }
Пример #5
0
 /**
  * @return Latte\Engine
  */
 private function getLatte()
 {
     if (!isset($this->latte)) {
         $this->latte = new Latte\Engine();
         $this->latte->setTempDirectory($this->tempDir);
         $this->latte->setAutoRefresh(FALSE);
         $this->latte->onCompile[] = function (Latte\Engine $latte) {
             $set = new Latte\Macros\MacroSet($latte->getCompiler());
             $set->addMacro('link', 'echo %escape(call_user_func($getLink, %node.word, %node.array))');
         };
         $this->latte->addFilter('attachmentLabel', function (MimePart $attachment) {
             $contentDisposition = $attachment->getHeader('Content-Disposition');
             $contentType = $attachment->getHeader('Content-Type');
             $matches = Strings::match($contentDisposition, '#filename="(.+?)"#');
             return ($matches ? "{$matches['1']} " : '') . "({$contentType})";
         });
         $this->latte->addFilter('plainText', function (MimePart $part) {
             $ref = new \ReflectionProperty('Nette\\Mail\\MimePart', 'parts');
             $ref->setAccessible(TRUE);
             $queue = array($part);
             for ($i = 0; $i < count($queue); $i++) {
                 /** @var MimePart $subPart */
                 foreach ($ref->getValue($queue[$i]) as $subPart) {
                     $contentType = $subPart->getHeader('Content-Type');
                     if (Strings::startsWith($contentType, 'text/plain') && $subPart->getHeader('Content-Transfer-Encoding') !== 'base64') {
                         // Take first available plain text
                         return (string) $subPart->getBody();
                     } elseif (Strings::startsWith($contentType, 'multipart/alternative')) {
                         $queue[] = $subPart;
                     }
                 }
             }
             return $part->getBody();
         });
     }
     return $this->latte;
 }
Пример #6
0
function add_default_macros(\Latte\Macros\MacroSet $set)
{
    $set->addMacro('url', 'echo \\url(%node.args);');
}
Пример #7
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('ajax', NULL, NULL, [$this, 'macroAjax']);
 }