Exemplo n.º 1
0
 /**
  * Twig_TokenStreamからTokenを自動で解析する
  *
  * @access private
  * @param  Twig_TokenStream
  * @return Array
  */
 private function _autoParse(Twig_TokenStream $s)
 {
     $return = array();
     while (!$s->test(Twig_Token::BLOCK_END_TYPE)) {
         if ($s->test(Twig_Token::OPERATOR_TYPE)) {
             $params = array();
             // 自動的に配列Expressionを取得
             $expressions = $this->parser->getExpressionParser()->parseExpression();
             //$params = $this->_parseExpression($expressions);
             $return[] = $expressions;
         } else {
             $return[] = $this->_getNode($s);
         }
     }
     return $return;
 }
 private function getOptionValue(\Twig_TokenStream $stream)
 {
     $value = $stream->getCurrent()->getValue();
     if ($stream->test(\Twig_Token::NAME_TYPE, ['true', 'false'])) {
         return 'true' === $value ? true : false;
     }
     return $value;
 }
 /**
  * @param \Twig_TokenStream $stream
  * @param int               $lineno
  * @return WebpackInlineNode
  * @throws \Twig_Error_Syntax
  */
 private function parseInline(\Twig_TokenStream $stream, $lineno)
 {
     if ($stream->test(\Twig_Token::NAME_TYPE)) {
         $stream->next();
     }
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $this->parser->subparse(function ($token) {
         return $token->test(['end' . $this->getTag()]);
     }, true);
     $stream->expect(\Twig_Token::BLOCK_END_TYPE);
     $file = $this->parser->getEnvironment()->getLoader()->getCacheKey($stream->getFilename());
     if (!isset($this->inline_blocks[$file])) {
         $this->inline_blocks[$file] = 0;
     }
     $file_name = md5($file . $this->inline_blocks[$file]) . '.js';
     $assets = $this->extension->webpackAsset('cache.' . $file_name);
     $this->inline_blocks[$file]++;
     return new WebpackInlineNode(['js_file' => $assets['js'], 'css_file' => $assets['css']], $lineno, $this->getTag());
 }
Exemplo n.º 4
0
 /**
  * get a primitive (string, quoted string, integer or float) 
  * argument
  *
  * @param Twig_TokenStream $s
  * @return mixed
  */
 protected function _getPrimitiveArgument(Twig_TokenStream $s)
 {
     // integer & float
     if ($s->test(Twig_Token::NUMBER_TYPE)) {
         return $s->expect(Twig_Token::NUMBER_TYPE)->getValue();
     }
     // boolean
     if ($s->test(Twig_Token::NAME_TYPE, array('true', 'false'))) {
         return $s->expect(Twig_Token::NAME_TYPE)->getValue() == 'true';
     }
     // string
     if ($s->test(Twig_Token::NAME_TYPE)) {
         return $s->expect(Twig_Token::NAME_TYPE)->getValue();
     }
     // quoted string
     return $s->expect(Twig_Token::STRING_TYPE)->getValue();
 }