Skip to content

Commit

Permalink
minor #1441 Update documentation links (smnandre)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the main branch.

Discussion
----------

Update documentation links

* update doclinks.js (and remove jquery usage)
* update some links in BlogController
* remove references to SensioFrameworkExtraBundle

Commits
-------

cec5eb3 Update documentation links
  • Loading branch information
javiereguiluz committed Oct 23, 2023
2 parents 27f08c4 + cec5eb3 commit 578246c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
63 changes: 27 additions & 36 deletions assets/js/doclinks.js
@@ -1,63 +1,54 @@
'use strict';

// Wraps some elements in anchor tags referencing to the Symfony documentation
$(function() {
var $modal = $('#sourceCodeModal');
var $controllerCode = $modal.find('code.php');
var $templateCode = $modal.find('code.twig');
document.addEventListener('DOMContentLoaded', function() {
const modalElt = document.querySelector('#sourceCodeModal');
if (!modalElt) {
return;
}
const controllerCode = modalElt.querySelector('code.php');
const templateCode = modalElt.querySelector('code.twig');

function anchor(url, content) {
return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>';
};
}

function wrap(content, links) {
return content.replace(
new RegExp(Object.keys(links).join('|'), 'g'),
token => anchor(links[token], token)
);
};
}

// Wraps links to the Symfony documentation
$modal.find('.hljs-comment').each(function() {
$(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) {
return anchor(url, url);
}));
// Wrap Symfony Doc urls in comments
[...modalElt.querySelectorAll('.hljs-comment')].forEach((commentElt) => {
commentElt.innerHTML = commentElt.innerHTML.replace(/https:\/\/symfony.com\/[\w/.#-]+/g, (url) => anchor(url, url));
});

// Wraps Symfony's attributes
var attributes = {
'Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html',
'IsGranted': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#isgranted',
'ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html',
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes-or-annotations',
'Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html#security'
// Wraps Symfony PHP attributes in code
const attributes = {
'Cache': 'https://symfony.com/doc/current/http_cache.html#http-cache-expiration-intro',
'Route': 'https://symfony.com/doc/current/routing.html#creating-routes-as-attributes',
'IsGranted': 'https://symfony.com/doc/current/security.html#security-securing-controller-annotations'
};

$controllerCode.find('.hljs-meta').each(function() {
var src = $(this).text();

$(this).html(wrap(src, attributes));
[...controllerCode.querySelectorAll('.hljs-meta')].forEach((elt) => {
elt.innerHTML = wrap(elt.textContent, attributes);
});

// Wraps Twig's tags
$templateCode.find('.hljs-template-tag + .hljs-name').each(function() {
var tag = $(this).text();

[...templateCode.querySelectorAll('.hljs-template-tag + .hljs-name')].forEach((elt) => {
const tag = elt.textContent;
if ('else' === tag || tag.match(/^end/)) {
return;
}

var url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag;

$(this).html(anchor(url, tag));
const url = 'https://twig.symfony.com/doc/3.x/tags/' + tag + '.html#' + tag;
elt.innerHTML = anchor(url, tag);
});

// Wraps Twig's functions
$templateCode.find('.hljs-template-variable > .hljs-name').each(function() {
var func = $(this).text();

var url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func;

$(this).html(anchor(url, func));
[...templateCode.querySelectorAll('.hljs-template-variable > .hljs-name')].forEach((elt) => {
const func = elt.textContent;
const url = 'https://twig.symfony.com/doc/3.x/functions/' + func + '.html#' + func;
elt.innerHTML = anchor(url, func);
});
});
10 changes: 6 additions & 4 deletions src/Controller/BlogController.php
Expand Up @@ -70,7 +70,7 @@ public function index(Request $request, int $page, string $_format, PostReposito
* after performing a database query looking for a Post with the 'slug'
* value given in the route.
*
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
* See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
*/
#[Route('/posts/{slug}', name: 'blog_post', methods: ['GET'])]
public function postShow(Post $post): Response
Expand All @@ -93,10 +93,10 @@ public function postShow(Post $post): Response
}

/**
* NOTE: The ParamConverter mapping is required because the route parameter
* NOTE: The #[MapEntity] mapping is required because the route parameter
* (postSlug) doesn't match any of the Doctrine entity properties (slug).
*
* See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#doctrine-converter
* See https://symfony.com/doc/current/doctrine.html#doctrine-entity-value-resolver
*/
#[Route('/comment/{postSlug}/new', name: 'comment_new', methods: ['POST'])]
#[IsGranted('IS_AUTHENTICATED')]
Expand Down Expand Up @@ -140,7 +140,9 @@ public function commentNew(
* a route name for it.
*
* The "id" of the Post is passed in and then turned into a Post object
* automatically by the ParamConverter.
* automatically by the ValueResolver.
*
* See https://symfony.com/doc/current/doctrine.html#automatically-fetching-objects-entityvalueresolver
*/
public function commentForm(Post $post): Response
{
Expand Down

0 comments on commit 578246c

Please sign in to comment.