s9e/repdoc
REPdoc is a CLI tool that brings Read-Eval-Print to documentation. It supports Markdown with paired fenced code blocks: a php block to run, immediately followed by an output block (any language) showing the expected printed result.
Dependency Management:
# .github/workflows/doc-validation.yml
name: Validate Documentation Examples
on: [push, pull_request]
jobs:
validate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-php@v3
with:
php-version: '8.2'
- run: composer install
- run: vendor/bin/repdoc docs/api/*.md
Security Patches:
Repdoc wrapper to restrict eval (e.g., using box/spout or Docker):
// app/Services/SandboxedRepdoc.php
use Box\Spout\Common\Entity\IO\WriteOnly\ShouldOverwriteExistingFile;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use S9e\Repdoc\Repdoc;
class SandboxedRepdoc {
public function evaluate(string $file): string {
$sandbox = new SpoutSandbox(); // Hypothetical sandbox
return $sandbox->run(function () use ($file) {
$repdoc = new Repdoc();
return $repdoc->processFile($file);
});
}
}
Developer Experience:
php artisan repdoc:eval docs/api.md
// app/Console/Commands/EvalDocs.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use S9e\Repdoc\Repdoc;
class EvalDocs extends Command {
protected $signature = 'repdoc:eval {file}';
public function handle() {
$repdoc = new Repdoc();
$output = $repdoc->processFile($this->argument('file'));
$this->info($output);
}
}
Troubleshooting Playbook:
| Issue | Solution |
|---|---|
| PHP errors in docs | Add try-catch in the Repdoc wrapper to log errors gracefully. |
| Missing Laravel classes | Mock dependencies in eval (e.g., use App\Models\User; in docs). |
| Slow performance | Cache evaluated outputs (e.g., Redis) or limit REPdoc to critical docs. |
| Permission denied (CLI) | Ensure docs are readable by the PHP process (e.g., chmod 644). |
Performance:
parallel:for or Symfony’s Process to evaluate docs concurrently.Failure Modes:
| Scenario | Impact | Mitigation |
|---|---|---|
| Malicious doc snippet | RCE in eval environment | Sandbox all evaluations (Docker/Spout). |
| Doc syntax errors | Broken builds | Pre-validate docs with php -l. |
| CI timeout | Flaky pipelines | Cache outputs or use smaller batches. |
| PHP version mismatch | Repdoc failures | Pin PHP version in CI (e.g., 8.2). |
Training:
/docs/repdoc-guide.md with:
Adoption Metrics:
Phased Rollout:
How can I help you explore Laravel packages today?