From 876f3506e6fbafd7535225c5af42948965ab0e7a Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Mon, 13 Mar 2023 21:54:52 +0100 Subject: [PATCH] Adding initial web, nothing implemented yet. --- Build.PL | 15 +++++++++++++++ lib/MSGBA/Web.pm | 0 lib/msgba-web.pm | 20 ++++++++++++++++++++ lib/msgba-web/Controller/Example.pm | 11 +++++++++++ public/index.html | 11 +++++++++++ script/msgba-web | 11 +++++++++++ t/basic.t | 9 +++++++++ templates/example/welcome.html.ep | 9 +++++++++ templates/layouts/default.html.ep | 5 +++++ 9 files changed, 91 insertions(+) create mode 100755 Build.PL create mode 100644 lib/MSGBA/Web.pm create mode 100644 lib/msgba-web.pm create mode 100644 lib/msgba-web/Controller/Example.pm create mode 100644 public/index.html create mode 100755 script/msgba-web create mode 100644 t/basic.t create mode 100644 templates/example/welcome.html.ep create mode 100644 templates/layouts/default.html.ep diff --git a/Build.PL b/Build.PL new file mode 100755 index 0000000..715a303 --- /dev/null +++ b/Build.PL @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +use Module::Build; + +my $home = $ENV{HOME}; + +my $build = Module::Build->new( + module_name => 'MSGBA::Web', + license => 'AGPLv3', + dist_author => 'Sergio Iglesias ', + dist_abstract => 'The emulator webpage.', + requires => { + 'Mojolicious' => 0, + }, +); +$build->create_build_script; diff --git a/lib/MSGBA/Web.pm b/lib/MSGBA/Web.pm new file mode 100644 index 0000000..e69de29 diff --git a/lib/msgba-web.pm b/lib/msgba-web.pm new file mode 100644 index 0000000..8804e06 --- /dev/null +++ b/lib/msgba-web.pm @@ -0,0 +1,20 @@ +package msgba-web; +use Mojo::Base 'Mojolicious', -signatures; + +# This method will run once at server start +sub startup ($self) { + + # Load configuration from config file + my $config = $self->plugin('NotYAMLConfig'); + + # Configure the application + $self->secrets($config->{secrets}); + + # Router + my $r = $self->routes; + + # Normal route to controller + $r->get('/')->to('Example#welcome'); +} + +1; diff --git a/lib/msgba-web/Controller/Example.pm b/lib/msgba-web/Controller/Example.pm new file mode 100644 index 0000000..36ed71b --- /dev/null +++ b/lib/msgba-web/Controller/Example.pm @@ -0,0 +1,11 @@ +package msgba-web::Controller::Example; +use Mojo::Base 'Mojolicious::Controller', -signatures; + +# This action will render a template +sub welcome ($self) { + + # Render template "example/welcome.html.ep" with message + $self->render(msg => 'Welcome to the Mojolicious real-time web framework!'); +} + +1; diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e74bb5f --- /dev/null +++ b/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/script/msgba-web b/script/msgba-web new file mode 100755 index 0000000..0576d4e --- /dev/null +++ b/script/msgba-web @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Mojo::File qw(curfile); +use lib curfile->dirname->sibling('lib')->to_string; +use Mojolicious::Commands; + +# Start command line interface for application +Mojolicious::Commands->start_app('msgba-web'); diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..25e14a0 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,9 @@ +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('msgba-web'); +$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i); + +done_testing(); diff --git a/templates/example/welcome.html.ep b/templates/example/welcome.html.ep new file mode 100644 index 0000000..0a67219 --- /dev/null +++ b/templates/example/welcome.html.ep @@ -0,0 +1,9 @@ +% layout 'default'; +% title 'Welcome'; +

<%= $msg %>

+

+ This page was generated from the template "templates/example/welcome.html.ep" + and the layout "templates/layouts/default.html.ep", + <%= link_to 'click here' => url_for %> to reload the page or + <%= link_to 'here' => '/index.html' %> to move forward to a static page. +

diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep new file mode 100644 index 0000000..599c556 --- /dev/null +++ b/templates/layouts/default.html.ep @@ -0,0 +1,5 @@ + + + <%= title %> + <%= content %> +