第十八天 - POD 一览
— 焉知非鱼第18天:对POD的看法
为了让Yancy拥有一个好的文档站点,实际上它需要渲染文档。要在Mojolicious中渲染Perl文档 ,我可以使用 PODViewer 插件(现已弃用的PODRenderer 插件的一个分支 )。
将PODViewer添加到现有站点很容易!
use Mojolicious::Lite;
plugin 'PODViewer';
app->start;
现在,当我访问http://127.0.0.1:3000/perldoc 时我看到了Mojolicious的 POD::Guides。这很棒,但是这是 Yancy 的文档站点,而不是 Mojolicious 的。让我们调整一些配置来使 Yancy 成为默认模块,并且只允许查看Yancy 模块(尝试查看另一个模块会将用户重定向到MetaCPAN)。
use Mojolicious::Lite;
plugin 'PODViewer', {
default_module => 'Yancy',
allow_modules => [qw( Yancy Mojolicious::Plugin::Yancy )],
};
app->start;
在那里,现在Yancy文档显示在首页。
最后,让它看起来更好一些:文档肯定需要使用默认的站点布局,而一些额外的CSS也会使文档看起来好看多了!
use Mojolicious::Lite;
plugin 'PODViewer', {
default_module => 'Yancy',
allow_modules => [qw( Yancy Mojolicious::Plugin::Yancy )],
layout => 'default',
};
app->start;
__DATA__
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/yancy/bootstrap.css">
<style>
h1 { font-size: 2.00rem }
h2 { font-size: 1.75rem }
h3 { font-size: 1.50rem }
h1, h2, h3 {
position: relative;
}
h1 .permalink, h2 .permalink, h3 .permalink {
position: absolute;
top: auto;
left: -0.7em;
color: #ddd;
}
h1:hover .permalink, h2:hover .permalink, h3:hover .permalink {
color: #212529;
}
pre {
border: 1px solid #ccc;
border-radius: 5px;
background: #f6f6f6;
padding: 0.6em;
}
.crumbs .more {
font-size: small;
}
</style>
<title><%= title %></title>
</head>
<body>
%= content
</body>
</html>
现在我们的文档很好看!
这是完整的源代码。现在我有一个漂亮的网站,我只需要将新网站部署到互联网上……
道格贝尔(preaction)是 Perl 的长期用户。他是CPAN测试人员的当前维护者,也是许多CPAN模块的作者,包括为该网站提供支持的Statocles博客引擎。