Пример #1
0
    public function testCompress()
    {
        $view = new View();
        $string = '  ';
        $resultString = $view->compress($string);
        $this->assertEquals(1, strlen($resultString));
        $string = ' ';
        $resultString = $view->compress($string);
        $this->assertEquals(1, strlen($resultString));
        $string = '<test>

        </test>';
        $resultString = $view->compress($string);
        $this->assertEquals(14, strlen($resultString));
        $string = 'test  test test';
        $resultString = $view->compress($string);
        $this->assertEquals(14, strlen($resultString));
    }
Пример #2
0
 /**
  * Method to render twig files with theyr specific arguments, can be used inside the element closure depending
  * on where the closure was registered. Otherwhise the use of the element variable must be provided.
  *
  * @param string $file The name of the file to render.
  * @param array  $args The parameters to pass in the render file.
  *
  * @return string The render value of the view file.
  */
 public function render($file, array $args = [])
 {
     if ($this->renderEngine == 'php') {
         $view = new View();
         return $view->renderPhpFile(rtrim($this->getFolder(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . FileHelper::ensureExtension($file, 'php'), $args);
     } elseif ($this->renderEngine == 'twig') {
         // @deprecated 1.0.0-RC2 Marked as deprecated and will be removed on 1.0.0 release.
         $twig = Yii::$app->twig->env(new Twig_Loader_Filesystem($this->getFolder()));
         return $twig->render(FileHelper::ensureExtension($file, 'twig'), $args);
     }
     throw new Exception('Not supported render engine: ' . $this->renderEngine);
 }