/**
  * Render the current Renderable for a given context.
  *
  * @since 1.0.0
  *
  * @param array $context The context in which to render the Renderable.
  *
  * @return string Rendered output of the Renderable.
  * @throws RuntimeException
  */
 public function render(array $context)
 {
     $viewName = $this->getViewName($context);
     $view = $this->viewBuilder->create($viewName);
     $context['css_class'] = $this->getCSSClass();
     $context['content'] = $this->content;
     return $view->render($context);
 }
Esempio n. 2
0
 /**
  * Instantiate an AbstractMail object.
  *
  * @since 1.0.0
  *
  * @param ConfigInterface $config The Config to use.
  *
  * @throws FailedToProcessConfigException If the Config could not be processed.
  */
 public function __construct(ConfigInterface $config)
 {
     $this->config = $config;
     $this->setFormat();
     $this->viewBuilder = new ViewBuilder($config ? $config->getSubConfig('ViewBuilder') : null);
     foreach ($this->config->getKey('view_root_locations') as $folder) {
         $this->viewBuilder->addLocation(new FilesystemLocation($folder));
     }
 }
Esempio n. 3
0
 /**
  * Render a partial view for a given URI.
  *
  * @since 0.2.0
  *
  * @param string      $view    View identifier to create a view for.
  * @param array       $context Optional. The context in which to render the view.
  * @param string|null $type    Type of view to create.
  *
  * @return string Rendered HTML content.
  */
 public function renderPart($view, array $context = null, $type = null)
 {
     if (null === $context) {
         $context = $this->context;
     }
     $this->initializeViewBuilder();
     $viewObject = $this->builder->create($view, $type);
     return $viewObject->render($context);
 }
 /**
  * Render the template for a given context.
  *
  * @since 1.0.0
  *
  * @param array $context The context in which to render the template.
  *
  * @return string The rendered content.
  */
 public function render(array $context)
 {
     $viewName = $this->getViewName($context);
     $view = $this->viewBuilder->create($viewName);
     $sanitizerType = $this->config['formats'][$context['format']]['sanitizer'];
     $sanitizerFactory = new Factory($this->config, 'sanitizers');
     $sanitizer = $sanitizerFactory->create($sanitizerType);
     $output = $view->render($context);
     return $sanitizer->sanitize($output, $context);
 }
Esempio n. 5
0
 public function testCustomConfig()
 {
     $viewBuilder = new ViewBuilder(ConfigFactory::create(['BrightNucleus' => ['View' => ['EngineFinder' => ['Engines' => ['TestEngine' => 'BrightNucleus\\View\\Tests\\TestEngine']]]]]));
     $viewBuilder->addLocation(new FilesystemLocation(__DIR__ . '/fixtures', ['.test']));
     $view = $viewBuilder->create('custom.engine');
     $result = $view->render(['testdata' => 'testvalue']);
     $this->assertEquals('Test Data = testvalue', $result);
 }