Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WebProfilerBundle] [WIP] Add help in Web Profiler #21046

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 4 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
Add help.yml + remove help config + improve design + refactoring
  • Loading branch information
maidmaid committed Dec 25, 2016
commit 09e450a22a54d0ca2d4e748268f769e5f6767d9f
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cookies:
Doc: 'https://symfony.com/doc/%s/components/http_foundation.html#setting-cookies'
API: 'http://api.symfony.com/%s/Symfony/Component/HttpFoundation/Cookie.html'
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
</service>

<service id="twig.extension.webprofiler" class="Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension" public="false">
<argument>%web_profiler.debug_toolbar.help%</argument>
<tag name="twig.extension" />
<argument type="service">
<service class="Symfony\Component\VarDumper\Dumper\HtmlDumper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestattributes }, with_context = false) }}
{% endif %}

<h3 {{ help({
doc: 'components/http_foundation.html#setting-cookies',
api: 'Symfony/Component/HttpFoundation/Cookie.html'
}) }}>Cookies</h3>
<h3 {{ help_attrs('cookies') }}>Cookies</h3>

{% if collector.requestcookies.all is empty %}
<div class="empty">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,7 @@
},

createHelp: function() {
var attributes = ['data-help-doc', 'data-help-api'];
var labels = { doc: 'Doc', api: 'API' };
var query = attributes.map(function (attr) { return '[' + attr + ']'; }).join(', ');
var helps = document.querySelectorAll(query);
var helps = document.querySelectorAll('[data-help]');

for (var i = 0; i < helps.length; i++) {
var root = document.createElement('div');
Expand All @@ -507,14 +504,13 @@
helps[i].appendChild(root);

// Add links
for (var j = 0; j < attributes.length; j++) {
if (helps[i].hasAttribute(attributes[j])) {
var link = document.createElement('a');
link.textContent = labels[attributes[j].substr('data-help-'.length)];
link.setAttribute('href', helps[i].getAttribute(attributes[j]));
link.setAttribute('target', '_blank');
container.appendChild(link);
}
var links = JSON.parse(helps[i].getAttribute('data-help'));
for (var key in links) {
var link = document.createElement('a');
link.textContent = key;
link.setAttribute('href', links[key]);
link.setAttribute('target', '_blank');
container.appendChild(link);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,14 +1001,17 @@ table.logs .metadata {
.help {
display: inline-block;
text-align: center;
background-color: #6da581;
background-color: #e0e0e0;
border-radius: 50%;
width: 21px;
height: 21px;
font-size: 13px;
line-height: 23px;
cursor: default;
margin: 0 5px;
vertical-align: middle;
border: 1px solid #c1c1c1;
text-shadow: 0 0 2px #444444;
}

.help:before {
Expand All @@ -1019,35 +1022,37 @@ table.logs .metadata {

.help:hover div {
display: block;
transform-origin: 100% 0;
}

.help div {
display: none;
background-color: #444444;
background-color: #e0e0e0;
padding: 8px;
width: auto;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
border: 1px solid #444444;
color: #FFF;
font-size: 13px;
margin-top: 5px;
line-height: 1.4;
}

.help div a {
color: white;
padding: 0 5px;
}

.help div:before {
position: absolute;
content: '';
width: 0;
height: 0;
border: 6px solid transparent;
border-bottom-color: #444444;
left: 5px;
left: 4px;
top: -12px;
}

.help div a {
color: black;
padding: 0 5px;
text-shadow: none;
font-weight: bold;
}
43 changes: 17 additions & 26 deletions 43 src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Yaml\Yaml;

/**
* Twig extension for the profiler.
Expand All @@ -28,7 +29,10 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
*/
private $valueExporter;

private $help;
/**
* @var array
*/
private $helpLinks;

/**
* @var HtmlDumper
Expand All @@ -45,11 +49,10 @@ class WebProfilerExtension extends \Twig_Extension_Profiler
*/
private $stackLevel = 0;

public function __construct(HtmlDumper $dumper = null, $help = false)
public function __construct(HtmlDumper $dumper = null)
{
$this->dumper = $dumper ?: new HtmlDumper();
$this->dumper->setOutput($this->output = fopen('php://memory', 'r+b'));
$this->help = $help;
}

public function enter(\Twig_Profiler_Profile $profile)
Expand All @@ -76,7 +79,7 @@ public function getFunctions()
return array(
new \Twig_SimpleFunction('profiler_dump', $profilerDump, array('is_safe' => array('html'), 'needs_environment' => true)),
new \Twig_SimpleFunction('profiler_dump_log', array($this, 'dumpLog'), array('is_safe' => array('html'), 'needs_environment' => true)),
new \Twig_SimpleFunction('help', array($this, 'help'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('help_attrs', array($this, 'help'), array('is_safe' => array('html'))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be prefixed with profiler_ to prevent conflicts with other extensions.

);
}

Expand Down Expand Up @@ -125,34 +128,22 @@ public function dumpValue($value)
return $this->valueExporter->exportValue($value);
}

public function help($links)
public function help($category)
{
if (!$this->help) {
return '';
if (!$this->helpLinks) {
$this->helpLinks = Yaml::parse(file_get_contents(__DIR__.'/../Resources/config/help.yml'));
}

$attrs = array();

if (isset($links['doc'])) {
$attrs['data-help-doc'] = sprintf(
'https://symfony.com/doc/%s/%s',
Kernel::MAJOR_VERSION.'.'.Kernel::MINOR_VERSION,
$links['doc']
);
if (!isset($this->helpLinks[$category])) {
throw new \Exception(sprintf('Help "%s" not found', $category));
}

if (isset($links['api'])) {
$attrs['data-help-api'] = sprintf(
'http://api.symfony.com/%s/%s',
Kernel::MAJOR_VERSION.'.'.Kernel::MINOR_VERSION,
$links['api']
);
}
$links = $this->helpLinks[$category];
array_walk($links, function (&$link) {
$link = sprintf($link, Kernel::MAJOR_VERSION.'.'.Kernel::MINOR_VERSION);
});

$html = '';
foreach ($attrs as $k => $v) {
$html .= $k.'="'.$v.'" ';
}
$html = 'data-help = "'.htmlspecialchars(json_encode($links, JSON_UNESCAPED_SLASHES)).'"';

return $html;
}
Expand Down
3 changes: 2 additions & 1 deletion 3 src/Symfony/Bundle/WebProfilerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"symfony/routing": "~2.8|~3.0",
"symfony/twig-bridge": "~2.8|~3.0",
"twig/twig": "~1.28|~2.0",
"symfony/var-dumper": "~3.2"
"symfony/var-dumper": "~3.2",
"symfony/yaml": "~2.8|~3.0"
},
"require-dev": {
"symfony/config": "~2.8|~3.0",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.