]> gb7djk.dxcluster.net Git - spider.git/commitdiff
add dxweb app
authorDirk Koopman <djk@tobit.co.uk>
Sat, 21 Oct 2017 16:08:45 +0000 (17:08 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 21 Oct 2017 16:08:45 +0000 (17:08 +0100)
dxweb/d_x_web.conf [new file with mode: 0644]
dxweb/lib/DXWeb.pm [new file with mode: 0644]
dxweb/lib/DXWeb/Controller/Example.pm [new file with mode: 0644]
dxweb/public/index.html [new file with mode: 0644]
dxweb/script/dxweb [new file with mode: 0755]
dxweb/t/basic.t [new file with mode: 0644]
dxweb/templates/example/welcome.html.ep [new file with mode: 0644]
dxweb/templates/layouts/default.html.ep [new file with mode: 0644]

diff --git a/dxweb/d_x_web.conf b/dxweb/d_x_web.conf
new file mode 100644 (file)
index 0000000..43ae174
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  perldoc => 1,
+  secrets => ['ac82f00b5490aa599f88feafe6b3af4014aefb5a']
+}
diff --git a/dxweb/lib/DXWeb.pm b/dxweb/lib/DXWeb.pm
new file mode 100644 (file)
index 0000000..68c5dcd
--- /dev/null
@@ -0,0 +1,21 @@
+package DXWeb;
+use Mojo::Base 'Mojolicious';
+
+# This method will run once at server start
+sub startup {
+  my $self = shift;
+
+  # Load configuration from hash returned by "my_app.conf"
+  my $config = $self->plugin('Config');
+
+  # Documentation browser under "/perldoc"
+  $self->plugin('PODRenderer') if $config->{perldoc};
+
+  # Router
+  my $r = $self->routes;
+
+  # Normal route to controller
+  $r->get('/')->to('example#welcome');
+}
+
+1;
diff --git a/dxweb/lib/DXWeb/Controller/Example.pm b/dxweb/lib/DXWeb/Controller/Example.pm
new file mode 100644 (file)
index 0000000..e701b7b
--- /dev/null
@@ -0,0 +1,12 @@
+package DXWeb::Controller::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(msg => 'Welcome to the Mojolicious real-time web framework!');
+}
+
+1;
diff --git a/dxweb/public/index.html b/dxweb/public/index.html
new file mode 100644 (file)
index 0000000..e74bb5f
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Welcome to the Mojolicious real-time web framework!</title>
+  </head>
+  <body>
+    <h2>Welcome to the Mojolicious real-time web framework!</h2>
+    This is the static document "public/index.html",
+    <a href="/">click here</a> to get back to the start.
+  </body>
+</html>
diff --git a/dxweb/script/dxweb b/dxweb/script/dxweb
new file mode 100755 (executable)
index 0000000..4200773
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use FindBin;
+BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
+use Mojolicious::Commands;
+
+# Start command line interface for application
+Mojolicious::Commands->start_app('DXWeb');
diff --git a/dxweb/t/basic.t b/dxweb/t/basic.t
new file mode 100644 (file)
index 0000000..f6b2a68
--- /dev/null
@@ -0,0 +1,9 @@
+use Mojo::Base -strict;
+
+use Test::More;
+use Test::Mojo;
+
+my $t = Test::Mojo->new('DXWeb');
+$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
+
+done_testing();
diff --git a/dxweb/templates/example/welcome.html.ep b/dxweb/templates/example/welcome.html.ep
new file mode 100644 (file)
index 0000000..1efd098
--- /dev/null
@@ -0,0 +1,13 @@
+% layout 'default';
+% title 'Welcome';
+<h2><%= $msg %></h2>
+<p>
+  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.
+  % if (config 'perldoc') {
+    To learn more, you can also browse through the documentation
+    <%= link_to 'here' => '/perldoc' %>.
+  % }
+</p>
diff --git a/dxweb/templates/layouts/default.html.ep b/dxweb/templates/layouts/default.html.ep
new file mode 100644 (file)
index 0000000..599c556
--- /dev/null
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<html>
+  <head><title><%= title %></title></head>
+  <body><%= content %></body>
+</html>