private function parseInline(\Twig_TokenStream $stream, $lineno)
 {
     $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());
 }
 /**
  * Get value from stream
  *
  * @param \Twig_TokenStream $stream
  * @param bool $isBool
  *
  * @return bool|string
  */
 protected function parseValue(\Twig_TokenStream $stream, $isBool = true)
 {
     $stream->next();
     $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
     if ($isBool) {
         return 'true' == $stream->expect(\Twig_Token::NAME_TYPE, ['true', 'false'])->getValue();
     }
     return $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
 }
 /**
  * Get string value from stream
  *
  * @param \Twig_TokenStream $stream
  * @return string
  */
 protected function parseStringValue(\Twig_TokenStream $stream)
 {
     $stream->next();
     $stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
     return $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
 }
Beispiel #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();
 }
 /**
  * Helper method for the common operation of grabbing the next boolean value
  * from the stream
  *
  * @param \Twig_TokenStream $stream
  * @param string $optionName
  * @return string
  */
 protected function getNextExpectedBoolValueFromStream(\Twig_TokenStream $stream, $optionName)
 {
     $stream->next();
     $stream->expect(\Twig_Token::PUNCTUATION_TYPE);
     $expr = $this->parser->getExpressionParser()->parseExpression();
     if (!$expr instanceof \Twig_Node_Expression_Constant || !is_bool($expr->getAttribute('value'))) {
         throw new SyntaxException(sprintf('The %s option must be boolean true or false (i.e. %s:false)', $optionName, $optionName), $stream->getCurrent()->getLine(), $stream->getFilename());
     }
     return $expr->getAttribute('value');
 }