html.pm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. $options{child_processor} = $child_processor;
  30. $options{child_renderer} = sub {
  31. my ( $template_string, $options ) = @_;
  32. # If it fails to render, it must be something else
  33. my $out = eval { $child_processor->render_string( $template_string, $options ) };
  34. return $out ? $out : $template_string;
  35. };
  36. return Trog::Renderer::Base::render(%options);
  37. }
  38. 1;