Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add template-inline #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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
Loading