Просмотр исходного кода

[TwigBundle] replaced the asset tag with an asset function (from {% asset css/foo.css %} to {{ asset('css/foo.css') }}

Fabien Potencier 14 лет назад
Родитель
Сommit
62cd09e708

+ 1 - 1
src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.twig

@@ -8,7 +8,7 @@
 {% block menu %}
 <div class="count">{{ '%0.0f'|format(collector.time * 1000) }} ms</div>
 <div class="count">{{ collector.querycount }}</div>
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Database" src="{% asset 'bundles/webprofiler/images/db.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Database" src="{{ asset('bundles/webprofiler/images/db.png') }}" />
 Doctrine
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.twig

@@ -7,7 +7,7 @@
 
 {% block menu %}
 <div class="count">{{ collector.querycount }}</div>
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Mongo" src="{% asset 'bundles/webprofiler/images/db.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Mongo" src="{{ asset('bundles/webprofiler/images/db.png') }}" />
 Doctrine MongoDB
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig

@@ -8,7 +8,7 @@
             body { font: 11px Verdana, Arial, sans-serif; color: #333 }
             .sf-exceptionreset, .sf-exceptionreset .block, .sf-exceptionreset #message { margin: auto }
         </style>
-        <link href="{% asset 'bundles/framework/css/exception.css' %}" rel="stylesheet" type="text/css" media="screen" />
+        <link href="{{ asset('bundles/framework/css/exception.css') }}" rel="stylesheet" type="text/css" media="screen" />
         <script type="text/javascript">
             //<![CDATA[
             function toggle(id, clazz) {

+ 8 - 5
src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php

@@ -67,8 +67,9 @@ class TemplatingExtension extends \Twig_Extension
     public function getFunctions()
     {
         return array(
-            'url'  => new \Twig_Function_Method($this, 'getUrl'),
-            'path' => new \Twig_Function_Method($this, 'getPath'),
+            'url'   => new \Twig_Function_Method($this, 'getUrl'),
+            'path'  => new \Twig_Function_Method($this, 'getPath'),
+            'asset' => new \Twig_Function_Method($this, 'getAssetUrl'),
         );
     }
 
@@ -82,6 +83,11 @@ class TemplatingExtension extends \Twig_Extension
         return $this->container->get('router')->generate($name, $parameters, true);
     }
 
+    public function getAssetUrl($location)
+    {
+        return $this->container->get('templating.helper.assets')->getUrl($location);
+    }
+
     /**
      * Returns the token parser instance to add to the existing list.
      *
@@ -102,9 +108,6 @@ class TemplatingExtension extends \Twig_Extension
             // {% stylesheets %}
             new HelperTokenParser('stylesheets', '', 'templating.helper.stylesheets', 'render'),
 
-            // {% asset 'css/blog.css' %}
-            new HelperTokenParser('asset', '<location>', 'templating.helper.assets', 'getUrl'),
-
             // {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
             new HelperTokenParser('render', '<template> [with <attributes:hash>[, <options:hash>]]', 'templating.helper.actions', 'render'),
 

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.twig

@@ -1,7 +1,7 @@
 {% extends 'WebProfilerBundle:Profiler:layout.twig' %}
 
 {% block menu %}
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Events" src="{% asset 'bundles/webprofiler/images/events.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Events" src="{{ asset('bundles/webprofiler/images/events.png') }}" />
 Events
 {% endblock %}
 

+ 2 - 2
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.twig

@@ -1,14 +1,14 @@
 {% extends 'WebProfilerBundle:Profiler:layout.twig' %}
 
 {% block head %}
-    <link href="{% asset 'bundles/framework/css/exception.css' %}" rel="stylesheet" type="text/css" media="screen" />
+    <link href="{{ asset('bundles/framework/css/exception.css') }}" rel="stylesheet" type="text/css" media="screen" />
 {% endblock %}
 
 {% block menu %}
 {% if collector.hasexception %}
     <span class="count">1</span>
 {% endif %}
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Exception" src="{% asset 'bundles/webprofiler/images/exception.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Exception" src="{{ asset('bundles/webprofiler/images/exception.png') }}" />
 Exception
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.twig

@@ -7,7 +7,7 @@
 
 {% block menu %}
 <span class="count">{{ collector.counterrors }}</span>
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Logs" src="{% asset 'bundles/webprofiler/images/logger.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Logs" src="{{ asset('bundles/webprofiler/images/logger.png') }}" />
 Logs
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.twig

@@ -6,7 +6,7 @@
 {% endblock %}
 
 {% block menu %}
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Request" src="{% asset 'bundles/webprofiler/images/request.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Request" src="{{ asset('bundles/webprofiler/images/request.png') }}" />
 Request
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/security.twig

@@ -12,7 +12,7 @@
 {% endblock %}
 
 {% block menu %}
-<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Security" src="{% asset 'bundles/webprofiler/images/security.png' %}" />
+<img style="margin: 0 5px 0 0; vertical-align: middle; width: 32px" width="32" height="32" alt="Security" src="{{ asset('bundles/webprofiler/images/security.png') }}" />
 Security
 {% endblock %}
 

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.twig

@@ -1,6 +1,6 @@
 <div class="import clearfix">
     <h3>
-        <img style="margin: 0 5px 0 0; vertical-align: middle; height: 16px" width="16" height="16" alt="Import" src="{% asset 'bundles/webprofiler/images/import.png' %}" />
+        <img style="margin: 0 5px 0 0; vertical-align: middle; height: 16px" width="16" height="16" alt="Import" src="{{ asset('bundles/webprofiler/images/import.png') }}" />
         Admin
     </h3>
 

+ 3 - 3
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.twig

@@ -3,9 +3,9 @@
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>{% block title 'Profiler' %}</title>
-        <link href="{% asset 'bundles/webprofiler/css/profiler.css' %}" rel="stylesheet" type="text/css" media="screen" />
-        <link href="{% asset 'bundles/webprofiler/css/toolbar.css' %}" rel="stylesheet" type="text/css" media="screen" />
-        <link rel="shortcut icon" type="image/x-icon" href="{% asset 'bundles/webprofiler/favicon.ico' %}" />
+        <link href="{{ asset('bundles/webprofiler/css/profiler.css') }}" rel="stylesheet" type="text/css" media="screen" />
+        <link href="{{ asset('bundles/webprofiler/css/toolbar.css') }}" rel="stylesheet" type="text/css" media="screen" />
+        <link rel="shortcut icon" type="image/x-icon" href="{{ asset('bundles/webprofiler/favicon.ico') }}" />
         {% block head '' %}
     </head>
     <body>

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.twig

@@ -3,7 +3,7 @@
 {% block body %}
     <div class="header">
         <h1>
-            <img alt="" src="{% asset 'bundles/webprofiler/images/profiler.png' %}" />
+            <img alt="" src="{{ asset('bundles/webprofiler/images/profiler.png') }}" />
             Symfony Profiler
         </h1>
         <div>

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/notfound.twig

@@ -3,7 +3,7 @@
 {% block body %}
     <div class="header">
         <h1>
-            <img alt="" src="{% asset 'bundles/webprofiler/images/profiler.png' %}" />
+            <img alt="" src="{{ asset('bundles/webprofiler/images/profiler.png') }}" />
             Symfony Profiler
         </h1>
         <div>

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.twig

@@ -1,6 +1,6 @@
 <div class="search clearfix">
     <h3>
-        <img style="margin: 0 5px 0 0; vertical-align: middle; height: 16px" width="16" height="16" alt="Search" src="{% asset 'bundles/webprofiler/images/search.png' %}" />
+        <img style="margin: 0 5px 0 0; vertical-align: middle; height: 16px" width="16" height="16" alt="Search" src="{{ asset('bundles/webprofiler/images/search.png') }}" />
         Search
     </h3>
     <form action="{{ path('_profiler_search') }}" method="get">