|
@@ -6,6 +6,8 @@ use warnings FATAL => 'all';
|
|
|
|
|
|
|
|
use Text::Xslate ();
|
|
use Text::Xslate ();
|
|
|
|
|
|
|
|
|
|
+use Trog::Themes ();
|
|
|
|
|
+
|
|
|
=head1 Trog::Component
|
|
=head1 Trog::Component
|
|
|
|
|
|
|
|
Dispatcher for the UI components living under the Trog::Component namespace.
|
|
Dispatcher for the UI components living under the Trog::Component namespace.
|
|
@@ -17,9 +19,9 @@ string into their data hash:
|
|
|
<: component('EmojiPicker') :>
|
|
<: component('EmojiPicker') :>
|
|
|
<: component('Gallery', { album => $post.id, cols => 3 }) :>
|
|
<: component('Gallery', { album => $post.id, cols => 3 }) :>
|
|
|
|
|
|
|
|
-Deliberately depends on nothing but Text::Xslate. Trog::Renderer::Base uses
|
|
|
|
|
-this module, and components use Trog::Renderer, so anything heavier here would
|
|
|
|
|
-close a compile-time load cycle. Components are loaded lazily, at call time,
|
|
|
|
|
|
|
+Deliberately depends on nothing that loads Trog::Renderer. Trog::Renderer::Base
|
|
|
|
|
+uses this module, and components use Trog::Renderer, so such a dependency here
|
|
|
|
|
+would close a compile-time load cycle. Components are loaded lazily, at call time,
|
|
|
for the same reason.
|
|
for the same reason.
|
|
|
|
|
|
|
|
=head1 Termination Conditions
|
|
=head1 Termination Conditions
|
|
@@ -135,6 +137,11 @@ sub component ( $name, $args = {} ) {
|
|
|
Render a component template and hand back the body, for the many components
|
|
Render a component template and hand back the body, for the many components
|
|
|
whose whole job is exactly that.
|
|
whose whole job is exactly that.
|
|
|
|
|
|
|
|
|
|
+The template gets theme_dir as well as $data, unless $data gives it a value: the
|
|
|
|
|
+active theme's directory as a path under the site root, such as
|
|
|
|
|
+C<themes/mytheme>, for building asset links. It is empty when there is no
|
|
|
|
|
+theme.
|
|
|
|
|
+
|
|
|
Dies naming the template if the render fails, rather than answering with the
|
|
Dies naming the template if the render fails, rather than answering with the
|
|
|
PSGI triplet Trog::Renderer::render() produces on failure.
|
|
PSGI triplet Trog::Renderer::render() produces on failure.
|
|
|
|
|
|
|
@@ -147,11 +154,15 @@ sub render_template ( $template, $data = {} ) {
|
|
|
# would close the cycle. By the time anyone calls this it is already loaded.
|
|
# would close the cycle. By the time anyone calls this it is already loaded.
|
|
|
require Trog::Renderer;
|
|
require Trog::Renderer;
|
|
|
|
|
|
|
|
|
|
+ # td() is rooted at /www, which is not in the URL space.
|
|
|
|
|
+ my %data = %$data;
|
|
|
|
|
+ $data{theme_dir} //= Trog::Themes::td() =~ s{\A/www/}{}r;
|
|
|
|
|
+
|
|
|
my $out = Trog::Renderer->render(
|
|
my $out = Trog::Renderer->render(
|
|
|
contenttype => 'text/html',
|
|
contenttype => 'text/html',
|
|
|
component => 1,
|
|
component => 1,
|
|
|
template => $template,
|
|
template => $template,
|
|
|
- data => $data,
|
|
|
|
|
|
|
+ data => \%data,
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
die "Could not render component template '$template'\n" if ref $out;
|
|
die "Could not render component template '$template'\n" if ref $out;
|