html.pm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package Trog::Renderer::html;
  2. use strict;
  3. use warnings;
  4. no warnings 'experimental';
  5. use feature qw{signatures state};
  6. use parent qw{Trog::Renderer::Base};
  7. use Text::Xslate;
  8. =head1 Trog::Renderer::html
  9. Render HTML. TODO: support inlining everything like you would want when emailing a post.
  10. =cut
  11. sub render (%options) {
  12. state $child_processor = Text::Xslate->new(
  13. # Prevent a recursive descent. If the renderer is hit again, just do nothing
  14. # XXX unfortunately if the post tries to include itself, it will die.
  15. function => {
  16. embed => sub {
  17. my ( $this_id, $style ) = @_;
  18. $style //= 'embed';
  19. # If instead the style is 'content', then we will only show the content w/ no formatting, and no title.
  20. return Text::Xslate::mark_raw(
  21. Trog::Routes::HTML::posts(
  22. { route => "/post/$this_id", style => $style },
  23. sub { },
  24. 1
  25. )
  26. );
  27. },
  28. }
  29. );
  30. state $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. $options{child_processor} = $child_processor;
  37. $options{child_renderer} = $child_renderer;
  38. return Trog::Renderer::Base::render(%options);
  39. }
  40. 1;