Inheritance: extends Latte\Object, implements Latte\IMacro
Example #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, '"\'') . '\');');
     });
 }
Example #2
0
function default_macros(MacroSet $set)
{
    $set->addMacro('url', 'echo \\url(%node.args);');
}
Example #3
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('secured', [$this, 'macroSecured'], '}');
 }
Example #4
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;
 }
Example #5
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('icon', [$this, 'macroIcon']);
 }
Example #6
0
 public function __construct(Latte\Engine $engine, Texy $texy)
 {
     $this->texy = $texy;
     parent::__construct($engine->getCompiler());
 }
Example #7
0
function add_default_macros(\Latte\Macros\MacroSet $set)
{
    $set->addMacro('url', 'echo \\url(%node.args);');
}
Example #8
0
 public function install(Latte\Engine $latte)
 {
     $set = new Latte\Macros\MacroSet($latte->getCompiler());
     $set->addMacro('ajax', NULL, NULL, [$this, 'macroAjax']);
 }
Example #9
0
 /**
  * EditorMacros constructor.
  */
 public function __construct(Engine $engine, IICMSAuthorizator $authorizator)
 {
     parent::__construct($engine->getCompiler());
     $this->engine = $engine;
     $this->authorizator = $authorizator;
 }
Example #10
0
use Zend\ServiceManager\ServiceLocatorInterface;
return array('factories' => array('Zf2Latte\\LatteStrategy' => function (ServiceLocatorInterface $sl) {
    return new \Zf2Latte\LatteStrategy($sl->get('Zf2Latte\\LatteRenderer'), $sl->get('Zf2Latte\\LatteResolver'), $sl->get('Zf2Latte\\LatteConfig'));
}, 'Zf2Latte\\LatteRenderer' => function (ServiceLocatorInterface $sl) {
    return new \Zf2Latte\LatteRenderer($sl->get('Latte\\Engine'), $sl->get('Zf2Latte\\LatteResolver'), $sl->get('Zf2Latte\\ZendHelpers'));
}, 'Zf2Latte\\ZendHelpers' => function (ServiceLocatorInterface $sl) {
    return new \Zf2Latte\ZendHelpers($sl->get('ViewHelperManager'));
}, 'Zf2Latte\\LatteResolver' => function (ServiceLocatorInterface $sl) {
    $config = $sl->get('config');
    return new \Zf2Latte\LatteResolver($config['view_manager'], $sl->get('Zf2Latte\\LatteConfig'));
}, 'Zf2Latte\\LatteConfig' => function (ServiceLocatorInterface $sl) {
    $config = $sl->get('config');
    $latteConfig = new \Zf2Latte\LatteConfig();
    foreach ($config['zf2_latte'] as $name => $value) {
        $latteConfig->{$name} = $value;
    }
    return $latteConfig;
}, 'Latte\\Engine' => function (ServiceLocatorInterface $sl) {
    /** @var \Zf2Latte\LatteConfig $config */
    $config = $sl->get('Zf2Latte\\LatteConfig');
    $engine = new \Latte\Engine();
    $engine->addFilter('translate', array($sl->get($config->translator_callback[0]), $config->translator_callback[1]));
    $engine->onCompile[] = function ($engine) {
        $set = \Latte\Macros\MacroSet::install($engine->getCompiler());
        $set->addMacro('href', NULL, NULL, 'echo \' href="\' . $helper->url(%node.args) . \'"\'');
    };
    $engine->setTempDirectory($config->temp_directory);
    $engine->setAutoRefresh($config->auto_refresh);
    return $engine;
}));