html.pm 1.5 KB

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