Mojolicious-Plugin-TemplateToolkit-0.006000755001750001750 014062303162 20364 5ustar00grinnzgrinnz000000000000README100644001750001750 742614062303162 21336 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006NAME Mojolicious::Plugin::TemplateToolkit - Template Toolkit renderer plugin for Mojolicious SYNOPSIS # Mojolicious $app->plugin('TemplateToolkit'); $app->plugin(TemplateToolkit => {name => 'foo'}); $app->plugin(TemplateToolkit => {template => {INTERPOLATE => 1}}); # Mojolicious::Lite plugin 'TemplateToolkit'; plugin TemplateToolkit => {name => 'foo'}; plugin TemplateToolkit => {template => {INTERPOLATE => 1}}); # Set as default handler $app->renderer->default_handler('tt2'); # Render without setting as default handler $c->render(template => 'bar', handler => 'tt2'); DESCRIPTION Mojolicious::Plugin::TemplateToolkit is a renderer for tt2 or Template Toolkit templates. See Template and Template::Manual for details on the Template Toolkit format, and Mojolicious::Guides::Rendering for general information on rendering in Mojolicious. Along with template files, inline and data section templates can be rendered in the standard Mojolicious fashion. Template files and data sections will be retrieved using Mojolicious::Renderer via Template::Provider::Mojo for both direct rendering and directives such as INCLUDE. This means that instead of specifying INCLUDE_PATH, you should set "paths" in Mojolicious::Renderer to the appropriate paths. $app->renderer->paths(['/path/to/templates']); push @{$app->renderer->paths}, '/path/to/more/templates'; Mojolicious stash values will be exposed directly as variables in the templates, and the current controller object will be available as c or self, similar to Mojolicious::Plugin::EPRenderer. Helper methods can be called on the controller object as normal, as well as on a proxy object available as h. The proxy object was previously needed for efficiency as the controller object used AUTOLOAD to call helper methods, but since Mojolicious 8.04 the controller object uses a more efficient mechanism and the proxy object is no longer needed. See Mojolicious::Plugin::DefaultHelpers and Mojolicious::Plugin::TagHelpers for a list of all built-in helper methods. Accessing helper methods directly as variables, rather than via the controller or proxy object, is deprecated and may be removed in a future release. $c->stash(description => 'template engine'); $c->stash(engines => [qw(Template::Toolkit Text::Template)]); [% FOREACH engine IN engines %] [% engine %] is a [% description %]. [% END %] [% c.link_to('Template Toolkit', 'http://www.template-toolkit.org') %] [% c.param('foo') %] OPTIONS Mojolicious::Plugin::TemplateToolkit supports the following options. name # Mojolicious::Lite plugin TemplateToolkit => {name => 'foo'}; Handler name, defaults to tt2. template # Mojolicious::Lite plugin TemplateToolkit => {template => {INTERPOLATE => 1}}; Configuration values passed to Template object used to render templates. Note that Template::Provider::Mojo will use "paths" in Mojolicious::Renderer to find templates, not INCLUDE_PATH specified here. METHODS Mojolicious::Plugin::TemplateToolkit inherits all methods from Mojolicious::Plugin and implements the following new ones. register $plugin->register(Mojolicious->new); $plugin->register(Mojolicious->new, {name => 'foo'}); Register renderer in Mojolicious application. BUGS Report any issues on the public bugtracker. AUTHOR Dan Book COPYRIGHT AND LICENSE This software is Copyright (c) 2015 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) SEE ALSO Mojolicious::Renderer, Template, Template::Provider::Mojo Changes100644001750001750 130014062303162 21732 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.0060.006 2021-06-16 01:04:48 EDT - Update IRC metadata to libera.chat 0.005 2018-10-18 19:16:25 EDT - Added a proxy object for calling helpers more efficiently as 'h' 0.004 2018-10-16 19:32:20 EDT - Deprecated calling helpers directly as template variables in favor of calling them via the 'c' controller variable, to disambiguate helpers from stash variables 0.003 2018-06-14 17:45:49 EDT - Removed randomly failing OUTLINE_TAG test - Fix rendering and including empty data templates 0.002 2015-10-20 20:03:54 EDT - Added Template::Provider::Mojo to resolve templates using Mojolicious::Renderer directly 0.001 2015-10-20 01:43:29 EDT - First release LICENSE100644001750001750 2151514062303162 21476 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006This software is Copyright (c) 2015 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. INSTALL100644001750001750 507014062303162 21500 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006This is the Perl distribution Mojolicious-Plugin-TemplateToolkit. Installing Mojolicious-Plugin-TemplateToolkit is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm Mojolicious::Plugin::TemplateToolkit If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Mojolicious::Plugin::TemplateToolkit ## Manual installation As a last resort, you can manually install it. If you have not already downloaded the release tarball, you can find the download link on the module's MetaCPAN page: https://metacpan.org/pod/Mojolicious::Plugin::TemplateToolkit Untar the tarball, install configure prerequisites (see below), then build it: % perl Build.PL % ./Build && ./Build test Then install it: % ./Build install Or the more portable variation: % perl Build.PL % perl Build % perl Build test % perl Build install If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Build.PL. Look for prerequisites in the following phases: * to run ./Build, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation Mojolicious-Plugin-TemplateToolkit documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc Mojolicious::Plugin::TemplateToolkit For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html dist.ini100644001750001750 42714062303162 22074 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006name = Mojolicious-Plugin-TemplateToolkit author = Dan Book license = Artistic_2_0 copyright_holder = Dan Book copyright_year = 2015 [@Author::DBOOK] :version = v1.0.3 installer = ModuleBuildTiny::Fallback pod_tests = 1 irc = ircs://irc.libera.chat/#mojo META.yml100644001750001750 261714062303162 21724 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006--- abstract: 'Template Toolkit renderer plugin for Mojolicious' author: - 'Dan Book ' build_requires: File::Spec: '0' Module::Metadata: '0' Test::More: '0.88' configure_requires: Module::Build::Tiny: '0.034' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Mojolicious-Plugin-TemplateToolkit no_index: directory: - eg - examples - inc - share - t - xt provides: Mojolicious::Plugin::TemplateToolkit: file: lib/Mojolicious/Plugin/TemplateToolkit.pm version: '0.006' Template::Provider::Mojo: file: lib/Template/Provider/Mojo.pm version: '0.006' requires: Carp: '0' Class::Method::Modifiers: '0' Mojolicious: '6.51' Scalar::Util: '0' Template: '2.26' Template::Provider: '2.94' parent: '0' perl: '5.010001' resources: IRC: ircs://irc.libera.chat/#mojo bugtracker: https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit/issues homepage: https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit repository: https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit.git version: '0.006' x_contributors: - 'Dan Book ' x_generated_by_perl: v5.34.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: Artistic-2.0 MANIFEST100644001750001750 121614062303162 21576 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.017. Build.PL CONTRIBUTING.md Changes INSTALL LICENSE MANIFEST META.json META.yml README dist.ini lib/Mojolicious/Plugin/TemplateToolkit.pm lib/Template/Provider/Mojo.pm prereqs.yml t/00-report-prereqs.dd t/00-report-prereqs.t t/lite_app.t t/provider.t t/renderer.t t/templates/file_include_data.html.tt2 t/templates/file_include_empty.html.tt2 t/templates/file_include_file.html.tt2 t/templates/file_insert_data.html.tt2 t/templates/file_insert_empty.html.tt2 t/templates/file_insert_file.html.tt2 t/templates/tmpl_file.html.tt2 xt/author/pod-coverage.t xt/author/pod-syntax.t Build.PL100644001750001750 706114062303162 21745 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006# This Build.PL for Mojolicious-Plugin-TemplateToolkit was generated by # Dist::Zilla::Plugin::ModuleBuildTiny::Fallback 0.025 use strict; use warnings; my %configure_requires = ( 'Module::Build::Tiny' => '0.034', ); my %errors = map { eval "require $_; $_->VERSION($configure_requires{$_}); 1"; $_ => $@, } keys %configure_requires; if (!grep { $_ } values %errors) { # This section for Mojolicious-Plugin-TemplateToolkit was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.015. use strict; use warnings; use 5.010001; # use Module::Build::Tiny 0.034; Module::Build::Tiny::Build_PL(); } else { if (not $ENV{PERL_MB_FALLBACK_SILENCE_WARNING}) { warn <<'EOW' *** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *** If you're seeing this warning, your toolchain is really, really old* and you'll almost certainly have problems installing CPAN modules from this century. But never fear, dear user, for we have the technology to fix this! If you're using CPAN.pm to install things, then you can upgrade it using: cpan CPAN If you're using CPANPLUS to install things, then you can upgrade it using: cpanp CPANPLUS If you're using cpanminus, you shouldn't be seeing this message in the first place, so please file an issue on github. This public service announcement was brought to you by the Perl Toolchain Gang, the irc.perl.org #toolchain IRC channel, and the number 42. ---- * Alternatively, you are running this file manually, in which case you need to learn to first fulfill all configure requires prerequisites listed in META.yml or META.json -- or use a cpan client to install this distribution. You can also silence this warning for future installations by setting the PERL_MB_FALLBACK_SILENCE_WARNING environment variable, but please don't do that until you fix your toolchain as described above. Errors from configure prereqs: EOW . do { require Data::Dumper; Data::Dumper->new([ \%errors ])->Indent(2)->Terse(1)->Sortkeys(1)->Dump; }; sleep 10 if -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)); } # This section was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.017. use strict; use warnings; require Module::Build; Module::Build->VERSION(0.28); my %module_build_args = ( "configure_requires" => { "Module::Build::Tiny" => "0.034" }, "dist_abstract" => "Template Toolkit renderer plugin for Mojolicious", "dist_author" => [ "Dan Book " ], "dist_name" => "Mojolicious-Plugin-TemplateToolkit", "dist_version" => "0.006", "license" => "artistic_2", "module_name" => "Mojolicious::Plugin::TemplateToolkit", "recursive_test_files" => 1, "requires" => { "Carp" => 0, "Class::Method::Modifiers" => 0, "Mojolicious" => "6.51", "Scalar::Util" => 0, "Template" => "2.26", "Template::Provider" => "2.94", "parent" => 0, "perl" => "5.010001" }, "test_requires" => { "File::Spec" => 0, "Module::Metadata" => 0, "Test::More" => "0.88" } ); my %fallback_build_requires = ( "File::Spec" => 0, "Module::Metadata" => 0, "Test::More" => "0.88" ); unless ( eval { Module::Build->VERSION(0.4004) } ) { delete $module_build_args{test_requires}; $module_build_args{build_requires} = \%fallback_build_requires; } my $build = Module::Build->new(%module_build_args); $build->create_build_script; } META.json100644001750001750 477614062303162 22104 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006{ "abstract" : "Template Toolkit renderer plugin for Mojolicious", "author" : [ "Dan Book " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Mojolicious-Plugin-TemplateToolkit", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.034" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "Class::Method::Modifiers" : "0", "Mojolicious" : "6.51", "Scalar::Util" : "0", "Template" : "2.26", "Template::Provider" : "2.94", "parent" : "0", "perl" : "5.010001" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "File::Spec" : "0", "Module::Metadata" : "0", "Test::More" : "0.88" } } }, "provides" : { "Mojolicious::Plugin::TemplateToolkit" : { "file" : "lib/Mojolicious/Plugin/TemplateToolkit.pm", "version" : "0.006" }, "Template::Provider::Mojo" : { "file" : "lib/Template/Provider/Mojo.pm", "version" : "0.006" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit/issues" }, "homepage" : "https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit", "repository" : { "type" : "git", "url" : "https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit.git", "web" : "https://github.com/Grinnz/Mojolicious-Plugin-TemplateToolkit" }, "x_IRC" : "ircs://irc.libera.chat/#mojo" }, "version" : "0.006", "x_contributors" : [ "Dan Book " ], "x_generated_by_perl" : "v5.34.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.26", "x_spdx_expression" : "Artistic-2.0" } prereqs.yml100644001750001750 35514062303162 22634 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006runtime: requires: perl: '5.010001' Carp: 0 Class::Method::Modifiers: 0 Mojolicious: '6.51' parent: 0 Scalar::Util: 0 Template: '2.26' Template::Provider: '2.94' test: requires: Test::More: '0.88' t000755001750001750 014062303162 20550 5ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006lite_app.t100644001750001750 175614062303162 22703 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/tuse Mojo::Base -strict; BEGIN { $ENV{MOJO_MODE} = 'development'; $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll'; } use Test::More; use Mojolicious::Lite; use Mojo::Util 'encode'; use Test::Mojo; plugin 'TemplateToolkit'; get '/inline/:foo' => { handler => 'tt2', inline => '[% foo %] ☃' }; get '/data/:foo' => { handler => 'tt2' } => 'data_section'; get '/tmpl/:foo' => { handler => 'tt2' } => 'tmpl_file'; get '/empty' => { handler => 'tt2' }; my $t = Test::Mojo->new; $t->get_ok('/inline/bar')->content_is('bar ☃'); is $t->tx->res->body, encode('UTF-8', 'bar ☃'), 'right encoded content'; $t->get_ok('/data/bar')->content_is("bar ☃\n"); is $t->tx->res->body, encode('UTF-8', "bar ☃\n"), 'right encoded content'; $t->get_ok('/tmpl/bar')->content_is("bar ☃\n"); is $t->tx->res->body, encode('UTF-8', "bar ☃\n"), 'right encoded content'; $t->get_ok('/empty')->status_is(200)->content_is(''); done_testing; __DATA__ @@ empty.html.tt2 @@ data_section.html.tt2 [% foo %] ☃ __END__ provider.t100644001750001750 1340314062303162 22750 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/tuse Mojo::Base -strict; use Test::More; use Mojo::Util 'encode'; use Template; use Template::Context; use Template::Provider::Mojo; use Mojolicious::Lite; my $renderer = app->renderer; my $provider = Template::Provider::Mojo->new({MOJO_RENDERER => $renderer}); my $context = Template::Context->new({LOAD_TEMPLATES => [$provider]}); my $tt = Template->new({CONTEXT => $context}); # Basic templates my $output; ok($tt->process(\'[% foo %] ☃', { foo => 'bar' }, \$output), 'processed inline template') or diag $tt->error; is $output, 'bar ☃', 'right template output'; undef $output; ok($tt->process('data_section.html.tt2', { foo => 'bar' }, \$output), 'processed data template') or diag $tt->error; is $output, "bar ☃\n", 'right template output'; undef $output; ok($tt->process('data_empty.html.tt2', { foo => 'bar' }, \$output), 'processed empty data template') or diag $tt->error; is $output, '', 'right template output'; undef $output; ok($tt->process('tmpl_file.html.tt2', { foo => 'bar' }, \$output), 'processed file template') or diag $tt->error; is $output, "bar ☃\n", 'right template output'; # Includes from inline undef $output; ok($tt->process(\'[% INCLUDE data_section.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with included data template') or diag $tt->error; is $output, "bar ☃\nbaz", 'right template output'; undef $output; ok($tt->process(\'[% INCLUDE data_empty.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with included empty data template') or diag $tt->error; is $output, "baz", 'right template output'; undef $output; ok($tt->process(\'[% INCLUDE tmpl_file.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with included file template') or diag $tt->error; is $output, "bar ☃\nbaz", 'right template output'; # Includes from data section undef $output; ok($tt->process('data_include_data.html.tt2', { foo => 'bar' }, \$output), 'processed data template with included data template') or diag $tt->error; is $output, "bar ☃\nbaz\n", 'right template output'; undef $output; ok($tt->process('data_include_empty.html.tt2', { foo => 'bar' }, \$output), 'processed data template with included empty data template') or diag $tt->error; is $output, "baz\n", 'right template output'; undef $output; ok($tt->process('data_include_file.html.tt2', { foo => 'bar' }, \$output), 'processed data template with included file template') or diag $tt->error; is $output, "bar ☃\nbaz\n", 'right template output'; # Includes from file template undef $output; ok($tt->process('file_include_data.html.tt2', { foo => 'bar' }, \$output), 'processed file template with included data template') or diag $tt->error; is $output, "bar ☃\nbaz\n", 'right template output'; undef $output; ok($tt->process('file_include_empty.html.tt2', { foo => 'bar' }, \$output), 'processed file template with included empty data template') or diag $tt->error; is $output, "baz\n", 'right template output'; undef $output; ok($tt->process('file_include_file.html.tt2', { foo => 'bar' }, \$output), 'processed file template with included file template') or diag $tt->error; is $output, "bar ☃\nbaz\n", 'right template output'; my $inserted = encode $renderer->encoding, "[% foo %] ☃\n"; # Inserts from inline undef $output; ok($tt->process(\'[% INSERT data_section.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with inserted data template') or diag $tt->error; is $output, "${inserted}baz", 'right template output'; undef $output; ok($tt->process(\'[% INSERT data_empty.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with inserted empty data template') or diag $tt->error; is $output, "baz", 'right template output'; undef $output; ok($tt->process(\'[% INSERT tmpl_file.html.tt2 %]baz', { foo => 'bar' }, \$output), 'processed inline template with inserted file template') or diag $tt->error; is $output, "${inserted}baz", 'right template output'; # Inserts from data section undef $output; ok($tt->process('data_insert_data.html.tt2', { foo => 'bar' }, \$output), 'processed data template with inserted data template') or diag $tt->error; is $output, "${inserted}baz\n", 'right template output'; undef $output; ok($tt->process('data_insert_empty.html.tt2', { foo => 'bar' }, \$output), 'processed data template with inserted empty data template') or diag $tt->error; is $output, "baz\n", 'right template output'; undef $output; ok($tt->process('data_insert_file.html.tt2', { foo => 'bar' }, \$output), 'processed data template with inserted file template') or diag $tt->error; is $output, "${inserted}baz\n", 'right template output'; # Inserts from file template undef $output; ok($tt->process('file_insert_data.html.tt2', { foo => 'bar' }, \$output), 'processed file template with inserted data template') or diag $tt->error; is $output, "${inserted}baz\n", 'right template output'; undef $output; ok($tt->process('file_insert_empty.html.tt2', { foo => 'bar' }, \$output), 'processed file template with inserted empty data template') or diag $tt->error; is $output, "baz\n", 'right template output'; undef $output; ok($tt->process('file_insert_file.html.tt2', { foo => 'bar' }, \$output), 'processed file template with inserted file template') or diag $tt->error; is $output, "${inserted}baz\n", 'right template output'; done_testing; __DATA__ @@ data_section.html.tt2 [% foo %] ☃ @@ data_empty.html.tt2 @@ data_include_data.html.tt2 [% INCLUDE data_section.html.tt2 %]baz @@ data_include_empty.html.tt2 [% INCLUDE data_empty.html.tt2 %]baz @@ data_include_file.html.tt2 [% INCLUDE tmpl_file.html.tt2 %]baz @@ data_insert_data.html.tt2 [% INSERT data_section.html.tt2 %]baz @@ data_insert_empty.html.tt2 [% INSERT data_empty.html.tt2 %]baz @@ data_insert_file.html.tt2 [% INSERT tmpl_file.html.tt2 %]baz __END__ renderer.t100644001750001750 310314062303162 22700 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/tuse Mojo::Base -strict; use Test::More; use Mojolicious; # Partial rendering my $app = Mojolicious->new(secrets => ['works']); $app->plugin('TemplateToolkit'); my $c = $app->build_controller; $c->app->log->level('fatal'); is $c->render_to_string(inline => 'works', handler => 'tt2'), 'works', 'renderer is working'; $app->renderer->default_handler('tt2'); # Stash variable is $c->render_to_string(inline => '[% foo %]', foo => 'bar'), 'bar', 'stash variable is passed'; # Helper is $c->render_to_string(inline => '[% h.stash("foo") %]', foo => 'bar'), 'bar', 'helper works'; like $c->render_to_string(inline => "[% c.link_to('some link', 'http://www.example.com') %]"), qr(href.+http://www\.example\.com.+some link), 'helper works'; # Controller is $c->render_to_string(inline => '[% c.stash.foo %]', foo => 'bar'), 'bar', 'controller is accessible'; # Encoding is $c->render_to_string(inline => '☃'), '☃', 'encoding works'; is $c->render_to_string(inline => '[% foo %]', foo => '☃'), '☃', 'encoding works'; # Set configuration $app = Mojolicious->new(secrets => ['works']); my $tt_config = { INTERPOLATE => 1, START_TAG => '<%', END_TAG => '%>' }; $app->plugin(TemplateToolkit => { name => 'foo', template => $tt_config }); $c = $app->build_controller; $c->app->log->level('fatal'); is $c->render_to_string(inline => 'foo', handler => 'foo'), 'foo', 'name works'; is $c->render_to_string(inline => '$foo', handler => 'foo', foo => 'bar'), 'bar', 'interpolate works'; is $c->render_to_string(inline => '<% foo %>', handler => 'foo', foo => 'bar'), 'bar', 'tags work'; done_testing(); CONTRIBUTING.md100644001750001750 1055514062303162 22724 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006# HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla). This means that many of the usual files you might expect are not in the repository, but are generated at release time. Some generated files are kept in the repository as a convenience (e.g. Build.PL/Makefile.PL and META.json). Generally, **you do not need Dist::Zilla to contribute patches**. You may need Dist::Zilla to create a tarball. See below for guidance. ## Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use [cpanm](https://metacpan.org/pod/cpanm) to satisfy dependencies like this: $ cpanm --installdeps --with-develop . You can also run this command (or any other cpanm command) without installing App::cpanminus first, using the fatpacked `cpanm` script via curl or wget: $ curl -L https://cpanmin.us | perl - --installdeps --with-develop . $ wget -qO - https://cpanmin.us | perl - --installdeps --with-develop . Otherwise, look for either a `cpanfile`, `prereqs.json`/`prereqs.yml`, or `META.json` file for a list of dependencies to satisfy. ## Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ## Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. ## Installing and using Dist::Zilla [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ dzil authordeps --missing | cpanm You can use Dist::Zilla to install the distribution's dependencies if you haven't already installed them with cpanm: $ dzil listdeps --missing --develop | cpanm You can instead combine these two steps into one command by installing Dist::Zilla::App::Command::installdeps then running: $ dzil installdeps Once everything is installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil regenerate You can learn more about Dist::Zilla at http://dzil.org/ ## Other notes This distribution maintains the generated `META.json` and either `Makefile.PL` or `Build.PL` in the repository. This allows two things: [Travis CI](https://travis-ci.org/) can build and test the distribution without requiring Dist::Zilla, and the distribution can be installed directly from Github or a local git repository using `cpanm` for testing (again, not requiring Dist::Zilla). $ cpanm git://github.com/Author/Distribution-Name.git $ cd Distribution-Name; cpanm . Contributions are preferred in the form of a Github pull request. See [Using pull requests](https://help.github.com/articles/using-pull-requests/) for further information. You can use the Github issue tracker to report issues without an accompanying patch. # CREDITS This file was adapted from an initial `CONTRIBUTING.mkdn` file from David Golden under the terms of the [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/), with inspiration from the contributing documents from [Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING](https://metacpan.org/pod/Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING) and [Dist::Zilla::PluginBundle::Author::ETHER](https://metacpan.org/pod/Dist::Zilla::PluginBundle::Author::ETHER). 00-report-prereqs.t100644001750001750 1347614062303162 24337 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.028 use Test::More tests => 1; use Module::Metadata; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = Module::Metadata->new_from_file( File::Spec->catfile($prefix, $file) )->version; $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: author000755001750001750 014062303162 22242 5ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/xtpod-syntax.t100644001750001750 25214062303162 24654 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644001750001750 307314062303162 24433 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/tdo { my $x = { 'configure' => { 'requires' => { 'Module::Build::Tiny' => '0.034' } }, 'develop' => { 'requires' => { 'Pod::Coverage::TrustPod' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Class::Method::Modifiers' => '0', 'Mojolicious' => '6.51', 'Scalar::Util' => '0', 'Template' => '2.26', 'Template::Provider' => '2.94', 'parent' => '0', 'perl' => '5.010001' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'File::Spec' => '0', 'Module::Metadata' => '0', 'Test::More' => '0.88' } } }; $x; }pod-coverage.t100644001750001750 33414062303162 25122 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Provider000755001750001750 014062303162 24420 5ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/lib/TemplateMojo.pm100644001750001750 1024214062303162 26041 0ustar00grinnzgrinnz000000000000Mojolicious-Plugin-TemplateToolkit-0.006/lib/Template/Providerpackage Template::Provider::Mojo; use strict; use warnings; use parent 'Template::Provider'; use Class::Method::Modifiers (); use Mojo::Util; use Mojolicious::Renderer; use Scalar::Util; use Template::Constants; our $VERSION = '0.006'; Class::Method::Modifiers::after '_init' => sub { my ($self, $params) = @_; Scalar::Util::weaken($self->{MOJO_RENDERER} = delete $params->{MOJO_RENDERER}); $self->{ENCODING} //= $self->_mojo_renderer->encoding; }; sub fetch { my ($self, $name) = @_; my ($data, $error); if (ref $name) { # $name can be a reference to a scalar, GLOB or file handle ($data, $error) = $self->_load($name); ($data, $error) = $self->_compile($data) unless $error; $data = $data->{data} unless $error; } else { # Use renderer to find template my $renderer = $self->_mojo_renderer; my $options = _template_options($renderer, $name); # Try template if (defined(my $path = $renderer->template_path($options))) { ($data, $error) = $self->_fetch($path); } # Try DATA section elsif (defined(my $d = $renderer->get_data_template($options))) { ($data, $error) = $self->_load(\$d); ($data, $error) = $self->_compile($data) unless $error; $data = $data->{data} unless $error; } # No template else { ($data, $error) = (undef, Template::Constants::STATUS_DECLINED) } } return ($data, $error); } sub load { my ($self, $name) = @_; my ($data, $error); # Use renderer to find template my $renderer = $self->_mojo_renderer; my $options = _template_options($renderer, $name); # Try template if (defined(my $path = $renderer->template_path($options))) { ($data, $error) = $self->_template_content($path); } # Try DATA section elsif (defined(my $d = $renderer->get_data_template($options))) { # Content is expected to be encoded $d = Mojo::Util::encode $self->{ENCODING}, $d if $self->{UNICODE} and $self->{ENCODING}; ($data, $error) = ($d, undef); } # No template else { return (undef, Template::Constants::STATUS_DECLINED) } if ($error) { return $self->{TOLERANT} ? (undef, Template::Constants::STATUS_DECLINED) : ($error, Template::Constants::STATUS_ERROR); } else { return ($data, Template::Constants::STATUS_OK); } } sub _mojo_renderer { shift->{MOJO_RENDERER} //= Mojolicious::Renderer->new } # Split template name back into options sub _template_options { my ($renderer, $name) = @_; my $options = {}; if ($name =~ m/^(.+)\.(.+)\.(.+)\z/) { $options->{template} = $1; $options->{format} = $2; $options->{handler} = $3; } elsif ($name =~ m/^(.+)\.(.+)\z/) { $options->{template} = $1; $options->{format} = $2; } else { $options->{template} = $name; $options->{format} = $renderer->default_format; $options->{handler} = $renderer->default_handler; } return $options; } 1; =head1 NAME Template::Provider::Mojo - Use Mojolicious to provide templates =head1 SYNOPSIS my $app = Mojolicious->new; $provider = Template::Provider::Mojo->new({MOJO_RENDERER => $app->renderer}); ($template, $error) = $provider->fetch($name); =head1 DESCRIPTION L is a L subclass that uses a L instance to resolve template names. This means that L will be searched for file-based templates, and L will be searched for DATA templates. The C configuration setting will be initialized to L if unset. =head1 METHODS L inherits all methods from L and implements the following new ones. =head2 fetch Returns a compiled template for the name specified. See L for usage details. =head2 load Loads a template without parsing or compiling it. This is used by the L directive. =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2015 by Dan Book. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) =head1 SEE ALSO L