diff --git a/README.pod b/README.pod index c40a100..14efeb2 100644 --- a/README.pod +++ b/README.pod @@ -14,7 +14,6 @@ L example: use Mojolicious::Lite; - # Documentation browser under "/perldoc" plugin 'tt_renderer'; get '/' => sub { @@ -29,7 +28,7 @@ L example: @@ index.html.tt [% WRAPPER 'layouts/default.html.tt' - title = 'default' + title = 'Welcome' %]

Welcome to the Mojolicious real-time web framework!

Welcome to the TtRenderer plugin!

@@ -42,6 +41,40 @@ L example: [% content %] +L example: + + package MyApp; + use Mojo::Base 'Mojolicious'; + + # This method will run once at server start + sub startup { + my $self = shift; + + $self->plugin('tt_renderer'); + + # Router + my $r = $self->routes; + + # Normal route to controller + $r->get('/')->to('example#welcome'); + } + + 1; + + package MyApp::Example; + use Mojo::Base 'Mojolicious::Controller'; + + # This action will render a template + sub welcome { + my $self = shift; + + # Render template "example/welcome.html.ep" with message + $self->render( + message => 'Welcome to the Mojolicious real-time web framework!'); + } + + 1; + =head1 DESCRIPTION This plugin is a simple Template Toolkit renderer for L. diff --git a/dist.ini b/dist.ini index aaf63db..1fe95f4 100644 --- a/dist.ini +++ b/dist.ini @@ -59,3 +59,6 @@ contributor = Árpád Szász [Author::Plicease::Upload] [InsertExample] + +[MetaNoIndex] +directory = example diff --git a/example/README b/example/README new file mode 100644 index 0000000..39f008e --- /dev/null +++ b/example/README @@ -0,0 +1,8 @@ +Included in this directory are two examples of how to use the Template Toolkit +Renderer. + +myapp.pl - Mojolicious::Lite example +myapp/ - full Mojolicious application example + +They were created as minor modifications of the applications generated +using the 'mojo generate' command. diff --git a/example/myapp.pl b/example/myapp.pl index 6affe65..63d97c5 100644 --- a/example/myapp.pl +++ b/example/myapp.pl @@ -1,6 +1,5 @@ use Mojolicious::Lite; -# Documentation browser under "/perldoc" plugin 'tt_renderer'; get '/' => sub { @@ -15,7 +14,7 @@ __DATA__ @@ index.html.tt [% WRAPPER 'layouts/default.html.tt' - title = 'default' + title = 'Welcome' %]

Welcome to the Mojolicious real-time web framework!

Welcome to the TtRenderer plugin!

diff --git a/example/myapp/lib/MyApp.pm b/example/myapp/lib/MyApp.pm new file mode 100644 index 0000000..d9eafcb --- /dev/null +++ b/example/myapp/lib/MyApp.pm @@ -0,0 +1,17 @@ +package MyApp; +use Mojo::Base 'Mojolicious'; + +# This method will run once at server start +sub startup { + my $self = shift; + + $self->plugin('tt_renderer'); + + # Router + my $r = $self->routes; + + # Normal route to controller + $r->get('/')->to('example#welcome'); +} + +1; diff --git a/example/myapp/lib/MyApp/Example.pm b/example/myapp/lib/MyApp/Example.pm new file mode 100644 index 0000000..a84ae83 --- /dev/null +++ b/example/myapp/lib/MyApp/Example.pm @@ -0,0 +1,13 @@ +package MyApp::Example; +use Mojo::Base 'Mojolicious::Controller'; + +# This action will render a template +sub welcome { + my $self = shift; + + # Render template "example/welcome.html.ep" with message + $self->render( + message => 'Welcome to the Mojolicious real-time web framework!'); +} + +1; diff --git a/example/myapp/log/development.log b/example/myapp/log/development.log new file mode 100644 index 0000000..7e25d14 --- /dev/null +++ b/example/myapp/log/development.log @@ -0,0 +1,21 @@ +[Thu Aug 8 09:00:16 2013] [info] Listening at "http://*:3000". +[Thu Aug 8 09:00:20 2013] [debug] Your secret passphrase needs to be changed!!! +[Thu Aug 8 09:00:20 2013] [debug] GET "/". +[Thu Aug 8 09:00:20 2013] [debug] Routing to controller "MyApp::Example" and action "welcome". +[Thu Aug 8 09:00:20 2013] [error] parse error - example/welcome.html.tt line 8: unexpected end of input +[Thu Aug 8 09:00:20 2013] [debug] Template "exception.development.html.ep" not found. +[Thu Aug 8 09:00:20 2013] [debug] Template "exception.html.ep" not found. +[Thu Aug 8 09:00:20 2013] [debug] Rendering inline template. +[Thu Aug 8 09:00:20 2013] [debug] Rendering inline template. +[Thu Aug 8 09:00:20 2013] [debug] 500 Internal Server Error (0.061556s, 16.245/s). +[Thu Aug 8 09:00:41 2013] [info] Listening at "http://*:3000". +[Thu Aug 8 09:00:44 2013] [debug] Your secret passphrase needs to be changed!!! +[Thu Aug 8 09:00:44 2013] [debug] GET "/". +[Thu Aug 8 09:00:44 2013] [debug] Routing to controller "MyApp::Example" and action "welcome". +[Thu Aug 8 09:00:44 2013] [debug] 200 OK (0.032461s, 30.806/s). +[Thu Aug 8 09:00:47 2013] [debug] GET "/". +[Thu Aug 8 09:00:47 2013] [debug] Routing to controller "MyApp::Example" and action "welcome". +[Thu Aug 8 09:00:47 2013] [debug] 200 OK (0.001260s, 793.651/s). +[Thu Aug 8 09:00:52 2013] [debug] GET "/". +[Thu Aug 8 09:00:52 2013] [debug] Routing to controller "MyApp::Example" and action "welcome". +[Thu Aug 8 09:00:52 2013] [debug] 200 OK (0.001683s, 594.177/s). diff --git a/example/myapp/public/index.html b/example/myapp/public/index.html new file mode 100644 index 0000000..e74bb5f --- /dev/null +++ b/example/myapp/public/index.html @@ -0,0 +1,11 @@ + + + + Welcome to the Mojolicious real-time web framework! + + +

Welcome to the Mojolicious real-time web framework!

+ This is the static document "public/index.html", + click here to get back to the start. + + diff --git a/example/myapp/script/my_app b/example/myapp/script/my_app new file mode 100755 index 0000000..b0be4bd --- /dev/null +++ b/example/myapp/script/my_app @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use FindBin; +BEGIN { unshift @INC, "$FindBin::Bin/../lib" } + +# Start command line interface for application +require Mojolicious::Commands; +Mojolicious::Commands->start_app('MyApp'); diff --git a/example/myapp/t/basic.t b/example/myapp/t/basic.t new file mode 100644 index 0000000..bf8d0c2 --- /dev/null +++ b/example/myapp/t/basic.t @@ -0,0 +1,9 @@ +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('MyApp'); +$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i); + +done_testing(); diff --git a/example/myapp/templates/example/welcome.html.tt b/example/myapp/templates/example/welcome.html.tt new file mode 100644 index 0000000..6407813 --- /dev/null +++ b/example/myapp/templates/example/welcome.html.tt @@ -0,0 +1,10 @@ +[% + WRAPPER 'layouts/default.html.tt' + title = 'Welcome' +%] +

[% $message %]

+This page was generated from the template "templates/example/welcome.html.ep" +and the layout "templates/layouts/default.html.ep", +click here to reload the page or +here to move forward to a static page. +[% END %] diff --git a/example/myapp/templates/layouts/default.html.tt b/example/myapp/templates/layouts/default.html.tt new file mode 100644 index 0000000..ef8169b --- /dev/null +++ b/example/myapp/templates/layouts/default.html.tt @@ -0,0 +1,5 @@ + + + [% title %] + [% content %] + diff --git a/lib/Mojolicious/Plugin/TtRenderer.pm b/lib/Mojolicious/Plugin/TtRenderer.pm index 56ddd26..b558452 100644 --- a/lib/Mojolicious/Plugin/TtRenderer.pm +++ b/lib/Mojolicious/Plugin/TtRenderer.pm @@ -35,6 +35,12 @@ L example: # EXAMPLE: example/myapp.pl +L example: + +# EXAMPLE: example/myapp/lib/MyApp.pm + +# EXAMPLE: example/myapp/lib/MyApp/Example.pm + =head1 DESCRIPTION This plugin is a simple Template Toolkit renderer for L.