Jelajahi Sumber

removed js and css helpers and Twig integration

These helpers have been removed as they do not work as expected.
Among other things, the order is not the right one when using PHP
templates, and adding assets from an included template is not
possible when using Twig templates.

This should be replaced by integrating a third-party library that
manages assets: minification, compilation, packaging, ...
Fabien Potencier 14 tahun lalu
induk
melakukan
7b7e83f428

+ 0 - 12
src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

@@ -9,8 +9,6 @@
         <parameter key="templating.loader.filesystem.class">Symfony\Component\Templating\Loader\FilesystemLoader</parameter>
         <parameter key="templating.loader.cache.class">Symfony\Component\Templating\Loader\CacheLoader</parameter>
         <parameter key="templating.loader.chain.class">Symfony\Component\Templating\Loader\ChainLoader</parameter>
-        <parameter key="templating.helper.javascripts.class">Symfony\Component\Templating\Helper\JavascriptsHelper</parameter>
-        <parameter key="templating.helper.stylesheets.class">Symfony\Component\Templating\Helper\StylesheetsHelper</parameter>
         <parameter key="templating.helper.slots.class">Symfony\Component\Templating\Helper\SlotsHelper</parameter>
         <parameter key="templating.helper.assets.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper</parameter>
         <parameter key="templating.helper.actions.class">Symfony\Bundle\FrameworkBundle\Templating\Helper\ActionsHelper</parameter>
@@ -48,16 +46,6 @@
             <call method="setDebugger"><argument type="service" id="templating.debugger" on-invalid="ignore" /></call>
         </service>
 
-        <service id="templating.helper.javascripts" class="%templating.helper.javascripts.class%">
-            <tag name="templating.helper" alias="javascripts" />
-            <argument type="service" id="templating.helper.assets" />
-        </service>
-
-        <service id="templating.helper.stylesheets" class="%templating.helper.stylesheets.class%">
-            <tag name="templating.helper" alias="stylesheets" />
-            <argument type="service" id="templating.helper.assets" />
-        </service>
-
         <service id="templating.helper.slots" class="%templating.helper.slots.class%">
             <tag name="templating.helper" alias="slots" />
         </service>

+ 0 - 16
src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php

@@ -7,10 +7,6 @@ use Symfony\Bundle\TwigBundle\TokenParser\IncludeTokenParser;
 use Symfony\Bundle\TwigBundle\TokenParser\UrlTokenParser;
 use Symfony\Bundle\TwigBundle\TokenParser\PathTokenParser;
 use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
-use Symfony\Bundle\TwigBundle\TokenParser\StylesheetTokenParser;
-use Symfony\Bundle\TwigBundle\TokenParser\StylesheetsTokenParser;
-use Symfony\Bundle\TwigBundle\TokenParser\JavascriptTokenParser;
-use Symfony\Bundle\TwigBundle\TokenParser\JavascriptsTokenParser;
 use Symfony\Component\Yaml\Dumper as YamlDumper;
 
 /*
@@ -100,18 +96,6 @@ class TemplatingExtension extends \Twig_Extension
     public function getTokenParsers()
     {
         return array(
-            // {% javascript 'bundles/blog/js/blog.js' %}
-            new JavascriptTokenParser(),
-
-            // {% javascripts %}
-            new JavascriptsTokenParser(),
-
-            // {% stylesheet 'bundles/blog/css/blog.css' with { 'media': 'screen' } %}
-            new StylesheetTokenParser(),
-
-            // {% stylesheets %}
-            new StylesheetsTokenParser(),
-
             // {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
             new RenderTokenParser(),
 

+ 0 - 42
src/Symfony/Bundle/TwigBundle/Node/JavascriptNode.php

@@ -1,42 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\Node;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a javascript node.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class JavascriptNode extends \Twig_Node
-{
-    public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $attributes, $lineno, $tag = null)
-    {
-        parent::__construct(array('expr' => $expr, 'attributes' => $attributes), array(), $lineno, $tag);
-    }
-
-    /**
-     * Compiles the node to PHP.
-     *
-     * @param \Twig_Compiler A Twig_Compiler instance
-     */
-    public function compile(\Twig_Compiler $compiler)
-    {
-        $compiler
-            ->addDebugInfo($this)
-            ->write("echo \$this->env->getExtension('templating')->getContainer()->get('templating.helper.javascripts')->add(")
-            ->subcompile($this->getNode('expr'))
-            ->raw(', ')
-            ->subcompile($this->getNode('attributes'))
-            ->raw(");\n")
-        ;
-    }
-}

+ 0 - 38
src/Symfony/Bundle/TwigBundle/Node/JavascriptsNode.php

@@ -1,38 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\Node;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a javascripts node.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class JavascriptsNode extends \Twig_Node
-{
-    public function __construct($lineno, $tag = null)
-    {
-        parent::__construct(array(), array(), $lineno, $tag);
-    }
-
-    /**
-     * Compiles the node to PHP.
-     *
-     * @param \Twig_Compiler A Twig_Compiler instance
-     */
-    public function compile(\Twig_Compiler $compiler)
-    {
-        $compiler
-            ->addDebugInfo($this)
-            ->write("echo \$this->env->getExtension('templating')->getContainer()->get('templating.helper.javascripts')->render();\n")
-        ;
-    }
-}

+ 0 - 42
src/Symfony/Bundle/TwigBundle/Node/StylesheetNode.php

@@ -1,42 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\Node;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a stylesheet node.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class StylesheetNode extends \Twig_Node
-{
-    public function __construct(\Twig_Node_Expression $expr, \Twig_Node_Expression $attributes, $lineno, $tag = null)
-    {
-        parent::__construct(array('expr' => $expr, 'attributes' => $attributes), array(), $lineno, $tag);
-    }
-
-    /**
-     * Compiles the node to PHP.
-     *
-     * @param \Twig_Compiler A Twig_Compiler instance
-     */
-    public function compile(\Twig_Compiler $compiler)
-    {
-        $compiler
-            ->addDebugInfo($this)
-            ->write("echo \$this->env->getExtension('templating')->getContainer()->get('templating.helper.stylesheets')->add(")
-            ->subcompile($this->getNode('expr'))
-            ->raw(', ')
-            ->subcompile($this->getNode('attributes'))
-            ->raw(");\n")
-        ;
-    }
-}

+ 0 - 38
src/Symfony/Bundle/TwigBundle/Node/StylesheetsNode.php

@@ -1,38 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\Node;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Represents a stylesheets node.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class StylesheetsNode extends \Twig_Node
-{
-    public function __construct($lineno, $tag = null)
-    {
-        parent::__construct(array(), array(), $lineno, $tag);
-    }
-
-    /**
-     * Compiles the node to PHP.
-     *
-     * @param \Twig_Compiler A Twig_Compiler instance
-     */
-    public function compile(\Twig_Compiler $compiler)
-    {
-        $compiler
-            ->addDebugInfo($this)
-            ->write("echo \$this->env->getExtension('templating')->getContainer()->get('templating.helper.stylesheets')->render();\n")
-        ;
-    }
-}

+ 0 - 57
src/Symfony/Bundle/TwigBundle/TokenParser/JavascriptTokenParser.php

@@ -1,57 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\TokenParser;
-
-use Symfony\Bundle\TwigBundle\Node\JavascriptNode;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * 
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class JavascriptTokenParser 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)
-    {
-        $expr = $this->parser->getExpressionParser()->parseExpression();
-
-        // attributes
-        if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
-            $this->parser->getStream()->next();
-
-            $attributes = $this->parser->getExpressionParser()->parseExpression();
-        } else {
-            $attributes = new \Twig_Node_Expression_Array(array(), $token->getLine());
-        }
-
-        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
-
-        return new JavascriptNode($expr, $attributes, $token->getLine(), $this->getTag());
-    }
-
-    /**
-     * Gets the tag name associated with this token parser.
-     *
-     * @param string The tag name
-     */
-    public function getTag()
-    {
-        return 'javascript';
-    }
-}

+ 0 - 46
src/Symfony/Bundle/TwigBundle/TokenParser/JavascriptsTokenParser.php

@@ -1,46 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\TokenParser;
-
-use Symfony\Bundle\TwigBundle\Node\JavascriptsNode;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * 
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class JavascriptsTokenParser 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)
-    {
-        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
-
-        return new JavascriptsNode($token->getLine(), $this->getTag());
-    }
-
-    /**
-     * Gets the tag name associated with this token parser.
-     *
-     * @param string The tag name
-     */
-    public function getTag()
-    {
-        return 'javascripts';
-    }
-}

+ 0 - 57
src/Symfony/Bundle/TwigBundle/TokenParser/StylesheetTokenParser.php

@@ -1,57 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\TokenParser;
-
-use Symfony\Bundle\TwigBundle\Node\StylesheetNode;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * 
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class StylesheetTokenParser 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)
-    {
-        $expr = $this->parser->getExpressionParser()->parseExpression();
-
-        // attributes
-        if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
-            $this->parser->getStream()->next();
-
-            $attributes = $this->parser->getExpressionParser()->parseExpression();
-        } else {
-            $attributes = new \Twig_Node_Expression_Array(array(), $token->getLine());
-        }
-
-        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
-
-        return new StylesheetNode($expr, $attributes, $token->getLine(), $this->getTag());
-    }
-
-    /**
-     * Gets the tag name associated with this token parser.
-     *
-     * @param string The tag name
-     */
-    public function getTag()
-    {
-        return 'stylesheet';
-    }
-}

+ 0 - 46
src/Symfony/Bundle/TwigBundle/TokenParser/StylesheetsTokenParser.php

@@ -1,46 +0,0 @@
-<?php
-
-namespace Symfony\Bundle\TwigBundle\TokenParser;
-
-use Symfony\Bundle\TwigBundle\Node\StylesheetsNode;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * 
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class StylesheetsTokenParser 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)
-    {
-        $this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
-
-        return new StylesheetsNode($token->getLine(), $this->getTag());
-    }
-
-    /**
-     * Gets the tag name associated with this token parser.
-     *
-     * @param string The tag name
-     */
-    public function getTag()
-    {
-        return 'stylesheets';
-    }
-}

+ 0 - 110
src/Symfony/Component/Templating/Helper/JavascriptsHelper.php

@@ -1,110 +0,0 @@
-<?php
-
-namespace Symfony\Component\Templating\Helper;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * JavascriptsHelper is a helper that manages JavaScripts.
- *
- * Usage:
- *
- * <code>
- *   $view['javascripts']->add('foo.js');
- *   echo $view['javascripts'];
- * </code>
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class JavascriptsHelper extends Helper
-{
-    protected $javascripts = array();
-    protected $assetHelper;
-
-    /**
-     * Constructor.
-     *
-     * @param AssetsHelper $assetHelper A AssetsHelper instance
-     */
-    public function __construct(AssetsHelper $assetHelper)
-    {
-        $this->assetHelper = $assetHelper;
-    }
-
-    /**
-     * Adds a JavaScript file.
-     *
-     * @param string $javascript A JavaScript file path
-     * @param array  $attributes An array of attributes
-     */
-    public function add($javascript, $attributes = array())
-    {
-        $this->javascripts[$this->assetHelper->getUrl($javascript)] = $attributes;
-    }
-
-    /**
-     * Returns all JavaScript files.
-     *
-     * @return array An array of JavaScript files to include
-     */
-    public function get()
-    {
-        return $this->javascripts;
-    }
-
-    /**
-     * Returns HTML representation of the links to JavaScripts.
-     *
-     * @return string The HTML representation of the JavaScripts
-     */
-    public function render()
-    {
-        $html = '';
-        foreach ($this->javascripts as $path => $attributes) {
-            $atts = '';
-            foreach ($attributes as $key => $value) {
-                $atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
-            }
-
-            $html .= sprintf('<script type="text/javascript" src="%s"%s></script>', $path, $atts)."\n";
-        }
-
-        return $html;
-    }
-
-    /**
-     * Outputs HTML representation of the links to JavaScripts.
-     *
-     */
-    public function output()
-    {
-        echo $this->render();
-    }
-
-    /**
-     * Returns a string representation of this helper as HTML.
-     *
-     * @return string The HTML representation of the JavaScripts
-     */
-    public function __toString()
-    {
-        return $this->render();
-    }
-
-    /**
-     * Returns the canonical name of this helper.
-     *
-     * @return string The canonical name
-     */
-    public function getName()
-    {
-        return 'javascripts';
-    }
-}

+ 0 - 110
src/Symfony/Component/Templating/Helper/StylesheetsHelper.php

@@ -1,110 +0,0 @@
-<?php
-
-namespace Symfony\Component\Templating\Helper;
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * StylesheetsHelper is a helper that manages stylesheets.
- *
- * Usage:
- *
- * <code>
- *   $view['stylesheets']->add('foo.css', array('media' => 'print'));
- *   echo $view['stylesheets'];
- * </code>
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
-class StylesheetsHelper extends Helper
-{
-    protected $stylesheets = array();
-    protected $assetHelper;
-
-    /**
-     * Constructor.
-     *
-     * @param AssetsHelper $assetHelper A AssetsHelper instance
-     */
-    public function __construct(AssetsHelper $assetHelper)
-    {
-        $this->assetHelper = $assetHelper;
-    }
-
-    /**
-     * Adds a stylesheets file.
-     *
-     * @param string $stylesheet A stylesheet file path
-     * @param array  $attributes An array of attributes
-     */
-    public function add($stylesheet, $attributes = array())
-    {
-        $this->stylesheets[$this->assetHelper->getUrl($stylesheet)] = $attributes;
-    }
-
-    /**
-     * Returns all stylesheet files.
-     *
-     * @return array An array of stylesheet files to include
-     */
-    public function get()
-    {
-        return $this->stylesheets;
-    }
-
-    /**
-     * Returns HTML representation of the links to stylesheets.
-     *
-     * @return string The HTML representation of the stylesheets
-     */
-    public function render()
-    {
-        $html = '';
-        foreach ($this->stylesheets as $path => $attributes) {
-            $atts = '';
-            foreach ($attributes as $key => $value) {
-                $atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
-            }
-
-            $html .= sprintf('<link href="%s" rel="stylesheet" type="text/css"%s />', $path, $atts)."\n";
-        }
-
-        return $html;
-    }
-
-    /**
-     * Outputs HTML representation of the links to stylesheets.
-     *
-     */
-    public function output()
-    {
-        echo $this->render();
-    }
-
-    /**
-     * Returns a string representation of this helper as HTML.
-     *
-     * @return string The HTML representation of the stylesheets
-     */
-    public function __toString()
-    {
-        return $this->render();
-    }
-
-    /**
-     * Returns the canonical name of this helper.
-     *
-     * @return string The canonical name
-     */
-    public function getName()
-    {
-        return 'stylesheets';
-    }
-}

+ 0 - 42
tests/Symfony/Tests/Component/Templating/Helper/JavascriptsHelperTest.php

@@ -1,42 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Tests\Component\Templating\Helper;
-
-use Symfony\Component\Templating\Helper\AssetsHelper;
-use Symfony\Component\Templating\Helper\JavascriptsHelper;
-use Symfony\Component\Templating\Loader\FilesystemLoader;
-
-class JavascriptsHelperTest extends \PHPUnit_Framework_TestCase
-{
-    public function testAdd()
-    {
-        $assetHelper = new AssetsHelper();
-        $helper = new JavascriptsHelper($assetHelper);
-        $helper->add('foo');
-        $this->assertEquals(array('/foo' => array()), $helper->get(), '->add() adds a JavaScript');
-        $helper->add('/foo');
-        $this->assertEquals(array('/foo' => array()), $helper->get(), '->add() does not add the same JavaScript twice');
-        $helper = new JavascriptsHelper($assetHelper);
-        $assetHelper->setBaseURLs('http://assets.example.com/');
-        $helper->add('foo');
-        $this->assertEquals(array('http://assets.example.com/foo' => array()), $helper->get(), '->add() converts the JavaScript to a public path');
-    }
-
-    public function testMagicToString()
-    {
-        $assetHelper = new AssetsHelper();
-        $assetHelper->setBaseURLs('');
-        $helper = new JavascriptsHelper($assetHelper);
-        $helper->add('foo', array('class' => 'ba>'));
-        $this->assertEquals('<script type="text/javascript" src="/foo" class="ba&gt;"></script>'."\n", $helper->__toString(), '->__toString() converts the JavaScript configuration to HTML');
-    }
-}

+ 0 - 42
tests/Symfony/Tests/Component/Templating/Helper/StylesheetsHelperTest.php

@@ -1,42 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Tests\Component\Templating\Helper;
-
-use Symfony\Component\Templating\Helper\AssetsHelper;
-use Symfony\Component\Templating\Helper\StylesheetsHelper;
-use Symfony\Component\Templating\Loader\FilesystemLoader;
-
-class StylesheetsHelperTest extends \PHPUnit_Framework_TestCase
-{
-    public function testAdd()
-    {
-        $assetHelper = new AssetsHelper();
-        $helper = new StylesheetsHelper($assetHelper);
-        $helper->add('foo');
-        $this->assertEquals(array('/foo' => array()), $helper->get(), '->add() adds a stylesheet');
-        $helper->add('/foo');
-        $this->assertEquals(array('/foo' => array()), $helper->get(), '->add() does not add the same stylesheet twice');
-        $helper = new StylesheetsHelper($assetHelper);
-        $assetHelper->setBaseURLs('http://assets.example.com/');
-        $helper->add('foo');
-        $this->assertEquals(array('http://assets.example.com/foo' => array()), $helper->get(), '->add() converts the stylesheet to a public path');
-    }
-
-    public function testMagicToString()
-    {
-        $assetHelper = new AssetsHelper();
-        $assetHelper->setBaseURLs('');
-        $helper = new StylesheetsHelper($assetHelper);
-        $helper->add('foo', array('media' => 'ba>'));
-        $this->assertEquals('<link href="/foo" rel="stylesheet" type="text/css" media="ba&gt;" />'."\n", $helper->__toString(), '->__toString() converts the stylesheet configuration to HTML');
-    }
-}