Extensions

Code Scrawl Extensions allow library developers to create their own documentation generators, shareable templates and MDVerbs, and hook into various Code Scrawl events.

If you're not a library developer, it's easier to use a @\system() call to a bin script, add template directories in your config, or add markdown verbs in your configured bootstrap.

Also see: @see_files(docs/Templates.md; Templates, docs/MarkdownVerbs.md; Markdown Verbs, docs/Configuration.md; Configuration)

Docs

  • Enabling & Configuring Extensions
  • Built-In Extensions
  • Create an Extension
  • Useful Scrawl Methods

Enabling & Configuring Extensions

Option 1:

  1. Configure scrawl.extensions with an array of Fully Qualified Class Names. Example: "scrawl.extensions": ["Tlf\\Scrawl\\Extension\\Notes"] (Each class must implement Tlf\Scrawl\Extension)
  2. See the Extension's documentation to learn how to configure it.

Option 2: Instantiate in your configured bootstrap.php file. (Option 1 is preferred, unless the Extension's documentation suggests otherwise.)

scrawl-bootstrap.php:

<?php
$ext = new \Some\ScrawlExtension($this);
$ext->some_option = true;
$ext->some_path = __DIR__;

// $this is the `Tlf\Scrawl` instance
$this->ScrawlExtensions[] = $ext;

Built-In Extensions

Optional Extensions: (Must be enabled via scrawl.extensions)

  • Tlf\Scrawl\Extension\Notes - Creates Notes.md documentation file listing all @\NOTE lines in scanned directories.

Other Extensions:

  • Tlf\Scrawl\DoNothingExtension - base class for other Extensions to extend from
  • Tlf\Scrawl\Ext\MdVerb\MainVerbs - enables all the built-in Markdown Verbs. It is loaded automatically and cannot be configured.

Note: There are other classes providing features that do not use the Extension interface. This may be changed in the future.

Create an Extension

  1. Create a class that implements \Tlf\Scrawl\Extension OR extends \Tlf\Scrawl\DoNothingExtension for easier setup, and implement any methods you need.
  2. Add features: (Reference $this->scrawl as needed, and use the 'Useful Scrawl Methods' below when working with files.)
    • Implement/Override any methods you need (and code whatever you want)
    • Add template directories (during bootstrap) ($scrawl->add_template_dir($absolute_path))
    • Create Markdown Verbs (during bootstrap) ($scrawl->add_md_verb('verb_name', $callable)

See @see(src/Extension.php, Extension Interface) and @see(src/Ext/DoNothingExtension.php, DoNothingExtension).

Useful Scrawl Methods

@ast(class.Tlf\Scrawl, Scrawl/UsefulScrawlMethods)