From 694a499e54860cd82e3b3e85c4cd06c781586e83 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Tue, 14 May 2013 22:19:05 +1200 Subject: [PATCH 1/1] Save boilerplate. --- MANIFEST | 19 ++++ MANIFEST.SKIP | 13 +++ Makefile.PL | 21 ++++ bin/app.pl | 4 + config.yml | 29 ++++++ environments/development.yml | 27 +++++ environments/production.yml | 17 ++++ lib/EtcX/Sounds.pm | 10 ++ public/404.html | 18 ++++ public/500.html | 18 ++++ public/css/error.css | 70 +++++++++++++ public/css/style.css | 189 +++++++++++++++++++++++++++++++++++ public/dispatch.cgi | 15 +++ public/dispatch.fcgi | 17 ++++ public/javascripts/jquery.js | 1 + t/001_base.t | 5 + t/002_index_route.t | 10 ++ views/index.tt | 148 +++++++++++++++++++++++++++ views/layouts/main.tt | 20 ++++ 19 files changed, 651 insertions(+) create mode 100644 MANIFEST create mode 100644 MANIFEST.SKIP create mode 100644 Makefile.PL create mode 100755 bin/app.pl create mode 100644 config.yml create mode 100644 environments/development.yml create mode 100644 environments/production.yml create mode 100644 lib/EtcX/Sounds.pm create mode 100644 public/404.html create mode 100644 public/500.html create mode 100644 public/css/error.css create mode 100644 public/css/style.css create mode 100755 public/dispatch.cgi create mode 100755 public/dispatch.fcgi create mode 120000 public/javascripts/jquery.js create mode 100644 t/001_base.t create mode 100644 t/002_index_route.t create mode 100644 views/index.tt create mode 100644 views/layouts/main.tt diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..9636ad7 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,19 @@ +MANIFEST +bin/app.pl +config.yml +environments/development.yml +environments/production.yml +views/index.tt +views/layouts/main.tt +MANIFEST.SKIP +lib/EtcX/Sounds.pm +public/css/style.css +public/css/error.css +public/404.html +public/dispatch.fcgi +public/javascripts/jquery.js +public/dispatch.cgi +public/500.html +t/002_index_route.t +t/001_base.t +Makefile.PL diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..8fd3d29 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,13 @@ +^\.git\/ +maint +^tags$ +.last_cover_stats +Makefile$ +^blib +^pm_to_blib +^.*.bak +^.*.old +^t.*sessions +^cover_db +^.*\.log +^.*\.swp$ diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..41752d6 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,21 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'EtcX::Sounds', + AUTHOR => q{Andrew Ruthven }, + VERSION_FROM => 'lib/EtcX/Sounds.pm', + ABSTRACT => 'Simple playlist and album selector for MPD', + ($ExtUtils::MakeMaker::VERSION >= 6.3002 + ? ('LICENSE'=> 'perl') + : ()), + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + 'YAML' => 0, + 'Dancer' => 1.3095, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'EtcX-Sounds-*' }, +); diff --git a/bin/app.pl b/bin/app.pl new file mode 100755 index 0000000..286c2cb --- /dev/null +++ b/bin/app.pl @@ -0,0 +1,4 @@ +#!/usr/bin/env perl +use Dancer; +use EtcX::Sounds; +dance; diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..c02a571 --- /dev/null +++ b/config.yml @@ -0,0 +1,29 @@ +# This is the main configuration file of your Dancer app +# env-related settings should go to environments/$env.yml +# all the settings in this file will be loaded at Dancer's startup. + +# Your application's name +appname: "EtcX::Sounds" + +# The default layout to use for your application (located in +# views/layouts/main.tt) +layout: "main" + +# when the charset is set to UTF-8 Dancer will handle for you +# all the magic of encoding and decoding. You should not care +# about unicode within your app when this setting is set (recommended). +charset: "UTF-8" + +# template engine +# simple: default and very basic template engine +# template_toolkit: TT + +template: "simple" + +# template: "template_toolkit" +# engines: +# template_toolkit: +# encoding: 'utf8' +# start_tag: '[%' +# end_tag: '%]' + diff --git a/environments/development.yml b/environments/development.yml new file mode 100644 index 0000000..2d3eaa7 --- /dev/null +++ b/environments/development.yml @@ -0,0 +1,27 @@ +# configuration file for development environment + +# the logger engine to use +# console: log messages to STDOUT (your console where you started the +# application server) +# file: log message to a file in log/ +logger: "console" + +# the log level for this environment +# core is the lowest, it shows Dancer's core log messages as well as yours +# (debug, info, warning and error) +log: "core" + +# should Dancer consider warnings as critical errors? +warnings: 1 + +# should Dancer show a stacktrace when an error is caught? +show_errors: 1 + +# auto_reload is a development and experimental feature +# you should enable it by yourself if you want it +# Module::Refresh is needed +# +# Be aware it's unstable and may cause a memory leak. +# DO NOT EVER USE THAT FEATURE IN PRODUCTION +# OR TINY KITTENS SHALL DIE WITH LOTS OF SUFFERING +auto_reload: 0 diff --git a/environments/production.yml b/environments/production.yml new file mode 100644 index 0000000..86801b4 --- /dev/null +++ b/environments/production.yml @@ -0,0 +1,17 @@ +# configuration file for production environment + +# only log warning and error messsages +log: "warning" + +# log message to a file in logs/ +logger: "file" + +# don't consider warnings critical +warnings: 0 + +# hide errors +show_errors: 0 + +# cache route resolution for maximum performance +route_cache: 1 + diff --git a/lib/EtcX/Sounds.pm b/lib/EtcX/Sounds.pm new file mode 100644 index 0000000..6d8e78b --- /dev/null +++ b/lib/EtcX/Sounds.pm @@ -0,0 +1,10 @@ +package EtcX::Sounds; +use Dancer ':syntax'; + +our $VERSION = '0.1'; + +get '/' => sub { + template 'index'; +}; + +true; diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..fc3e1c4 --- /dev/null +++ b/public/404.html @@ -0,0 +1,18 @@ + + + +Error 404 + + + + +

Error 404

+
+

Page Not Found

Sorry, this is the void.

+
+ + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..232dde9 --- /dev/null +++ b/public/500.html @@ -0,0 +1,18 @@ + + + +Error 500 + + + + +

Error 500

+
+

Internal Server Error

Wooops, something went wrong

+
+ + + diff --git a/public/css/error.css b/public/css/error.css new file mode 100644 index 0000000..003ee2a --- /dev/null +++ b/public/css/error.css @@ -0,0 +1,70 @@ +body { + font-family: Lucida,sans-serif; +} + +h1 { + color: #AA0000; + border-bottom: 1px solid #444; +} + +h2 { color: #444; } + +pre { + font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; + font-size: 12px; + border-left: 2px solid #777; + padding-left: 1em; +} + +footer { + font-size: 10px; +} + +span.key { + color: #449; + font-weight: bold; + width: 120px; + display: inline; +} + +span.value { + color: #494; +} + +/* these are for the message boxes */ + +pre.content { + background-color: #eee; + color: #000; + padding: 1em; + margin: 0; + border: 1px solid #aaa; + border-top: 0; + margin-bottom: 1em; +} + +div.title { + font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; + font-size: 12px; + background-color: #aaa; + color: #444; + font-weight: bold; + padding: 3px; + padding-left: 10px; +} + +pre.content span.nu { + color: #889; + margin-right: 10px; +} + +pre.error { + background: #334; + color: #ccd; + padding: 1em; + border-top: 1px solid #000; + border-left: 1px solid #000; + border-right: 1px solid #eee; + border-bottom: 1px solid #eee; +} + diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..706c3e5 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,189 @@ + +body { +margin: 0; +margin-bottom: 25px; +padding: 0; +background-color: #ddd; +background-image: url("/images/perldancer-bg.jpg"); +background-repeat: no-repeat; +background-position: top left; + +font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana"; +font-size: 13px; +color: #333; +} + +h1 { +font-size: 28px; +color: #000; +} + +a {color: #03c} +a:hover { +background-color: #03c; +color: white; +text-decoration: none; +} + +#page { +background-color: #ddd; +width: 750px; +margin: auto; +margin-left: auto; +padding-left: 0px; +margin-right: auto; +} + +#content { +background-color: white; +border: 3px solid #aaa; +border-top: none; +padding: 25px; +width: 500px; +} + +#sidebar { +float: right; +width: 175px; +} + +#header, #about, #getting-started { +padding-left: 75px; +padding-right: 30px; +} + + +#header { +background-image: url("/images/perldancer.jpg"); +background-repeat: no-repeat; +background-position: top left; +height: 64px; +} +#header h1, #header h2 {margin: 0} +#header h2 { +color: #888; +font-weight: normal; +font-size: 16px; +} + +#about h3 { +margin: 0; +margin-bottom: 10px; +font-size: 14px; +} + +#about-content { +background-color: #ffd; +border: 1px solid #fc0; +margin-left: -11px; +} +#about-content table { +margin-top: 10px; +margin-bottom: 10px; +font-size: 11px; +border-collapse: collapse; +} +#about-content td { +padding: 10px; +padding-top: 3px; +padding-bottom: 3px; +} +#about-content td.name {color: #555} +#about-content td.value {color: #000} + +#about-content.failure { +background-color: #fcc; +border: 1px solid #f00; +} +#about-content.failure p { +margin: 0; +padding: 10px; +} + +#getting-started { +border-top: 1px solid #ccc; +margin-top: 25px; +padding-top: 15px; +} +#getting-started h1 { +margin: 0; +font-size: 20px; +} +#getting-started h2 { +margin: 0; +font-size: 14px; +font-weight: normal; +color: #333; +margin-bottom: 25px; +} +#getting-started ol { +margin-left: 0; +padding-left: 0; +} +#getting-started li { +font-size: 18px; +color: #888; +margin-bottom: 25px; +} +#getting-started li h2 { +margin: 0; +font-weight: normal; +font-size: 18px; +color: #333; +} +#getting-started li p { +color: #555; +font-size: 13px; +} + +#search { +margin: 0; +padding-top: 10px; +padding-bottom: 10px; +font-size: 11px; +} +#search input { +font-size: 11px; +margin: 2px; +} +#search-text {width: 170px} + +#sidebar ul { +margin-left: 0; +padding-left: 0; +} +#sidebar ul h3 { +margin-top: 25px; +font-size: 16px; +padding-bottom: 10px; +border-bottom: 1px solid #ccc; +} +#sidebar li { +list-style-type: none; +} +#sidebar ul.links li { +margin-bottom: 5px; +} + +h1, h2, h3, h4, h5 { +font-family: sans-serif; +margin: 1.2em 0 0.6em 0; +} + +p { +line-height: 1.5em; +margin: 1.6em 0; +} + +code, tt { + font-family: 'Andale Mono', Monaco, 'Liberation Mono', 'Bitstream Vera Sans Mono', 'DejaVu Sans Mono', monospace; +} + +#footer { +clear: both; +padding-top: 2em; +text-align: center; +padding-right: 160px; +font-family: sans-serif; +font-size: 10px; +} diff --git a/public/dispatch.cgi b/public/dispatch.cgi new file mode 100755 index 0000000..3bb7f2a --- /dev/null +++ b/public/dispatch.cgi @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +use Dancer ':syntax'; +use FindBin '$RealBin'; +use Plack::Runner; + +# For some reason Apache SetEnv directives dont propagate +# correctly to the dispatchers, so forcing PSGI and env here +# is safer. +set apphandler => 'PSGI'; +set environment => 'production'; + +my $psgi = path($RealBin, '..', 'bin', 'app.pl'); +die "Unable to read startup script: $psgi" unless -r $psgi; + +Plack::Runner->run($psgi); diff --git a/public/dispatch.fcgi b/public/dispatch.fcgi new file mode 100755 index 0000000..8c42e3a --- /dev/null +++ b/public/dispatch.fcgi @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +use Dancer ':syntax'; +use FindBin '$RealBin'; +use Plack::Handler::FCGI; + +# For some reason Apache SetEnv directives dont propagate +# correctly to the dispatchers, so forcing PSGI and env here +# is safer. +set apphandler => 'PSGI'; +set environment => 'production'; + +my $psgi = path($RealBin, '..', 'bin', 'app.pl'); +my $app = do($psgi); +die "Unable to read startup script: $@" if $@; +my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1); + +$server->run($app); diff --git a/public/javascripts/jquery.js b/public/javascripts/jquery.js new file mode 120000 index 0000000..b77fd86 --- /dev/null +++ b/public/javascripts/jquery.js @@ -0,0 +1 @@ +/usr/share/javascript/jquery/jquery.js \ No newline at end of file diff --git a/t/001_base.t b/t/001_base.t new file mode 100644 index 0000000..4ffb91c --- /dev/null +++ b/t/001_base.t @@ -0,0 +1,5 @@ +use Test::More tests => 1; +use strict; +use warnings; + +use_ok 'EtcX::Sounds'; diff --git a/t/002_index_route.t b/t/002_index_route.t new file mode 100644 index 0000000..e88eb5b --- /dev/null +++ b/t/002_index_route.t @@ -0,0 +1,10 @@ +use Test::More tests => 2; +use strict; +use warnings; + +# the order is important +use EtcX::Sounds; +use Dancer::Test; + +route_exists [GET => '/'], 'a route handler is defined for /'; +response_status_is ['GET' => '/'], 200, 'response status is 200 for /'; diff --git a/views/index.tt b/views/index.tt new file mode 100644 index 0000000..cf4382e --- /dev/null +++ b/views/index.tt @@ -0,0 +1,148 @@ + + + +
+ + +
+ + +
+

Getting started

+

Here’s how to get dancing:

+ +

About your application's environment

+ + + + + + +
    +
  1. +

    Tune your application

    + +

    + Your application is configured via a global configuration file, + config.yml and an "environment" configuration file, + environments/development.yml. Edit those files if you + want to change the settings of your application. +

    +
  2. + +
  3. +

    Add your own routes

    + +

    + The default route that displays this page can be removed, + it's just here to help you get started. The template used to + generate this content is located in + views/index.tt. + You can add some routes to lib/EtcX/Sounds.pm. +

    +
  4. + +
  5. +

    Enjoy web development again

    + +

    + Once you've made your changes, restart your standalone server + (bin/app.pl) and you're ready to test your web application. +

    +
  6. + +
+
+
+
diff --git a/views/layouts/main.tt b/views/layouts/main.tt new file mode 100644 index 0000000..a7ef88d --- /dev/null +++ b/views/layouts/main.tt @@ -0,0 +1,20 @@ + + + + +EtcX::Sounds + + + + + + +<% content %> + + + -- 2.30.2