Beispiel #1
0
 public function __invoke(RenderContext $context, \DOMNode $node)
 {
     if ($node instanceof \DOMText) {
         return $node->textContent;
     } elseif ($node instanceof BBDomElement) {
         return $node->getOpenToken() . $context->render($node) . $node->getCloseToken();
     }
     return new \InvalidArgumentException("A DOMText node or a BBDomElement should be passed as second argument");
 }
Beispiel #2
0
 /**
  * Expects a relative url to the template that is to be included as path
  * if extension name is omitted the current extension is used
  *
  * @param string $path
  * @param string $extensionId
  * @param array $data bind additional data to the context
  * @return string
  */
 public static function inc($path, $extensionId = null, $data = array())
 {
     $context = \Context::getInstance();
     if (!is_null($extensionId) && $extensionId != $context->getExtensionName()) {
         // template is within different extension, change context
         $formerContext = $context->getExtensionName();
         $context->setExtensionName($extensionId);
     }
     if (count($data) > 0) {
         \RenderContext::pushContext($data);
     }
     $absPath = self::getTemplate($path, $extensionId);
     if (file_exists($absPath)) {
         include $absPath;
     } else {
         \common_Logger::w('Failed to include "' . $absPath . '" in template');
     }
     // restore context
     if (isset($formerContext)) {
         $context->setExtensionName($formerContext);
     }
 }
 /**
  * Returns the current language of the client interface.
  * Or in other words: The language of the current rukzuk user.
  */
 public function getCurrentClientLanguage()
 {
     return RenderContext::getLocale();
 }
/**
 * Returns whenever or not a variable with the specified key is defined
 * 
 * @param string $key
 * @return boolean
 */
function has_data($key)
{
    return RenderContext::getCurrentContext()->hasData($key);
}
 /**
  * Return a string containing the SVG transform attribute values for the padding
  *
  * @param   RenderContext $ctx  The context to determine the translation coordinates
  *
  * @return  string              The transformation string
  */
 public function getInnerTransform(RenderContext $ctx)
 {
     list($translateX, $translateY) = $ctx->toAbsolute($this->padding[self::PADDING_LEFT] + $this->getX(), $this->padding[self::PADDING_TOP] + $this->getY());
     list($scaleX, $scaleY) = $ctx->paddingToScaleFactor($this->padding);
     $scaleX *= $this->getWidth() / 100;
     $scaleY *= $this->getHeight() / 100;
     return sprintf('translate(%s, %s) scale(%s, %s)', $translateX, $translateY, $scaleX, $scaleY);
 }
Beispiel #6
0
 public function getModuleDataPath()
 {
     return RenderContext::getModuleDataPath($this->getModuleId());
 }
 /**
  * Renders the template
  * 
  * @return string the rendered view 
  */
 public function render()
 {
     if (!$this->hasTemplate()) {
         throw new common_Exception('Cannot render without template');
     }
     extract($this->variables);
     RenderContext::pushContext($this->variables);
     ob_start();
     include $this->template;
     $returnValue = ob_get_contents();
     ob_end_clean();
     //clean the extracted variables
     foreach ($this->variables as $key => $name) {
         unset(${$key});
     }
     RenderContext::popContext();
     return $returnValue;
 }
Beispiel #8
0
 /**
  * Outputs a comment based on the current render context into the document.
  *
  * @param  string  $text  The debugging text to output.
  *
  * @todo  Allow single line comments with // and #
  */
 public static function comment($text)
 {
     if (!self::$enabled) {
         return;
     }
     $ctx = RenderContext::get();
     switch ($ctx->getLanguage()) {
         case RenderContext::LANG_FBML:
         case RenderContext::LANG_HTML:
         case RenderContext::LANG_MHTML:
         case RenderContext::LANG_WML:
         case RenderContext::LANG_XHTML:
         case RenderContext::LANG_XML:
             $comment_open = '<!--';
             $comment_close = '-->';
             break;
         case RenderContext::LANG_FBJS:
         case RenderContext::LANG_JSON:
             $comment_open = '/*';
             $comment_close = '*/';
             break;
         case RenderContext::LANG_TEXT:
         default:
             # Don't know how to handle this...
             return;
     }
     $multiline = strpos($text, PHP_EOL) !== false;
     echo $comment_open, $multiline ? PHP_EOL : ' ';
     echo $text;
     echo $multiline ? PHP_EOL : ' ', $comment_close, PHP_EOL;
 }