myapp.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
db
Helper#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::SQLite;
helper db => sub {
state $db = Mojo::SQLite->new( 'sqlite:docs.db' );
return $db;
};
app->db->migrations->from_string( <<ENDSQL );
-- 1 up
CREATE TABLE pages (
path VARCHAR PRIMARY KEY,
markdown TEXT,
html TEXT
);
ENDSQL
app->db->auto_migrate(1);
plugin 'Yancy', {
backend => { Sqlite => app->db },
read_schema => 1,
schema => {
pages => {
properties => {
markdown => {
format => 'markdown',
'x-html-field' => 'html',
},
},
},
},
};
get '/*id' => ...;
get '/*id' => 'index';
get '/*id' => sub {
my ( $c ) = @_;
$c->render( text => 'Hello' );
};
get '/*id' => sub {
my ( $c ) = @_;
$c->render( text => 'Hello' );
};
package MyApp::Controller::MyController;
use Mojo::Base 'Mojolicious::Controller';
sub hello {
my ( $c ) = @_;
$c->render( text => 'Hello' );
}
get '/*id' => {
controller => 'MyController',
action => 'hello',
};
get '/*id' => 'MyController#hello';
get '/*id' => {
controller => 'yancy', # Yancy::Controller::Yancy
action => 'get',
schema => 'pages',
template => 'pages',
id => 'index', # Default to index page
};
app->start;
__DATA__
@@ pages.html.ep
%== $item->{html}
<%== $item->{html} %>
<% my $html = $item->{html} %>
<%== $html %>
% if ( $item->{html} ) {
%== $item->{html}
% }
% if ( $item->{html} ) {
<h1><%= $item->{path} %></h1>
%== $item->{html}
% }
$ perl myapp.pl daemon
[Wed Jan 23 23:24:28 2019] [info] Listening at "http://*:3000"
Server available at http://127.0.0.1:3000
Mojolicious::Plugin::PODViewer
plugin 'PODViewer', {
default_module => 'Yancy',
allow_modules => [qw(
Yancy Mojolicious::Plugin::Yancy
)],
};
default
Layout__DATA__
@@ layouts/default.html.ep
__DATA__
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
%= stylesheet "/yancy/bootstrap.css"
<main class="container">
<%= content %>
</main>
@@ pages.html.ep
% content_for 'head' => begin
%= javascript 'vue.js'
% end
@@ layouts/default.html
<head>
%= content 'head'
</head>
<body>
%= content
</body>
pre {
border: 1px solid #ccc;
border-radius: 5px;
background: #f6f6f6;
padding: 0.6em;
}
.crumbs .more {
font-size: small;
}
plugin 'PODViewer', {
layout => 'default',
};
get '/*id' => {
layout => 'default',
};
app->defaults({ layout => 'default' });
/yancy
export
CommandMojolicious::Command::export
$ perl myapp.pl export \
--base /yancy \
--to ./deploy
# [r]ecursive, [v]erbose, [z]ipped, [m]odified dates
# --delete files from destination not in source
rsync -rvzm --delete ./deploy/. \
preaction.me:/var/www/yancy/.
---
title: Yancy
---
# Yancy
Yancy is a simple Content Management System written for
[the Mojolicious web framework](http://mojolicious.org).
plugin Yancy => {
backend => 'static:' . app->home,
read_schema => 1,
};