logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1341499 [7/7] - in /logging/site/branches/experimental-twig-textile: ./ libs/Twig/ libs/Twig/lib/ libs/Twig/lib/Twig/ libs/Twig/lib/Twig/Error/ libs/Twig/lib/Twig/Extension/ libs/Twig/lib/Twig/Filter/ libs/Twig/lib/Twig/Function/ libs/Twig...
Date Tue, 22 May 2012 14:42:31 GMT
Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParser/Use.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParser/Use.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParser/Use.php
(added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParser/Use.php
Tue May 22 14:42:25 2012
@@ -0,0 +1,85 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2011 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Imports blocks defined in another template into the current template.
+ *
+ * <pre>
+ * {% extends "base.html" %}
+ *
+ * {% use "blocks.html" %}
+ *
+ * {% block title %}{% endblock %}
+ * {% block content %}{% endblock %}
+ * </pre>
+ *
+ * @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details.
+ */
+class Twig_TokenParser_Use extends Twig_TokenParser
+{
+    /**
+     * Parses a token and returns a node.
+     *
+     * @param Twig_Token $token A Twig_Token instance
+     *
+     * @return Twig_NodeInterface A Twig_NodeInterface instance
+     */
+    public function parse(Twig_Token $token)
+    {
+        $template = $this->parser->getExpressionParser()->parseExpression();
+
+        if (!$template instanceof Twig_Node_Expression_Constant) {
+            throw new Twig_Error_Syntax('The template references in a "use" statement must
be a string.', $token->getLine());
+        }
+
+        $stream = $this->parser->getStream();
+
+        $targets = array();
+        if ($stream->test('with')) {
+            $stream->next();
+
+            do {
+                $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+
+                $alias = $name;
+                if ($stream->test('as')) {
+                    $stream->next();
+
+                    $alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
+                }
+
+                $targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
+
+                if (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ',')) {
+                    break;
+                }
+
+                $stream->next();
+            } while (true);
+        }
+
+        $stream->expect(Twig_Token::BLOCK_END_TYPE);
+
+        $this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets'
=> new Twig_Node($targets))));
+
+        return null;
+    }
+
+    /**
+     * Gets the tag name associated with this token parser.
+     *
+     * @return string The tag name
+     */
+    public function getTag()
+    {
+        return 'use';
+    }
+}

Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBroker.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBroker.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBroker.php
(added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBroker.php
Tue May 22 14:42:25 2012
@@ -0,0 +1,113 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ * (c) 2010 Arnaud Le Blanc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Default implementation of a token parser broker.
+ *
+ * @package twig
+ * @author  Arnaud Le Blanc <arnaud.lb@gmail.com>
+ */
+class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
+{
+    protected $parser;
+    protected $parsers = array();
+    protected $brokers = array();
+
+    /**
+     * Constructor.
+     *
+     * @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances
+     * @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface
instances
+     */
+    public function __construct($parsers = array(), $brokers = array())
+    {
+        foreach ($parsers as $parser) {
+            if (!$parser instanceof Twig_TokenParserInterface) {
+                throw new Twig_Error('$parsers must a an array of Twig_TokenParserInterface');
+            }
+            $this->parsers[$parser->getTag()] = $parser;
+        }
+        foreach ($brokers as $broker) {
+            if (!$broker instanceof Twig_TokenParserBrokerInterface) {
+                throw new Twig_Error('$brokers must a an array of Twig_TokenParserBrokerInterface');
+            }
+            $this->brokers[] = $broker;
+        }
+    }
+
+    /**
+     * Adds a TokenParser.
+     *
+     * @param Twig_TokenParserInterface $parser A Twig_TokenParserInterface instance
+     */
+    public function addTokenParser(Twig_TokenParserInterface $parser)
+    {
+        $this->parsers[$parser->getTag()] = $parser;
+    }
+
+    /**
+     * Adds a TokenParserBroker.
+     *
+     * @param Twig_TokenParserBroker $broker A Twig_TokenParserBroker instance
+     */
+    public function addTokenParserBroker(Twig_TokenParserBroker $broker)
+    {
+        $this->brokers[] = $broker;
+    }
+
+    /**
+     * Gets a suitable TokenParser for a tag.
+     *
+     * First looks in parsers, then in brokers.
+     *
+     * @param string $tag A tag name
+     *
+     * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable
TokenParser was found
+     */
+    public function getTokenParser($tag)
+    {
+        if (isset($this->parsers[$tag])) {
+            return $this->parsers[$tag];
+        }
+        $broker = end($this->brokers);
+        while (false !== $broker) {
+            $parser = $broker->getTokenParser($tag);
+            if (null !== $parser) {
+                return $parser;
+            }
+            $broker = prev($this->brokers);
+        }
+
+        return null;
+    }
+
+    public function getParsers()
+    {
+        return $this->parsers;
+    }
+
+    public function getParser()
+    {
+        return $this->parser;
+    }
+
+    public function setParser(Twig_ParserInterface $parser)
+    {
+        $this->parser = $parser;
+        foreach ($this->parsers as $tokenParser) {
+            $tokenParser->setParser($parser);
+        }
+        foreach ($this->brokers as $broker) {
+            $broker->setParser($parser);
+        }
+    }
+}

Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBrokerInterface.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBrokerInterface.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBrokerInterface.php
(added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserBrokerInterface.php
Tue May 22 14:42:25 2012
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ * (c) 2010 Arnaud Le Blanc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Interface implemented by token parser brokers.
+ *
+ * Token parser brokers allows to implement custom logic in the process of resolving a token
parser for a given tag name.
+ *
+ * @package twig
+ * @author  Arnaud Le Blanc <arnaud.lb@gmail.com>
+ */
+interface Twig_TokenParserBrokerInterface
+{
+    /**
+     * Gets a TokenParser suitable for a tag.
+     *
+     * @param  string $tag A tag name
+     *
+     * @return null|Twig_TokenParserInterface A Twig_TokenParserInterface or null if no suitable
TokenParser was found
+     */
+    function getTokenParser($tag);
+
+    /**
+     * Calls Twig_TokenParserInterface::setParser on all parsers the implementation knows
of.
+     *
+     * @param Twig_ParserInterface $parser A Twig_ParserInterface interface
+     */
+    function setParser(Twig_ParserInterface $parser);
+
+    /**
+     * Gets the Twig_ParserInterface.
+     *
+     * @return null|Twig_ParserInterface A Twig_ParserInterface instance or null
+     */
+    function getParser();
+}

Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserInterface.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserInterface.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserInterface.php
(added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenParserInterface.php
Tue May 22 14:42:25 2012
@@ -0,0 +1,42 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2010 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Interface implemented by token parsers.
+ *
+ * @package twig
+ * @author  Fabien Potencier <fabien@symfony.com>
+ */
+interface Twig_TokenParserInterface
+{
+    /**
+     * Sets the parser associated with this token parser
+     *
+     * @param $parser A Twig_Parser instance
+     */
+    function setParser(Twig_Parser $parser);
+
+    /**
+     * Parses a token and returns a node.
+     *
+     * @param Twig_Token $token A Twig_Token instance
+     *
+     * @return Twig_NodeInterface A Twig_NodeInterface instance
+     */
+    function parse(Twig_Token $token);
+
+    /**
+     * Gets the tag name associated with this token parser.
+     *
+     * @return string The tag name
+     */
+    function getTag();
+}

Added: logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenStream.php
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenStream.php?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenStream.php (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/lib/Twig/TokenStream.php Tue
May 22 14:42:25 2012
@@ -0,0 +1,145 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2009 Fabien Potencier
+ * (c) 2009 Armin Ronacher
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a token stream.
+ *
+ * @package twig
+ * @author  Fabien Potencier <fabien@symfony.com>
+ */
+class Twig_TokenStream
+{
+    protected $tokens;
+    protected $current;
+    protected $filename;
+
+    /**
+     * Constructor.
+     *
+     * @param array  $tokens   An array of tokens
+     * @param string $filename The name of the filename which tokens are associated with
+     */
+    public function __construct(array $tokens, $filename = null)
+    {
+        $this->tokens     = $tokens;
+        $this->current    = 0;
+        $this->filename   = $filename;
+    }
+
+    /**
+     * Returns a string representation of the token stream.
+     *
+     * @return string
+     */
+    public function __toString()
+    {
+        return implode("\n", $this->tokens);
+    }
+
+    public function injectTokens(array $tokens)
+    {
+        $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current),
$tokens, array_slice($this->tokens, $this->current));
+    }
+
+    /**
+     * Sets the pointer to the next token and returns the old one.
+     *
+     * @return Twig_Token
+     */
+    public function next()
+    {
+        if (!isset($this->tokens[++$this->current])) {
+            throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
+        }
+
+        return $this->tokens[$this->current - 1];
+    }
+
+    /**
+     * Tests a token and returns it or throws a syntax error.
+     *
+     * @return Twig_Token
+     */
+    public function expect($type, $value = null, $message = null)
+    {
+        $token = $this->tokens[$this->current];
+        if (!$token->test($type, $value)) {
+            $line = $token->getLine();
+            throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s"
expected%s)',
+                $message ? $message.'. ' : '',
+                Twig_Token::typeToEnglish($token->getType(), $line), $token->getValue(),
+                Twig_Token::typeToEnglish($type, $line), $value ? sprintf(' with value "%s"',
$value) : ''),
+                $line,
+                $this->filename
+            );
+        }
+        $this->next();
+
+        return $token;
+    }
+
+    /**
+     * Looks at the next token.
+     *
+     * @param integer $number
+     *
+     * @return Twig_Token
+     */
+    public function look($number = 1)
+    {
+        if (!isset($this->tokens[$this->current + $number])) {
+            throw new Twig_Error_Syntax('Unexpected end of template', -1, $this->filename);
+        }
+
+        return $this->tokens[$this->current + $number];
+    }
+
+    /**
+     * Tests the current token
+     *
+     * @return bool
+     */
+    public function test($primary, $secondary = null)
+    {
+        return $this->tokens[$this->current]->test($primary, $secondary);
+    }
+
+    /**
+     * Checks if end of stream was reached
+     *
+     * @return bool
+     */
+    public function isEOF()
+    {
+        return $this->tokens[$this->current]->getType() === Twig_Token::EOF_TYPE;
+    }
+
+    /**
+     * Gets the current token
+     *
+     * @return Twig_Token
+     */
+    public function getCurrent()
+    {
+        return $this->tokens[$this->current];
+    }
+
+    /**
+     * Gets the filename associated with this stream
+     *
+     * @return string
+     */
+    public function getFilename()
+    {
+        return $this->filename;
+    }
+}

Added: logging/site/branches/experimental-twig-textile/libs/Twig/package.xml.tpl
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/package.xml.tpl?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/package.xml.tpl (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/package.xml.tpl Tue May 22 14:42:25
2012
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.8.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+    http://pear.php.net/dtd/tasks-1.0.xsd
+    http://pear.php.net/dtd/package-2.0
+    http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Twig</name>
+ <channel>pear.twig-project.org</channel>
+ <summary>Twig is a PHP template engine.</summary>
+ <description>
+   Twig is a template language for PHP, released under the new BSD license
+   (code and documentation).
+
+   Twig uses a syntax similar to the Django and Jinja template languages which
+   inspired the Twig runtime environment.
+ </description>
+ <lead>
+  <name>Fabien Potencier</name>
+  <user>fabpot</user>
+  <email>fabien.potencier@symfony-project.org</email>
+  <active>yes</active>
+ </lead>
+ <lead>
+  <name>Armin Ronacher</name>
+  <user>armin</user>
+  <email>armin.ronacher@active-4.com</email>
+  <active>no</active>
+ </lead>
+ <date>{{ date }}</date>
+ <time>{{ time }}</time>
+ <version>
+  <release>{{ version }}</release>
+  <api>{{ api_version }}</api>
+ </version>
+ <stability>
+  <release>{{ stability }}</release>
+  <api>{{ stability }}</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD Style</license>
+ <notes>-</notes>
+ <contents>
+   <dir name="/">
+     <file name="AUTHORS" role="doc" />
+     <file name="CHANGELOG" role="doc" />
+     <file name="LICENSE" role="doc" />
+     <file name="README.markdown" role="doc" />
+     <dir name="lib">
+      <dir name="Twig">
+{{ files }}
+      </dir>
+     </dir>
+   </dir>
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.2.4</min>
+   </php>
+   <pearinstaller>
+    <min>1.4.0</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <phprelease />
+</package>

Added: logging/site/branches/experimental-twig-textile/libs/Twig/phpunit.xml.dist
URL: http://svn.apache.org/viewvc/logging/site/branches/experimental-twig-textile/libs/Twig/phpunit.xml.dist?rev=1341499&view=auto
==============================================================================
--- logging/site/branches/experimental-twig-textile/libs/Twig/phpunit.xml.dist (added)
+++ logging/site/branches/experimental-twig-textile/libs/Twig/phpunit.xml.dist Tue May 22
14:42:25 2012
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+         backupStaticAttributes="false"
+         colors="true"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         processIsolation="false"
+         stopOnFailure="false"
+         syntaxCheck="false"
+         bootstrap="test/bootstrap.php"
+>
+  <testsuites>
+    <testsuite name="Twig Test Suite">
+      <directory>./test/Twig/</directory>
+    </testsuite>
+  </testsuites>
+
+  <filter>
+    <whitelist>
+      <directory suffix=".php">./lib/Twig/</directory>
+    </whitelist>
+  </filter>
+</phpunit>



Mime
View raw message