ParaTemplate.php 1.3 KB

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