Пример #1
0
 /**
  * {syntax ...}
  */
 public function macroSyntax($var)
 {
     switch ($var) {
         case '':
         case 'latte':
             $this->filter->setDelimiters('\\{(?![\\s\'"{}])', '\\}');
             // {...}
             break;
         case 'double':
             $this->filter->setDelimiters('\\{\\{(?![\\s\'"{}])', '\\}\\}');
             // {{...}}
             break;
         case 'asp':
             $this->filter->setDelimiters('<%\\s*', '\\s*%>');
             /* <%...%> */
             break;
         case 'python':
             $this->filter->setDelimiters('\\{[{%]\\s*', '\\s*[%}]\\}');
             // {% ... %} | {{ ... }}
             break;
         case 'off':
             $this->filter->setDelimiters('[^\\x00-\\xFF]', '');
             break;
         default:
             throw new LatteException("Unknown syntax '{$var}'", 0, $this->filter->line);
     }
 }
Пример #2
0
	/**
	 * Creates and returns configured template.
	 *
	 * @author   Jan Tvrdík, David Grudl
	 * @param    string            template file path
	 * @return   Nette\Templates\FileTemplate
	 */
	protected function createTemplate($path = NULL)
	{
		$template = new Nette\Templates\FileTemplate($path);

		// default parameters
		$template->baseUri = rtrim(Env::getVariable('baseUri', NULL), '/');
		$template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUri);
		$template->presenter = $this;
		$template->page = $this->page;
		$template->lang = $this->lang;

		// default filters
		$template->onPrepareFilters[] = function($template) {
			require_once APP_DIR . '/classes/ConfiguredTexy.php';
			require_once APP_DIR . '/classes/TexyElementsFilter.php';
			require_once APP_DIR . '/classes/LatteMacros.php';

			$texyElementsFilter = new TexyElementsFilter();
			$texyElementsFilter->texy = new ConfiguredTexy();
			$texyElementsFilter->autoChangeSyntax = TRUE;

			$latteHandler = new LatteMacros();
			$latteHandler->macros['@href'] = ' href="<?php echo %:escape%(%:macroPageLink%) ?>"';
			$latteFilter = new Nette\Templates\LatteFilter();
			$latteFilter->setHandler($latteHandler);

			$template->registerFilter($texyElementsFilter);
			$template->registerFilter($latteFilter);
		};

		// default helpers
		$template->registerHelper('escape', 'Nette\Templates\TemplateHelpers::escapeHtml');
		$template->registerHelper('escapeUrl', 'rawurlencode');
		$template->registerHelper('stripTags', 'strip_tags');
		$template->registerHelper('nl2br', 'nl2br');
		$template->registerHelper('substr', 'iconv_substr');
		$template->registerHelper('repeat', 'str_repeat');
		$template->registerHelper('replaceRE', 'Nette\String::replace');
		$template->registerHelper('implode', 'implode');
		$template->registerHelper('number', 'number_format');
		$template->registerHelperLoader('Nette\Templates\TemplateHelpers::loader');

		return $template;
	}
Пример #3
0
 /**
  * Just modifiers helper.
  */
 public function macroModifiers($content, $modifiers)
 {
     return LatteFilter::formatModifiers($content, $modifiers);
 }