html.pm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package Trog::Renderer::html;
  2. use 5.040;
  3. use re '/aasx';
  4. use parent qw{Trog::Renderer::Base};
  5. use Text::Xslate;
  6. =head1 Trog::Renderer::html
  7. Render HTML. TODO: support inlining everything like you would want when emailing a post.
  8. =cut
  9. sub render (%options) {
  10. state $child_processor = Text::Xslate->new(
  11. # Prevent a recursive descent. If the renderer is hit again, just do nothing
  12. # XXX unfortunately if the post tries to include itself, it will die.
  13. function => {
  14. embed => sub {
  15. my ( $this_id, $style ) = @_;
  16. $style //= 'embed';
  17. # If instead the style is 'content', then we will only show the content w/ no formatting, and no title.
  18. return Text::Xslate::mark_raw(
  19. Trog::Routes::HTML::posts(
  20. { route => "/post/$this_id", style => $style },
  21. sub { },
  22. 1
  23. )
  24. );
  25. },
  26. }
  27. );
  28. state $child_renderer = sub {
  29. my ( $template_string, $options ) = @_;
  30. # If it fails to render, it must be something else
  31. my $out = eval { $child_processor->render_string( $template_string, $options ) };
  32. return $out ? $out : $template_string;
  33. };
  34. $options{child_processor} = $child_processor;
  35. $options{child_renderer} = $child_renderer;
  36. return Trog::Renderer::Base::render(%options);
  37. }
  38. 1;