ParaTemplate.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Services\Markup\Templates;
  3. use App\Services\Markup\Ir\Call;
  4. use App\Services\Markup\Render\RenderContext;
  5. /**
  6. * 嵌入经文段落:`{{para|id=book-para|title|style}}`。
  7. */
  8. final class ParaTemplate extends Template
  9. {
  10. protected string $component = 'para';
  11. public function params(): array
  12. {
  13. return ['id' => ParamSpec::at(1), 'title' => ParamSpec::at(2), 'style' => ParamSpec::at(3)];
  14. }
  15. /**
  16. * @return array<string, mixed>
  17. */
  18. public function props(Call $call, RenderContext $ctx): array
  19. {
  20. $props = [
  21. 'id' => (string) $call->param('id'),
  22. 'title' => (string) $call->param('title'),
  23. 'style' => (string) $call->param('style'),
  24. ];
  25. if ($call->scope->channels !== []) {
  26. $props['channel'] = implode('_', $call->scope->channels);
  27. }
  28. return $props;
  29. }
  30. public function references(Call $call): array
  31. {
  32. return self::paragraphRef((string) $call->param('id'));
  33. }
  34. public function text(Call $call, RenderContext $ctx): string
  35. {
  36. return (string) $call->param('title');
  37. }
  38. }