Skip to content

Commit

Permalink
add template-inline
Browse files Browse the repository at this point in the history
  • Loading branch information
librasteve committed Dec 3, 2024
1 parent b57c0c7 commit d6c4ed9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 38 deletions.
74 changes: 36 additions & 38 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
{
"name": "Cro::WebApp",
"description": "Support for building server-side web applications with Cro, including templates and form handling.",
"version": "0.8.9.1",
"perl": "6.*",
"authors": [
"Jonathan Worthington <[email protected]>"
],
"auth": "zef:cro",
"depends": [
"Cro::HTTP:ver<0.8.9>",
"Log::Timeline",
"OO::Monitors"
],
"build-depends": [],
"test-depends": [],
"provides": {
"Cro::WebApp::Form": "lib/Cro/WebApp/Form.rakumod",
"Cro::WebApp::LogTimelineSchema": "lib/Cro/WebApp/LogTimelineSchema.rakumod",
"Cro::WebApp::Template": "lib/Cro/WebApp/Template.rakumod",
"Cro::WebApp::Template::AST": "lib/Cro/WebApp/Template/AST.rakumod",
"Cro::WebApp::Template::ASTBuilder": "lib/Cro/WebApp/Template/ASTBuilder.rakumod",
"Cro::WebApp::Template::Builtins": "lib/Cro/WebApp/Template/Builtins.rakumod",
"Cro::WebApp::Template::Error": "lib/Cro/WebApp/Template/Error.rakumod",
"Cro::WebApp::Template::Library": "lib/Cro/WebApp/Template/Library.rakumod",
"Cro::WebApp::Template::Location": "lib/Cro/WebApp/Template/Location.rakumod",
"Cro::WebApp::Template::Parser": "lib/Cro/WebApp/Template/Parser.rakumod",
"Cro::WebApp::Template::Repository": "lib/Cro/WebApp/Template/Repository.rakumod"
},
"resources": [
"prelude.crotmp"
],
"license": "Artistic-2.0",
"tags": [
"template",
"web"
],
"source-url": "https://github.com/croservices/cro-webapp.git"
}
"name": "Cro::WebApp",
"description": "Support for building server-side web applications with Cro, including templates and form handling.",
"version": "0.8.9.1",
"authors": [
"Jonathan Worthington <[email protected]>"
],
"auth": "zef:cro",
"depends": [
"Cro::HTTP:ver<0.8.9>",
"Log::Timeline",
"OO::Monitors"
],
"build-depends": [],
"provides": {
"Cro::WebApp::Form": "lib/Cro/WebApp/Form.rakumod",
"Cro::WebApp::LogTimelineSchema": "lib/Cro/WebApp/LogTimelineSchema.rakumod",
"Cro::WebApp::Template": "lib/Cro/WebApp/Template.rakumod",
"Cro::WebApp::Template::AST": "lib/Cro/WebApp/Template/AST.rakumod",
"Cro::WebApp::Template::ASTBuilder": "lib/Cro/WebApp/Template/ASTBuilder.rakumod",
"Cro::WebApp::Template::Builtins": "lib/Cro/WebApp/Template/Builtins.rakumod",
"Cro::WebApp::Template::Error": "lib/Cro/WebApp/Template/Error.rakumod",
"Cro::WebApp::Template::Library": "lib/Cro/WebApp/Template/Library.rakumod",
"Cro::WebApp::Template::Location": "lib/Cro/WebApp/Template/Location.rakumod",
"Cro::WebApp::Template::Parser": "lib/Cro/WebApp/Template/Parser.rakumod",
"Cro::WebApp::Template::Repository": "lib/Cro/WebApp/Template/Repository.rakumod"
},
"resources": [
"prelude.crotmp"
],
"license": "Artistic-2.0",
"tags": [
"template",
"web"
],
"source-url": "https://github.com/croservices/cro-webapp.git"
}
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

0 comments on commit d6c4ed9

Please sign in to comment.