ExerciseTemplate.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Services\Markup\Templates;
  3. use App\Services\Markup\Format;
  4. use App\Services\Markup\Ir\Call;
  5. use App\Services\Markup\Render\RenderContext;
  6. /**
  7. * 练习题:`{{exercise|id}}`。title 与 id 共用第 1 个位置(v2 如此),通常写成 `title=`。
  8. */
  9. final class ExerciseTemplate extends Template
  10. {
  11. protected string $component = 'exercise';
  12. public function params(): array
  13. {
  14. return ['id' => ParamSpec::at(1), 'title' => ParamSpec::at(1)];
  15. }
  16. /**
  17. * @return array<string, mixed>
  18. */
  19. public function props(Call $call, RenderContext $ctx): array
  20. {
  21. return [
  22. 'id' => (string) $call->param('id'),
  23. 'title' => (string) $call->param('title'),
  24. 'channel' => $call->scope->firstChannel(),
  25. ];
  26. }
  27. public function plain(Call $call, RenderContext $ctx, Format $format): string
  28. {
  29. return $format === Format::Prompt ? '' : (string) $call->param('title');
  30. }
  31. public function html(Call $call, RenderContext $ctx): string
  32. {
  33. return '';
  34. }
  35. }