PHP code example of ubertech-za / asciidoc-renderer

1. Go to this page and download the library: Download ubertech-za/asciidoc-renderer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ubertech-za / asciidoc-renderer example snippets


use UbertechZa\AsciidocRenderer\Facades\Asciidoc;

$asciidoc = Asciidoc::render('adoc::my-document', [
    'title' => 'My Amazing Project',
    'author' => 'John Doe',
    'date' => '2025-01-01'
]);

// Or render directly to file
Asciidoc::renderToFile('adoc::my-document', $data, '/path/to/output.adoc');

Asciidoc::render('adoc::article', [
    'title' => 'My Article',
    'authors' => ['John Doe', 'Jane Smith'],
    'abstract' => 'This article demonstrates...',
    'summary' => 'Key takeaways from this article.',
    'keywords' => ['laravel', 'asciidoc', 'documentation'],
    'sections' => [
        ['title' => 'Introduction', 'body' => 'Welcome to our article...'],
        ['title' => 'Methodology', 'body' => 'We approached this by...'],
        // Or 

Asciidoc::render('adoc::book', [
    'title' => 'The Complete Guide',
    'authors' => 'Expert Author',
    'doctype' => 'book',
    'toc' => 'left',
    'toclevels' => 3,
    'chapters' => [
        'introduction.adoc',
        'getting-started.adoc',
        'advanced-topics.adoc'
    ]
]);



namespace App\Asciidoc\Components;

use Illuminate\View\Component;

class DataTable extends Component
{
    public function __construct(
        public array $headers,
        public array $rows,
        public ?string $title = null
    ) {}

    public function render()
    {
        return view('adoc::components.data-table');
    }
}

return [
    // Template search paths
    'paths' => [
        resource_path('asciidoc'),
        // Add additional paths as needed
    ],

    // Default output directory for generated files
    'output_path' => storage_path('app/asciidoc'),
];

use UbertechZa\AsciidocRenderer\Contracts\TemplateRenderer;

class MyCustomRenderer implements TemplateRenderer
{
    public function render(string $template, array $data = []): string
    {
        // Your custom rendering logic
    }
}

// Bind in a service provider
$this->app->bind(TemplateRenderer::class, MyCustomRenderer::class);

use UbertechZa\AsciidocRenderer\AsciidocGenerator;
use UbertechZa\AsciidocRenderer\Rendering\BladeRenderer;

$generator = new AsciidocGenerator(
    new BladeRenderer(app('view'))
);

$output = $generator->render('my-template', $data);
$generator->renderToFile('my-template', $data, '/path/to/file.adoc');

[
    // Document metadata
    'doctype' => 'article|book',
    'title' => 'Document Title',
    'subtitle' => 'Optional Subtitle',
    'authors' => ['Author One', 'Author Two'], // or string
    
    // Revision information
    'revnumber' => '1.0',
    'revdate' => '2025-01-01',
    'revremark' => 'Initial release',
    
    // Formatting options
    'toc' => 'auto|left|right|macro',
    'toclevels' => 3,
    'sectnums' => true,
    'icons' => true,
    'source_highlighter' => 'rouge',
    'linenums' => true,
    
    // Paths
    'imagesdir' => 'images',
    'docdir' => base_path('docs'),
]
bash
php artisan vendor:publish --provider="UbertechZa\AsciidocRenderer\Laravel\AsciidocRendererServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="UbertechZa\AsciidocRenderer\Laravel\AsciidocRendererServiceProvider" --tag="asciidoc-views"
blade
{{-- resources/asciidoc/components/supplier.adoc.blade --}}
@props(['name', 'contact' => null, 'website' => null])

[sidebar]
.Supplier: <# $name #>
====
Name:: <# $name #>
@if($contact)
Contact:: <# $contact #>
@endif
@if($website)
Website:: link:<# $website #>[<# parse_url($website, PHP_URL_HOST) ?: $website #>]
@endif
====
blade
{{-- resources/asciidoc/components/data-table.adoc.blade --}}
@if($title)
.<# $title #>
@endif
[%autowidth]
|===
@foreach($headers as $header)
| <# $header #>
@endforeach

@foreach($rows as $row)
@foreach($row as $cell)
| <# $cell #>
@endforeach
@endforeach
|===
bash
composer analyse