Skip to content

Move redditify to Sculpin Bundle #230

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions app/SculpinKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use App\Bundles\AtomFeedGeneratorBundle\SculpinAtomFeedGeneratorBundle;
use App\Bundles\MermaidBundle\SculpinMermaidBundle;
use App\Bundles\PhpFoundationBundle\PhpFoundationBundle;
use App\Bundles\RedditifyBundle\SculpinRedditifyBundle;
use App\Bundles\SharingImageGeneratorBundle\SculpinSharingImageGeneratorBundle;
use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel;

Expand All @@ -14,6 +15,7 @@ protected function getAdditionalSculpinBundles(): array
SculpinAtomFeedGeneratorBundle::class,
SculpinSharingImageGeneratorBundle::class,
SculpinMermaidBundle::class,
SculpinRedditifyBundle::class,
PhpFoundationBundle::class,
App\Bundles\RedirectBundle\SculpinRedirectBundle::class,
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Bundles\RedditifyBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class SculpinRedditifyExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
}
}
55 changes: 55 additions & 0 deletions app/src/Bundles/RedditifyBundle/RedditifyAssetCopier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Bundles\RedditifyBundle;

use Dflydev\DotAccessConfiguration\Configuration;
use Sculpin\Core\Sculpin;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

class RedditifyAssetCopier implements EventSubscriberInterface
{
private Configuration $configuration;
private Filesystem $filesystem;

public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
$this->filesystem = new Filesystem();
}

public static function getSubscribedEvents(): array
{
return [
Sculpin::EVENT_BEFORE_RUN => 'copyRedditifyAssets',
];
}

public function copyRedditifyAssets(): void
{
$env = $this->configuration->get('env') ?? 'dev';
$outputDir = "output_{$env}";

$jsTargetDir = "{$outputDir}/assets/js";
$cssTargetDir = "{$outputDir}/assets/css";

$this->filesystem->mkdir([$jsTargetDir, $cssTargetDir]);

$nodePath = 'node_modules/redditify/dist/';

if (file_exists($nodePath . 'redditify.min.js')) {
$this->filesystem->copy(
$nodePath . 'redditify.min.js',
$jsTargetDir . '/redditify.min.js'
);
}

if (file_exists($nodePath . 'redditify.css')) {
$this->filesystem->copy(
$nodePath . 'redditify.css',
$cssTargetDir . '/redditify.css'
);
}
}
}
20 changes: 20 additions & 0 deletions app/src/Bundles/RedditifyBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="sculpin_redditify.asset_copier"
class="App\Bundles\RedditifyBundle\RedditifyAssetCopier">
<argument type="service" id="sculpin.site_configuration"/>

<tag name="kernel.event_subscriber"/>
</service>

<service id="sculpin_redditify.twig_extension"
class="App\Bundles\RedditifyBundle\TwigRedditifyExtension">
<tag name="twig.extension"/>
</service>
</services>

</container>
9 changes: 9 additions & 0 deletions app/src/Bundles/RedditifyBundle/SculpinRedditifyBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Bundles\RedditifyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class SculpinRedditifyBundle extends Bundle
{
}
42 changes: 42 additions & 0 deletions app/src/Bundles/RedditifyBundle/TwigRedditifyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Bundles\RedditifyBundle;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Twig\Markup;

class TwigRedditifyExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('redditify', [$this, 'renderRedditifyWidget'], ['is_safe' => ['html']]),
];
}

public function renderRedditifyWidget(string $url, array $options = []): Markup
{
$maxDepth = $options['max_depth'] ?? 10;
$showContent = $options['show_content'] ?? false;
$showControls = $options['show_controls'] ?? true;
$cssClass = $options['class'] ?? 'thread-container';

$showContentStr = $showContent ? 'true' : 'false';
$showControlsStr = $showControls ? 'true' : 'false';

$html = sprintf(
'<div class="%s" data-reddit-thread="%s" data-reddit-max-depth="%d" data-reddit-show-content="%s" data-reddit-show-controls="%s"></div>',
htmlspecialchars($cssClass, ENT_QUOTES),
htmlspecialchars($url, ENT_QUOTES),
$maxDepth,
$showContentStr,
$showControlsStr
);

$html .= '<script src="/assets/js/redditify.min.js"></script>';
$html .= '<link rel="stylesheet" href="/assets/css/redditify.css">';

return new Markup($html, 'UTF-8');
}
}
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"bugs": {
"url": "https://github.com/thephpf/thephp.foundation/issues"
},
"homepage": "https://github.com/thephpf/thephp.foundation"
"homepage": "https://github.com/thephpf/thephp.foundation",
"dependencies": {
"redditify": "^0.2.2"
}
}
9 changes: 0 additions & 9 deletions source/_partials/redditify.html

This file was deleted.

4 changes: 1 addition & 3 deletions source/_posts/2025-06-08-php-30.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ Happy 30th birthday, PHP! 🎉

🐘💜

{{ include('redditify.html', {
url: 'https://www.reddit.com/r/PHP/comments/1l7v0df/30_years_of_php_frankenphp_is_now_part_of_the_php/'
}) }}
{{ redditify('https://www.reddit.com/r/PHP/comments/1l7v0df/30_years_of_php_frankenphp_is_now_part_of_the_php/') }}
4 changes: 1 addition & 3 deletions source/_posts/2025-08-05-compile-generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,4 @@ Would a partial-generics approach like that described here be acceptable? Even

**Would you support (and vote in favor of) compile-time-only generics as described here?**

{{ include('redditify.html', {
url: 'https://www.reddit.com/r/PHP/comments/1mhe7qf/compile_time_generics_yay_or_nay/'
}) }}
{{ redditify('https://www.reddit.com/r/PHP/comments/1mhe7qf/compile_time_generics_yay_or_nay/') }}