Beispiel #1
0
 public function testSmartyPantsFormatter()
 {
     $fs = MockFileSystem::create()->withConfig(array('smartypants' => array('enabled' => true)));
     $app = $fs->getApp();
     $text = PieCrustHelper::formatText($app, 'Something...');
     $this->assertEquals("<p>Something&#8230;</p>\n", $text);
     // At the beginning you enabled SmartyPants with 'enable', and not 'enabled'.
     $fs = MockFileSystem::create()->withConfig(array('smartypants' => array('enable' => true)));
     $app = $fs->getApp();
     $text = PieCrustHelper::formatText($app, 'Something...');
     $this->assertEquals("<p>Something&#8230;</p>\n", $text);
 }
 public function transformGeneric($value, $formatterName = null)
 {
     return PieCrustHelper::formatText($this->pieCrust, $value, $formatterName);
 }
 protected function formatContentsUnsafe(array $rawSegments)
 {
     $data = DataBuilder::getPageRenderingData($this->page);
     $pieCrust = $this->page->getApp();
     $templateEngineName = $this->page->getConfig()->getValue('template_engine');
     $templateEngine = PieCrustHelper::getTemplateEngine($pieCrust, $templateEngineName);
     if (!$templateEngine) {
         throw new PieCrustException("Unknown template engine '{$templateEngineName}'.");
     }
     $contents = array();
     foreach ($rawSegments as $key => $pieces) {
         $contents[$key] = '';
         foreach ($pieces as $piece) {
             $content = $piece['content'];
             $format = $piece['format'];
             ob_start();
             try {
                 $templateEngine->renderString($content, $data);
                 $renderedContent = ob_get_clean();
             } catch (Exception $e) {
                 ob_end_clean();
                 throw $e;
             }
             if (!$format) {
                 $format = $this->page->getConfig()->getValue('format');
             }
             $renderedAndFormattedContent = PieCrustHelper::formatText($pieCrust, $renderedContent, $format);
             $contents[$key] .= $renderedAndFormattedContent;
         }
     }
     if (!empty($contents['content'])) {
         $matches = array();
         if (preg_match('/^<!--\\s*(more|(page)?break)\\s*-->\\s*$/m', $contents['content'], $matches, PREG_OFFSET_CAPTURE)) {
             // Add a special content segment for the "intro/abstract" part
             // of the article.
             $offset = $matches[0][1];
             $abstract = substr($contents['content'], 0, $offset);
             $this->page->getConfig()->appendValue('segments', 'content.abstract');
             $contents['content.abstract'] = $abstract;
         }
     }
     return $contents;
 }