/**
  * Parse name to determine template folder and filename.
  */
 protected function parse()
 {
     $parts = explode('::', $this->name);
     if (count($parts) === 1) {
         if (is_null($this->engine->getDirectory())) {
             $this->throwParseException('The default directory has not been defined.');
         }
         if ($parts[0] === '') {
             $this->throwParseException('The template name cannot be empty.');
         }
         $this->file = $parts[0];
     } elseif (count($parts) === 2) {
         if ($parts[0] === '') {
             $this->throwParseException('The folder name cannot be empty.');
         }
         if ($parts[1] === '') {
             $this->throwParseException('The template name cannot be empty.');
         }
         if (!$this->engine->getFolders()->exists($parts[0])) {
             $this->throwParseException('The folder "' . $parts[0] . '" does not exist.');
         }
         $this->folder = $this->engine->getFolders()->get($parts[0]);
         $this->file = $parts[1];
     } else {
         $this->throwParseException('Do not use the folder namespace seperator "::" more than once.');
     }
 }
 public function __invoke(array $input)
 {
     $name = 'index';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     //		$filename = APPPATH . 'templates/static/' . $name;
     //		if (file_exists($filename)) {
     //			echo "The file $filename does not exist";
     //			die('the file does not exist');
     //		}
     // Create new Plates instance
     $plates = new Engine(APPPATH . 'templates');
     // Register extension
     $plates->loadExtension(new Utils());
     // Check static page or partial exists
     if ($plates->exists('static/' . $name)) {
         // Render a template
         $template = $plates->render('static/' . $name);
     } else {
         header("HTTP/1.0 404 Not Found");
         echo "PHP continues.\n";
         echo "Not after a die, however.\n";
         die;
     }
     // return
     return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]);
 }
 protected function setUp()
 {
     $plates = new Engine(__DIR__ . '/Resources/views');
     $plates->setFileExtension(null);
     $plates->addData(['foo' => 'bar']);
     $this->engine = new PlatesEngineAdapter($plates);
 }
Beispiel #4
0
 /**
  * {@inheritDoc}
  */
 public function register()
 {
     $container = $this->getContainer();
     // route map which contains routes for lookup
     $container->singleton(Router\RouteMap::class, function () {
         return new Router\RouteMap();
     });
     // handles errors in the life-cycle
     $container->singleton(Handler\ErrorInterface::class, function () {
         return new Handler\Error();
     });
     // handles not found errors in the life-cycle
     $container->singleton(Handler\NotFoundInterface::class, function () {
         return new Handler\NotFound();
     });
     // plates engine
     $container->singleton(Engine::class, function () use($container) {
         $engine = new Engine(__DIR__ . '/../view');
         $engine->registerFunction('url', new View\Plates\UrlFunction($container->get(Router\RouteMap::class)));
         return $engine;
     });
     // view manager
     $container->singleton(View\Manager::class, function () use($container) {
         return new View\Manager(new View\PlatesStrategy($container->get(Engine::class)));
     });
     // router
     $container->add(Router\Router::class, function () use($container) {
         return new Router\Router($container->get(Router\RouteMap::class));
     });
 }
 /**
  * Register extension functions.
  * @return null
  */
 public function register(Engine $engine)
 {
     $engine->registerFunction('fh_default_val', array($this, 'fhDefaultVal'));
     $engine->registerFunction('fh_input_select', array($this, 'fhInputSelect'));
     $engine->registerFunction('fh_error_css_class', array($this, 'fhErrorCssClass'));
     $engine->registerFunction('fh_show_errors', array($this, 'fhShowErrors'));
 }
Beispiel #6
0
 /**
  * PlatesProvider constructor.
  * @param Engine $plates
  * @param string $root_path
  * @param string $namespace
  */
 public function __construct(Engine $plates, $root_path, $namespace)
 {
     $this->plates = $plates;
     $this->namespace = $namespace;
     if (!$plates->getFolders()->exists($namespace)) {
         $plates->addFolder($namespace, $root_path);
     }
 }
Beispiel #7
0
 /**
  * @param  Engine $engine
  */
 public function register(Engine $engine)
 {
     // Load the built in URI extension
     $engine->loadExtension(new URI($this->request->getPathInfo()));
     // Custom methods
     $engine->registerFunction('route', [$this, 'route']);
     $engine->registerFunction('asset', [$this, 'asset']);
 }
Beispiel #8
0
 private function plates()
 {
     $league = new Plates\Engine(APP . 'views');
     $league->setFileExtension('tpl');
     $league->loadExtension(new Plates\Extension\URI(trim(strtok(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']), '?'), '/')));
     $league->loadExtension(new MY\Plates\Extension());
     return $league;
 }
 /**
  * Handler.
  * 
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * 
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     $page = $request->getAttribute('page', '/index');
     $content = $this->contentLoader->getContent($page);
     $template = $content->getMetadataEntry('template');
     $params = array_merge($content->getMetadata(), ['html' => $content->getHtml()]);
     $response->getBody()->write($this->plates->render($template, $params));
     return $response->withHeader('Content-Type', 'text/html');
 }
 public function prepareEngine(Engine $engine)
 {
     // set file extension
     // $engine->setFileExtension('php');
     // Add folders
     $engine->addFolder('templates', APPPATH . 'templates');
     $engine->addFolder('partials', APPPATH . 'templates/partials');
     $engine->addFolder('staticpages', APPPATH . 'templates/staticpages');
 }
 /**
  * @param $template
  * @return bool
  */
 public function __invoke($template)
 {
     //
     $template = $this->getPlatesPath($template);
     // get the HTML for whatever is going on
     echo $this->engine->render($template);
     // because we echo'd already, we return false so it's not double-echo'd by wordpress'
     // default `include $template` statement
     return false;
 }
 public function __invoke(array $config)
 {
     $theme = $config['theme'];
     $templateEngine = new Engine();
     $templateEngine->addFolder('app', 'templates');
     $templateEngine->addFolder('theme', 'public/themes/' . $theme . '/templates');
     $templateEngine->setFileExtension('phtml');
     $templateEngine->loadExtensions([new AssetExt('public', true), new ThemeAssetExt('themes/' . $theme . '/assets')]);
     return new Application($config, new PlatesTemplateRenderer($templateEngine));
 }
Beispiel #13
0
 public function register()
 {
     $this->container->add('service.http.request', function () {
         return Request::createFromGlobals();
     });
     $this->container->add('service.http.route', function () {
         $route = new Route($this->container);
         foreach ($this->container->get('config')['http']['routes'] as $item) {
             $route->addRoute(strtoupper($item['method']), $item['path'], $item['target']);
         }
         return $route;
     });
     $this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () {
         return $this->container->get('service.http.request');
     });
     $this->container->add('service.view.view', function () {
         $view = new View();
         foreach ($this->container->get('config')['http']['views_path'] as $name => $path) {
             $view->addFolder($name, $path);
         }
         $request = $this->container->get('service.http.request');
         $view->loadExtension(new RequestExtension($request));
         $view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag()));
         $view->loadExtension(new BaseUrlExtension($request->getBasePath()));
         $assetBaseUrl = $this->container->get('config')['asset_base_url'];
         $view->loadExtension(new AssetUrlExtension($assetBaseUrl));
         if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) {
             $authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser();
             $view->loadExtension(new AuthenticatedUserExtension($authenticatedUser));
         }
         $view->addData(['applicationName' => $this->container->get('config')['application_name']]);
         return $view;
     });
 }
 public function getInstance()
 {
     if (!$this->_engineInstance) {
         // Create new Plates engine
         $this->_engineInstance = new PlatesEngine($this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->_engineInstance->setFileExtension($this->fileExtension);
         }
     }
     return $this->_engineInstance;
 }
Beispiel #15
0
 public function __construct()
 {
     $this->setUrl(env('APP_URL'));
     $this->pipe(Middleware::formatNegotiator());
     $this->pipe(Middleware::whoops());
     $this->source(new StaticFiles('build/**/*'))->build(false);
     $this->source(new StaticFiles('source/img/**/*', '/img/**/*'));
     $plates = new Engine('source/templates');
     $plates->addData(['app' => $this]);
     $this->source(new YamlFiles('source/data/*.yml'))->templates($plates);
 }
Beispiel #16
0
 /**
  * @param string $type
  * @return string
  */
 public function render($type = null)
 {
     $templates = new Engine($this->viewPath);
     if ($type === null) {
         if ($this->media === false) {
             $type = 'media';
         } else {
             $type = 'thumbnail';
         }
     }
     return $templates->render($type, $this->toArray());
 }
 /**
  * Create instance
  *
  * @return Engine
  */
 public function create(Request $request)
 {
     $engine = new Engine($this->options['view_path'], null);
     // Add folder shortcut (assets::file.js)
     $engine->addFolder('assets', $this->options['assets_path']);
     $engine->addFolder('view', $this->options['view_path']);
     $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE);
     $baseUrl = $request->getAttribute('base_url');
     // Register Asset extension
     $cacheOptions = array('cachepath' => $this->options['cache_path'], 'cachekey' => $session->get('user.locale'), 'baseurl' => $baseUrl, 'minify' => $this->options['minify']);
     $engine->loadExtension(new \Odan\Plates\Extension\AssetCache($cacheOptions));
     return $engine;
 }
Beispiel #18
0
 public function register(Fol $app)
 {
     $app['templates'] = function ($app) {
         $root = dirname(dirname(__DIR__));
         $templates = new Engine($root . '/templates');
         $icons = new Collection(new MaterialDesignIcons($root . '/assets/icons'));
         $templates->addData(['app' => $app]);
         $templates->registerFunction('icon', function ($name) use($icons) {
             return $icons->get($name);
         });
         return $templates;
     };
 }
 protected function getTemplates()
 {
     if (!self::$templates) {
         // Create new Plates engine
         self::$templates = new Engine(__DIR__ . '/../../views', 'tpl');
         self::$templates->registerFunction('substr', function ($string, $start, $length) {
             return substr($string, $start, $length);
         });
         self::$templates->registerFunction('cleanWikiSyntax', function ($string) {
             return preg_replace("/\\[(wiki|url)\\=(?P<url>https?:\\/\\/[^\\]]*)\\](?P<text>[^\\[]*)\\[\\/(wiki|url)\\]/i", "\$3", $string);
         });
     }
     return self::$templates;
 }
Beispiel #20
0
 public function register(App $glue)
 {
     $glue->singleton('League\\Plates\\Engine', function ($glue) {
         if (!$glue->config->exists('plates.path')) {
             // We need a default template folder
             throw new \Exception("You must configure the plates.path");
         }
         $engine = new Engine($glue->config->get('plates.path'));
         // Register some extensions
         $engine->loadExtension($glue->make('Glue\\Plates\\Extensions\\UrlHelpers'));
         return $engine;
     });
     $glue->alias('League\\Plates\\Engine', 'plates');
 }
 /**
  * @param BatchManager           $batches
  * @param ServerRequestInterface $request
  * @param string                 $task
  *
  * @return View
  */
 public function index(BatchManager $batches, ServerRequestInterface $request, $task = 'custom')
 {
     // Interactive mode
     $query = $request->getQueryParams();
     if (array_key_exists('interactive', $query)) {
         $this->configuration['tasks'] = $query['interactive'];
     }
     $task = $this->getTask($task);
     $sync = array_get($query, 'sync');
     $method = $sync ? 'runTask' : 'getCommandsFrom';
     $commands = $this->runner->{$method}($task);
     // Store commands for retrieval
     $hash = $batches->set($commands);
     return $this->views->render('index', ['tasks' => $commands, 'hash' => $hash, 'url' => $this->configuration->get('url')]);
 }
Beispiel #22
0
 /**
  * Render the template.
  *
  * @param string   $name
  * @param string[] $data
  *
  * @throws \LogicException
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function render($name, array $data = [])
 {
     if (!isset($this->response)) {
         throw new \LogicException(sprintf('Invalid %s object instance', ResponseInterface::class));
     }
     return $this->response->write($this->plates->render($name, $data));
 }
Beispiel #23
0
 /**
  * Get a Plates engine
  *
  * @return \League\Plates\Engine
  */
 public function getInstance()
 {
     if (!$this->engineInstance) {
         // Create new Plates engine
         $this->engineInstance = new \League\Plates\Engine($this->templatesPath ?: $this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->engineInstance->setFileExtension($this->fileExtension);
         }
         if (count($this->templatesFolders)) {
             foreach ($this->templatesFolders as $name => $path) {
                 $this->engineInstance->addFolder($name, $path);
             }
         }
     }
     return $this->engineInstance;
 }
 /**
  * Return the internal array of plates folders.
  *
  * @return \League\Plates\Template\Folder[]
  */
 private function getPlatesFolders()
 {
     $folders = $this->template->getFolders();
     $r = new ReflectionProperty($folders, 'folders');
     $r->setAccessible(true);
     return $r->getValue($folders);
 }
Beispiel #25
0
 /**
  * Get the default templates directory.
  * @return string
  */
 protected function getDefaultDirectory()
 {
     $directory = $this->engine->getDirectory();
     if (is_null($directory)) {
         throw new LogicException('The template name "' . $this->name . '" is not valid. ' . 'The default directory has not been defined.');
     }
     return $directory;
 }
Beispiel #26
0
 public function render($name, $data = [], $echo = false)
 {
     $data["layoutName"] = $this->getLayoutName();
     $data["crud"] = $this;
     $html = $this->template->render($name, $data);
     if ($echo) {
         echo $html;
     }
     return $html;
 }
Beispiel #27
0
 /**
  * Get an instance of the Plates Engine
  *
  * @return \League\Plates\Engine
  */
 public function getInstance()
 {
     if (!$this->engineInstance) {
         $this->engineInstance = new Engine($this->templatesPath ?: $this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->engineInstance->setFileExtension($this->fileExtension);
         }
         if (count($this->templatesFolders) > 0) {
             foreach ($this->templatesFolders as $name => $path) {
                 $this->engineInstance->addFolder($name, $path);
             }
         }
         if (count($this->parserExtensions) > 0) {
             foreach ($this->parserExtensions as $extension) {
                 $this->engineInstance->loadExtension($extension);
             }
         }
     }
     return $this->engineInstance;
 }
 /**
  * Apply multiple functions to variable.
  * @param  mixed  $var
  * @param  string $functions
  * @return mixed
  */
 protected function batch($var, $functions)
 {
     foreach (explode('|', $functions) as $function) {
         if ($this->engine->doesFunctionExist($function)) {
             $var = call_user_func(array($this, $function), $var);
         } elseif (is_callable($function)) {
             $var = call_user_func($function, $var);
         } else {
             throw new LogicException('The batch function could not find the "' . $function . '" function.');
         }
     }
     return $var;
 }
Beispiel #29
0
 /**
  * Plates paths loader.
  */
 protected function getLoader() : LeagueEngine
 {
     if (!$this->engine) {
         $config = $this->config;
         $this->engine = new LeagueEngine($config['template']['default'] ?? null, $config['engine']['plates']['file_extension'] ?? null);
         if (($paths = $config['template']['paths'] ?? null) !== null) {
             foreach ($paths as $name => $addPaths) {
                 $this->engine->addFolder($name, $addPaths);
             }
         }
     }
     return $this->engine;
 }
Beispiel #30
-1
 protected function setUp()
 {
     $engine = new Engine(dirname(__DIR__) . '/Fixtures');
     $this->plates = new Template($engine->setFileExtension(null));
     $this->engine = new PlatesEngine($this->plates);
     $this->template = 'foobar.plates.php';
 }