Skip to content

Commit

Permalink
Merge pull request FriendsOfSymfony#17 from FriendsOfSymfony/clean_in…
Browse files Browse the repository at this point in the history
…itialize

Changed the way to build the json array for the config
  • Loading branch information
arghav committed Dec 13, 2011
2 parents d39dd5f + 9c256b8 commit 7f867fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Resources/views/initialize.html.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script type="text/javascript">
<?php if ($configMap): ?>
twttr.anywhere.config({ <?php echo $configMap ?> });
twttr.anywhere.config(<?php echo json_encode($configMap) ?>);
<?php endif; ?>

twttr.anywhere(function (T) {
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/initialize.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% autoescape false %}
<script type="text/javascript">
{% if configMap %}
twttr.anywhere.config({ {{ configMap }} });
{% if configMap is not empty %}
twttr.anywhere.config({{ configMap|json_encode }});
{% endif %}
twttr.anywhere(function (T) {
Expand Down
18 changes: 6 additions & 12 deletions Templating/Helper/TwitterAnywhereHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(EngineInterface $templating, $apiKey, $version = 1)
}

/*
*
*
*/
public function setup($parameters = array(), $name = null)
{
Expand All @@ -44,25 +44,19 @@ public function setup($parameters = array(), $name = null)
}

/*
*
*
*/
public function initialize($parameters = array(), $name = null)
{
//convert config array to map
$configMap = null;
foreach ($this->config as $key => $value){
$configMap .= $key.": ".$value.',';
}

//convert scripts into lines
$lines = '';
foreach ($this->scripts as $script) {
$lines .= rtrim($script, ';').";\n";
}
}

$name = $name ?: 'FOSTwitterBundle::initialize.html.php';
return $this->templating->render($name, $parameters + array(
'configMap' => $configMap,
'configMap' => $this->config,
'scripts' => $lines,
));
}
Expand All @@ -76,11 +70,11 @@ public function queue($script)
}

/*
*
*
*/
public function setConfig($key, $value)
{
$this->config[$key] = '"'.$value.'"';
$this->config[$key] = $value;
}

/**
Expand Down

0 comments on commit 7f867fa

Please sign in to comment.