/** * {element name[:method] [key]} */ public function macroElement(MacroNode $node, PhpWriter $writer) { $rawName = $node->tokenizer->fetchWord(); if ($rawName === FALSE) { throw new CompileException("Missing element type in {element}"); } $rawName = explode(':', $rawName, 2); $name = $writer->formatWord($rawName[0]); $method = isset($rawName[1]) ? ucfirst($rawName[1]) : ''; $method = Strings::match($method, '#^\\w*$#') ? "render{$method}" : "{\"render{$method}\"}"; $idRaw = $node->tokenizer->fetchWord(); $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, 6, -1); // removes array() } if (!$idRaw) { throw new CompileException("Missing element title in {element}"); } if (substr($idRaw, 0, 1) !== '$') { $id = Helpers::encodeName($idRaw); } else { $id = $idRaw; } return '$_ctrl = $_presenter->getComponent(\\CmsModule\\Content\\ElementManager::ELEMENT_PREFIX . ' . '"' . $id . '"' . ' . \'_\' . ' . $name . '); ' . '$_ctrl->setName("' . trim($idRaw, '"\'') . '");' . 'if ($presenter->isPanelOpened() && (!isset($__element) || !$__element)) { echo "<span id=\\"' . \CmsModule\Content\ElementManager::ELEMENT_PREFIX . (substr($id, 0, 1) === '$' ? '{' . $id . '}' : $id) . '_' . $rawName[0] . '\\" style=\\"display: inline-block; min-width: 50px; min-height: 25px;\\" class=\\"venne-element-container\\" data-venne-element-id=\\"' . trim($id, '"\'') . '\\" data-venne-element-name=\\"' . $rawName[0] . '\\" data-venne-element-route=\\"" . $presenter->route->id . "\\" data-venne-element-language=\\"" . $presenter->language->id . "\\" data-venne-element-buttons=\\"" . (str_replace(\'"\', "\'", json_encode($_ctrl->getViews()))) . "\\">"; }' . 'if ($_ctrl instanceof Nette\\Application\\UI\\IRenderable) $_ctrl->validateControl(); ' . "\$_ctrl->{$method}({$param});" . 'if ($presenter->isPanelOpened()) { echo "</span>"; }'; }
public function filter(\Nette\Latte\MacroNode $node, \Nette\Latte\PhpWriter $writer) { $path = $node->tokenizer->fetchWord(); $params = $writer->formatArray(); $path = $this->moduleHelpers->expandPath($path, 'Resources/public'); if (!$this->debugMode) { $sass = new \SassParser(); $file = new \SplFileInfo($path); $targetFile = $file->getBasename() . '-' . md5($path . filemtime($path)) . '.css'; $targetDir = $this->wwwCacheDir . '/sass'; $target = $targetDir . '/' . $targetFile; $targetUrl = substr($target, strlen($this->wwwDir)); if (!file_exists($targetDir)) { umask(00); mkdir($targetDir, 0777, true); } $css = $sass->toCss($path); file_put_contents($target, $css); return '$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet("' . $targetUrl . '", ' . $params . '); '; } else { return ' $_sass_file = new \\SplFileInfo("' . $path . '"); $_sass_targetFile = $_sass_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-\' . md5(\'' . $path . '\' . filemtime("' . $path . '")) . \'.css\'; $_sass_targetDir = \'' . $this->wwwCacheDir . '/sass\'; $_sass_target = $_sass_targetDir . \'/\' . $_sass_targetFile; $_sass_targetUrl = substr($_sass_target, strlen(\'' . $this->wwwDir . '\')); if (!file_exists($_sass_target)) { $_sass = new \\SassParser(); if (!file_exists($_sass_targetDir)) { umask(0000); mkdir($_sass_targetDir, 0777, true); } // Remove old files foreach (\\Nette\\Utils\\Finder::findFiles($_sass_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-*\')->from($_sass_targetDir) as $_sass_old) { unlink($_sass_old->getPathname()); } $_sass_css = $_sass->toCss(\'' . $path . '\', $_sass_target); file_put_contents($_sass_target, $_sass_css); } $control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet($_sass_targetUrl, ' . $params . '); '; } }
public function macroWidget(MacroNode $node, PhpWriter $writer) { $pair = $node->tokenizer->fetchWord(); if ($pair === FALSE) { throw new CompileException("Missing widget name in {widget}"); } $pair = explode(':', $pair, 2); $name = $writer->formatWord($pair[0]); $method = isset($pair[1]) ? ucfirst($pair[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, 6, -1); // removes array() } return ($name[0] === '$' ? "if (is_object({$name})) \$_ctrl = {$name}; else " : '') . '$_ctrl = $presenter->getComponent("widgets")->getComponent(' . $name . '); ' . 'if ($_ctrl instanceof Nette\\Application\\UI\\IRenderable) $_ctrl->validateControl(); ' . "\$_ctrl->{$method}({$param})"; }
public function filter(\Nette\Latte\MacroNode $node, PhpWriter $writer) { $files = array(); $pos = 0; while ($file = $node->tokenizer->fetchWord()) { if (strpos($file, '=>') !== FALSE) { $node->tokenizer->position = $pos; break; } $files[] = $this->wwwDir . '/' . $this->moduleHelpers->expandResource($file); $pos = $node->tokenizer->position; } if (!count($files)) { throw new CompileException("Missing file name in {js}"); } eval('$args = ' . $writer->formatArray() . ';'); return "\$_control['js']->render('" . join('\', \'', $files) . "', array('config' => " . var_export($args, TRUE) . "));"; }
/** * {control name[:method] [params]} */ public function macroControl(MacroNode $node, PhpWriter $writer) { if ($node->name === 'widget') { trigger_error('Macro {widget} is deprecated; use {control} instead.', E_USER_DEPRECATED); } $words = $node->tokenizer->fetchWords(); if (!$words) { throw new CompileException("Missing control name in {control}"); } $name = $writer->formatWord($words[0]); $method = isset($words[1]) ? ucfirst($words[1]) : ''; $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}"; $param = $writer->formatArray(); if (!Strings::contains($node->args, '=>')) { $param = substr($param, 6, -1); // removes array() } return ($name[0] === '$' ? "if (is_object({$name})) \$_ctrl = {$name}; else " : '') . '$_ctrl = $_control->getComponent(' . $name . '); ' . 'if ($_ctrl instanceof Nette\\Application\\UI\\IRenderable) $_ctrl->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_ctrl->{$method}({$param})" : $writer->write("ob_start(); \$_ctrl->{$method}({$param}); echo %modify(ob_get_clean())")); }
FALSE;}$list=array();while(($name=$node->tokenizer->fetchWord())!==FALSE){$list[]=$name[0]==='#'?'$_l->blocks["'.substr($name,1).'"]':$name;}return'if (isset('.implode(', ',$list).')):';}function macroControl(MacroNode$node,PhpWriter$writer){$pair=$node->tokenizer->fetchWord();if($pair===FALSE){throw new CompileException("Missing control name in {control}");}$pair=explode(':',$pair,2);$name=$writer->formatWord($pair[0]);$method=isset($pair[1])?ucfirst($pair[1]):'';$method=Strings::match($method,'#^('.self::RE_IDENTIFIER.'|)$#')?"render$method":"{\"render$method\"}";$param=$writer->formatArray();if(!Strings::contains($node->args,'=>')){$param=substr($param,6,-1);}return($name[0]==='$'?"if (is_object($name)) \$_ctrl = $name; else ":'').'$_ctrl = $_control->getComponent('.$name.'); '.'if ($_ctrl instanceof Nette\Application\UI\IRenderable) $_ctrl->validateControl(); '."\$_ctrl->$method($param)";}function