8000 [Var-Dumper] added feature to set default nodes collapsed by MGDSoft · Pull Request #18148 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Var-Dumper] added feature to set default nodes collapsed #18148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Var-Dumper] added feature to set default nodes collapsed
modify js htmldumper and add options to configure js
  • Loading branch information
MGDSoft committed Apr 2, 2016
commit 91058a585375bfc98e0f6a7294b9e033efe1dda2
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Tests/Extension/DumpExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ public function getDumpArgs()
{
return array(
array(array(), array(), '', false),
array(array(), array(), "<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\">[]\n</pre><script>Sfdump(\"sf-dump\")</script>\n"),
array(array(), array(), "<pre class=sf-dump id=sf-dump data-indent-pad=\" \">[]\n</pre><script>Sfdump(\"sf-dump\")</script>\n"),
array(
array(),
array(123, 456),
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n"
."<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>456</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n"
."<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>456</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
),
array(
array('foo' => 'bar'),
array(),
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-note>array:1</span> [<samp>\n"
"<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-note>array:1</span> [<samp>\n"
." \"<span class=sf-dump-key>foo</span>\" => \"<span class=sf-dump-str title=\"3 characters\">bar</span>\"\n"
."</samp>]\n"
."</pre><script>Sfdump(\"sf-dump\")</script>\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testDump()

$xDump = array(
array(
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \" data-collapsed-by-default-nodes-higher-than=\"1\"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'name' => 'DumpDataCollectorTest.php',
'file' => __FILE__,
'line' => $line,
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testCollectHtml()
$line = __LINE__ - 1;
$file = __FILE__;
$xOutput = <<<EOTXT
<pre class=sf-dump id=sf-dump data-indent-pad=" " data-collapsed-by-default-nodes-higher-than="1"><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<pre class=sf-dump id=sf-dump data-indent-pad=" "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
<span class=sf-dump-num>123</span>
</pre>

Expand Down
51 changes: 34 additions & 17 deletions src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class HtmlDumper extends CliDumper
public static $defaultOutput = 'php://output';

protected $dumpHeader;
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s" data-collapsed-by-default-nodes-higher-than="%s">';
protected $dumpSuffix = '</pre><script>Sfdump("%s")</script>';
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s">';
protected $dumpSuffix = '</pre><script>Sfdump("%s"%s)</script>';
protected $dumpId = 'sf-dump';
protected $colors = true;
protected $headerIsDumped = false;
Expand All @@ -45,10 +45,12 @@ class HtmlDumper extends CliDumper
'index' => 'color:#1299DA',
);

protected $jsProperties = array(
protected $jsPropertiesDefault = array(
'collapsedByDefaultNodesHigherThan' => 1,
);

protected $jsProperties = array();

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -80,7 +82,7 @@ public function setStyles(array $styles)
}

/**
* Configures js properties.
* Configures js properties, it is not necessary to add all
*
* @param array $jsProperties A map of jsProperties names to customize the behavior.
*/
Expand Down Expand Up @@ -131,11 +133,27 @@ protected function getDumpHeader()
return $this->dumpHeader;
}

$line = <<<'EOHTML'
<script>

$line = "<script>
Sfdump = window.Sfdump || (function (doc) {

var defaultOptions = ".json_encode($this->jsPropertiesDefault).";

";

$line .= <<<'EOHTML'

function extend(a, b){
if (!a) a= {};
if (!b) b= {};

for(var key in b)
if(b.hasOwnProperty(key))
a[key] = b[key];
return a;
}

options = extend(defaultOptions, options);

var refStyle = doc.createElement('style'),
rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
idRx = /\bsf-dump-\d+-ref[012]\w+\b/,
Expand Down Expand Up @@ -188,9 +206,9 @@ function toggle(a, recursive) {
return true;
};

return function (root) {
return function (root, options) {
root = doc.getElementById(root);
var collapsedByDefaultNodesHigherThan = root.getAttribute('data-collapsed-by-default-nodes-higher-than');
options = extend(defaultOptions, options);

function a(e, f) {
addEventListener(root, e, function (e) {
Expand Down Expand Up @@ -297,7 +315,7 @@ function getLevelNodeFromRoot(node, level) {
a.innerHTML += '<span>▼</span>';
a.className += ' sf-dump-toggle';

if (getLevelNodeFromRoot(elt) > collapsedByDefaultNodesHigherThan) {
if (getLevelNodeFromRoot(elt) > options.collapsedByDefaultNodesHigherThan) {
toggle(a);
}

Expand Down Expand Up @@ -462,19 +480,18 @@ protected function style($style, $value, $attr = array())
protected function dumpLine($depth, $endOfValue = false)
{
if (-1 === $this->lastDepth) {
$this->line = sprintf(
$this->dumpPrefix,
$this->dumpId,
$this->indentPad,
$this->jsProperties['collapsedByDefaultNodesHigherThan']
).$this->line;
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
}
if (!$this->headerIsDumped) {
$this->line = $this->getDumpHeader().$this->line;
}

if (-1 === $depth) {
$this->line .= sprintf($this->dumpSuffix, $this->dumpId);
$this->line .= sprintf(
$this->dumpSuffix,
$this->dumpId,
$this->jsProperties ? ','. json_encode($this->jsProperties) : ''
);
}
$this->lastDepth = $depth;

Expand Down
0