starxen/lasertag

LaserTag - 一个用于创建和渲染自定义模板的 Symfony 扩展。

安装: 113

依赖项: 0

建议者: 0

安全: 0

星标: 0

分支: 0

类型:symfony-bundle

v1.0.2 2024-08-09 22:11 UTC

This package is auto-updated.

Last update: 2024-09-09 22:29:49 UTC


README

LaserTag 是一个 Symfony 扩展,允许您根据自定的 BBCode-style 标签编写和渲染自己的 HTML 模板。通过使用 LaserTag,我们获得了内容的可重用性和从伴随的 HTML 代码中独立出来的特性。

示例

渲染前

[h2 class="extra-class-name"]Check my new YouTube video![/h2]
[youtube url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"/]

渲染后

<h2 class="app-color-darken fw-bolder mt-3 mb-3 extra-class-name">Check my new YouTube video!</h2>
<div class="app-border-left-bold embed-responsive embed-responsive-16by9 col col-lg-6 mx-auto mt-3 mb-3">
    <iframe class="embed-responsive-item" src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" title="" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

LaserTag 插件

// src/LaserTag/MyPlugin.php
<?php

declare(strict_types=1);

namespace App\LaserTag;

use StarXen\LaserTag\LaserTag\AbstractPlugin;
use StarXen\LaserTag\LaserTag\LaserTag;
use StarXen\LaserTag\LaserTag\TagAttribute;

class MyPlugin extends AbstractPlugin
{
    public function getTags(): array
    {
        return [
            new LaserTag('h2', [$this, 'h2'], [new TagAttribute('class')]),
            new LaserTag('youtube', [$this, 'youtube'], [new TagAttribute('url', true), new TagAttribute('title')])
        ];
    }

    public function h2(string $content): string
    {
        return <<<HTML
<h2 class="app-color-darken fw-bolder mt-3 mb-3 {$this->getAttribute('class')}">$content</h2>
HTML;
    }

    public function youtube(): string
    {
        return <<<HTML
<div class="app-border-left-bold embed-responsive embed-responsive-16by9 col col-lg-6 mx-auto mt-3 mb-3">
    <iframe class="embed-responsive-item" src="{$this->getAttribute('url')}" title="{$this->getAttribute('title')}" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
HTML;
    }
    
}

安装

composer require starxen/lasertag

用法

EXAMPLE.md