Skip to content

Commit

Permalink
merged branch kbond/hinclude (PR #3259)
Browse files Browse the repository at this point in the history
Commits
-------

cea2c7e removed unneeded local variable
924f378 updated changelog
72d5805 changed route name
41cc0d6 [FrameworkBundle] added support for HInclude

Discussion
----------

[FrameworkBundle] added support for HInclude

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: discuss
Example: https://github.com/kbond/symfony-standard/tree/hinclude

**Reopened this as I broke #2903**

References:

 - http://groups.google.com/group/symfony-devs/browse_thread/thread/b74e587d6f2f87b0
 - http://groups.google.com/group/symfony-devs/browse_thread/thread/8776a9833d4a5f79
 - #2903
 - #2865

[![Build Status](https://secure.travis-ci.org/kbond/symfony.png?branch=hinclude)](http://travis-ci.org/kbond/symfony)

---------------------------------------------------------------------------

by kbond at 2012-02-11T20:27:22Z

unless there is anything else I think this is ready, want me to squash again?

---------------------------------------------------------------------------

by fabpot at 2012-02-11T21:07:33Z

@kbond: Can you add some information about the changes in the CHANGELOG?

---------------------------------------------------------------------------

by Tobion at 2012-02-11T21:33:32Z

Do I see it correctly that we cannot set a default template on a per hinclude tag basis? But only global?
That's not really usefull when javascript is disabled because it should resemble the content to be included as an alternative.

---------------------------------------------------------------------------

by stof at 2012-02-11T21:42:15Z

@Tobion currently it is not possible. But changing the content on a tag basis may require changing the way the render tag look like (as there is no content in the tag currently) so this needs further discussion and @fabpot said he wants to merge a first implementation without it. See the discussion above.
  • Loading branch information
fabpot committed Feb 14, 2012
2 parents 803fba8 + cea2c7e commit 4a0057f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-2.1.md
Expand Up @@ -41,6 +41,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
* changed the default profiler storage to use the filesystem instead of SQLite
* added support for placeholders in route defaults and requirements (replaced by the value set in the service container)
* added Filesystem component as a dependency
* added support for hinclude (use ``standalone: 'js'`` in render tag)

### MonologBundle

Expand Down
Expand Up @@ -211,6 +211,7 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->children()
->scalarNode('assets_version')->defaultValue(null)->end()
->scalarNode('assets_version_format')->defaultValue('%%s?%%s')->end()
->scalarNode('hinclude_default_template')->defaultNull()->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->fixXmlConfig('resource')
Expand Down
Expand Up @@ -335,6 +335,7 @@ private function registerTemplatingConfiguration(array $config, $ide, ContainerB

$container->setParameter('templating.helper.code.file_link_format', isset($links[$ide]) ? $links[$ide] : $ide);
$container->setParameter('templating.helper.form.resources', $config['form']['resources']);
$container->setParameter('templating.hinclude.default_template', $config['hinclude_default_template']);

if ($container->getParameter('kernel.debug')) {
$loader->load('templating_debug.xml');
Expand Down
27 changes: 24 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
Expand Up @@ -114,7 +114,7 @@ public function render($controller, array $options = array())
$this->esiSupport = $this->container->has('esi') && $this->container->get('esi')->hasSurrogateEsiCapability($this->container->get('request'));
}

if ($this->esiSupport && $options['standalone']) {
if ($this->esiSupport && (true === $options['standalone'] || 'esi' === $options['standalone'])) {
$uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']);

$alt = '';
Expand All @@ -125,6 +125,17 @@ public function render($controller, array $options = array())
return $this->container->get('esi')->renderIncludeTag($uri, $alt, $options['ignore_errors'], $options['comment']);
}

if ('js' === $options['standalone']) {
$uri = $this->generateInternalUri($controller, $options['attributes'], $options['query'], false);
$defaultContent = null;

if ($template = $this->container->getParameter('templating.hinclude.default_template')) {
$defaultContent = $this->container->get('templating')->render($template);
}

return $this->renderHIncludeTag($uri, $defaultContent);
}

$request = $this->container->get('request');

// controller or URI?
Expand Down Expand Up @@ -185,14 +196,14 @@ public function render($controller, array $options = array())
*
* @return string An internal URI
*/
public function generateInternalUri($controller, array $attributes = array(), array $query = array())
public function generateInternalUri($controller, array $attributes = array(), array $query = array(), $secure = true)
{
if (0 === strpos($controller, '/')) {
return $controller;
}

$path = http_build_query($attributes);
$uri = $this->container->get('router')->generate('_internal', array(
$uri = $this->container->get('router')->generate($secure ? '_internal' : '_internal_public', array(
'controller' => $controller,
'path' => $path ?: 'none',
'_format' => $this->container->get('request')->getRequestFormat(),
Expand All @@ -204,4 +215,14 @@ public function generateInternalUri($controller, array $attributes = array(), ar

return $uri;
}

/**
* Renders an HInclude tag.
*
* @param string $uri A URI
*/
public function renderHIncludeTag($uri, $defaultContent = null)
{
return sprintf('<hx:include src="%s">%s</hx:include>', $uri, $defaultContent);
}
}
Expand Up @@ -4,7 +4,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_internal" pattern="/{controller}/{path}.{_format}">
<route id="_internal" pattern="/secure/{controller}/{path}.{_format}">
<default key="_controller">FrameworkBundle:Internal:index</default>
<requirement key="path">.+</requirement>
<requirement key="_format">[^.]+</requirement>
</route>

<route id="_internal_public" pattern="/{controller}/{path}.{_format}">
<default key="_controller">FrameworkBundle:Internal:index</default>
<requirement key="path">.+</requirement>
<requirement key="_format">[^.]+</requirement>
Expand Down

0 comments on commit 4a0057f

Please sign in to comment.