Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Cro/WebApp/Template.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,10 @@ multi template($template, $initial-topic, :%parts, :$content-type = 'text/html',
multi template($template, :%parts, :$content-type = 'text/html', :$fragment --> Nil) is export {
template($template, Nil, :%parts, :$content-type, :$fragment);
}

#| Used in a Cro::HTTP::Router route handler to render a template inline from
#| a source Str. The initial topic is then passed to the template to render. The
#| content type will default to text/html, but can be set explicitly also.
sub template-inline($source, $initial-topic, :%parts, :$content-type = 'text/html', :$fragment --> Nil) is export {
content $content-type, parse-template($source).render($initial-topic, :%parts, :$fragment);
}
2 changes: 2 additions & 0 deletions t/template-parse-from-source.rakutest
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use Test;
use Cro::WebApp::Template::Repository;

#| template-inline() is not amenable to direct testing since
#| Can only use 'content' inside of a request handler
my Cro::WebApp::Template::Compiled $parsed;
lives-ok { $parsed = parse-template('<.foo>, <.bar>') },
'Can parse a template from a string';
Expand Down