コード例 #1
0
ファイル: WithHelper.php プロジェクト: dmitriz/Platform
 /**
  * Execute the helper
  *
  * @param Handlebars_Template $template The template instance
  * @param Handlebars_Context  $context  The current context
  * @param array                $args     The arguments passed the the helper
  * @param string               $source   The source
  *
  * @return {mixed}
  */
 public function execute(Handlebars_Template $template, Handlebars_Context $context, $args, $source)
 {
     $context->with($args);
     $buffer = $template->render($context);
     $context->pop();
     return $buffer;
 }
コード例 #2
0
ファイル: EachHelper.php プロジェクト: dmitriz/Platform
 /**
  * Execute the helper
  *
  * @param Handlebars_Template $template The template instance
  * @param Handlebars_Context  $context  The current context
  * @param array                $args     The arguments passed the the helper
  * @param string               $source   The source
  *
  * @return {mixed}
  */
 public function execute(Handlebars_Template $template, Handlebars_Context $context, $args, $source)
 {
     $tmp = $context->get($args);
     $buffer = '';
     if (!$tmp) {
         $template->setStopToken('else');
         $template->discard();
         $template->setStopToken(false);
         $buffer = $template->render($context);
     } elseif (is_array($tmp) || $tmp instanceof Traversable) {
         $isList = is_array($tmp) && array_keys($tmp) === range(0, count($tmp) - 1);
         $index = 0;
         $lastIndex = $isList ? count($tmp) - 1 : false;
         foreach ($tmp as $key => $var) {
             $specialVariables = array('@index' => $index, '@first' => $index === 0, '@last' => $index === $lastIndex);
             if (!$isList) {
                 $specialVariables['@key'] = $key;
             }
             $context->pushSpecialVariables($specialVariables);
             $context->push($var);
             $template->setStopToken('else');
             $template->rewind();
             $buffer .= $template->render($context);
             $context->pop();
             $context->popSpecialVariables();
             $index++;
         }
         $template->setStopToken(false);
     }
     return $buffer;
 }
コード例 #3
0
ファイル: UnlessHelper.php プロジェクト: dmitriz/Platform
 /**
  * Execute the helper
  *
  * @param Handlebars_Template $template The template instance
  * @param Handlebars_Context  $context  The current context
  * @param array                $args     The arguments passed the the helper
  * @param string               $source   The source
  *
  * @return {mixed}
  */
 public function execute(Handlebars_Template $template, Handlebars_Context $context, $args, $source)
 {
     $parsedArgs = $template->parseArguments($args);
     $tmp = $context->get($parsedArgs[0]);
     $context->push($context->last());
     if (!$tmp) {
         $template->setStopToken('else');
         $buffer = $template->render($context);
         $template->setStopToken(false);
     } else {
         $template->setStopToken('else');
         $template->discard();
         $template->setStopToken(false);
         $buffer = $template->render($context);
     }
     $context->pop();
     return $buffer;
 }
コード例 #4
0
ファイル: Template.php プロジェクト: dmitriz/Platform
 /**
  * Process variable
  *
  * @param Handlebars_Context $context current context
  * @param array   $current section node data
  * @param boolean $escaped escape result or not
  *
  * @return {string} the result
  */
 private function _getVariable(Handlebars_Context $context, $current, $escaped)
 {
     $name = $current[Handlebars_Tokenizer::NAME];
     $value = $context->get($name);
     if (is_array($value)) {
         return 'Array';
     }
     if ($escaped) {
         $args = $this->handlebars->getEscapeArgs();
         array_unshift($args, $value);
         $value = call_user_func_array($this->handlebars->getEscape(), array_values($args));
     }
     return $value;
 }
コード例 #5
0
ファイル: Template.php プロジェクト: postmatic/beta-dist
 /**
  * Process partial section
  *
  * @param Handlebars_Context $context current context
  * @param array              $current section node data
  * @param boolean            $escaped escape result or not
  *
  * @return string the result
  */
 private function _variables($context, $current, $escaped)
 {
     $name = $current[Handlebars_Tokenizer::NAME];
     $value = $context->get($name);
     if ($name == '@index') {
         return $context->lastIndex();
     }
     if ($name == '@key') {
         return $context->lastKey();
     }
     if ($escaped) {
         $args = $this->handlebars->getEscapeArgs();
         array_unshift($args, $value);
         $value = call_user_func_array($this->handlebars->getEscape(), array_values($args));
     }
     return $value;
 }