source: main/trunk/greenstone2/perllib/cpan/Mojolicious/Command/generate/app.pm

Last change on this file was 32205, checked in by ak19, 6 years ago

First set of commits to do with implementing the new 'paged_html' output option of PDFPlugin that uses using xpdftools' new pdftohtml. So far tested only on Linux (64 bit), but things work there so I'm optimistically committing the changes since they work. 2. Committing the pre-built Linux binaries of XPDFtools for both 32 and 64 bit built by the XPDF group. 2. To use the correct bitness variant of xpdftools, setup.bash now exports the BITNESS env var, consulted by gsConvert.pl. 3. All the perl code changes to do with using xpdf tools' pdftohtml to generate paged_html and feed it in the desired form into GS(3): gsConvert.pl, PDFPlugin.pm and its parent ConvertBinaryPFile.pm have been modified to make it all work. xpdftools' pdftohtml generates a folder containing an html file and a screenshot for each page in a PDF (as well as an index.html linking to each page's html). However, we want a single html file that contains each individual 'page' html's content in a div, and need to do some further HTML style, attribute and structure modifications to massage the xpdftool output to what we want for GS. In order to parse and manipulate the HTML 'DOM' to do this, we're using the Mojo::DOM package that Dr Bainbridge found and which he's compiled up. Mojo::DOM is therefore also committed in this revision. Some further changes and some display fixes are required, but need to check with the others about that.

File size: 5.1 KB
Line 
1package Mojolicious::Command::generate::app;
2use Mojo::Base 'Mojolicious::Command';
3
4use Mojo::Util qw(class_to_file class_to_path decamelize);
5
6has description => 'Generate Mojolicious application directory structure';
7has usage => sub { shift->extract_usage };
8
9sub run {
10 my ($self, $class) = @_;
11 $class ||= 'MyApp';
12
13 # Prevent bad applications
14 die <<EOF unless $class =~ /^[A-Z](?:\w|::)+$/;
15Your application name has to be a well formed (CamelCase) Perl module name
16like "MyApp".
17EOF
18
19 # Script
20 my $name = class_to_file $class;
21 $self->render_to_rel_file('mojo', "$name/script/$name", $class);
22 $self->chmod_rel_file("$name/script/$name", 0744);
23
24 # Application class
25 my $app = class_to_path $class;
26 $self->render_to_rel_file('appclass', "$name/lib/$app", $class);
27
28 # Config file (using the default moniker)
29 $self->render_to_rel_file('config', "$name/@{[decamelize $class]}.conf");
30
31 # Controller
32 my $controller = "${class}::Controller::Example";
33 my $path = class_to_path $controller;
34 $self->render_to_rel_file('controller', "$name/lib/$path", $controller);
35
36 # Test
37 $self->render_to_rel_file('test', "$name/t/basic.t", $class);
38
39 # Static file
40 $self->render_to_rel_file('static', "$name/public/index.html");
41
42 # Templates
43 $self->render_to_rel_file('layout',
44 "$name/templates/layouts/default.html.ep");
45 $self->render_to_rel_file('welcome',
46 "$name/templates/example/welcome.html.ep");
47}
48
491;
50
51=encoding utf8
52
53=head1 NAME
54
55Mojolicious::Command::generate::app - App generator command
56
57=head1 SYNOPSIS
58
59 Usage: APPLICATION generate app [OPTIONS] [NAME]
60
61 mojo generate app
62 mojo generate app TestApp
63
64 Options:
65 -h, --help Show this summary of available options
66
67=head1 DESCRIPTION
68
69L<Mojolicious::Command::generate::app> generates application directory
70structures for fully functional L<Mojolicious> applications.
71
72This is a core command, that means it is always enabled and its code a good
73example for learning to build new commands, you're welcome to fork it.
74
75See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
76available by default.
77
78=head1 ATTRIBUTES
79
80L<Mojolicious::Command::generate::app> inherits all attributes from
81L<Mojolicious::Command> and implements the following new ones.
82
83=head2 description
84
85 my $description = $app->description;
86 $app = $app->description('Foo');
87
88Short description of this command, used for the command list.
89
90=head2 usage
91
92 my $usage = $app->usage;
93 $app = $app->usage('Foo');
94
95Usage information for this command, used for the help screen.
96
97=head1 METHODS
98
99L<Mojolicious::Command::generate::app> inherits all methods from
100L<Mojolicious::Command> and implements the following new ones.
101
102=head2 run
103
104 $app->run(@ARGV);
105
106Run this command.
107
108=head1 SEE ALSO
109
110L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
111
112=cut
113
114__DATA__
115
116@@ mojo
117% my $class = shift;
118#!/usr/bin/env perl
119
120use strict;
121use warnings;
122
123use FindBin;
124BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
125use Mojolicious::Commands;
126
127# Start command line interface for application
128Mojolicious::Commands->start_app('<%= $class %>');
129
130@@ appclass
131% my $class = shift;
132package <%= $class %>;
133use Mojo::Base 'Mojolicious';
134
135# This method will run once at server start
136sub startup {
137 my $self = shift;
138
139 # Load configuration from hash returned by "my_app.conf"
140 my $config = $self->plugin('Config');
141
142 # Documentation browser under "/perldoc"
143 $self->plugin('PODRenderer') if $config->{perldoc};
144
145 # Router
146 my $r = $self->routes;
147
148 # Normal route to controller
149 $r->get('/')->to('example#welcome');
150}
151
1521;
153
154@@ controller
155% my $class = shift;
156package <%= $class %>;
157use Mojo::Base 'Mojolicious::Controller';
158
159# This action will render a template
160sub welcome {
161 my $self = shift;
162
163 # Render template "example/welcome.html.ep" with message
164 $self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
165}
166
1671;
168
169@@ static
170<!DOCTYPE html>
171<html>
172 <head>
173 <title>Welcome to the Mojolicious real-time web framework!</title>
174 </head>
175 <body>
176 <h2>Welcome to the Mojolicious real-time web framework!</h2>
177 This is the static document "public/index.html",
178 <a href="/">click here</a> to get back to the start.
179 </body>
180</html>
181
182@@ test
183% my $class = shift;
184use Mojo::Base -strict;
185
186use Test::More;
187use Test::Mojo;
188
189my $t = Test::Mojo->new('<%= $class %>');
190$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
191
192done_testing();
193
194@@ layout
195<!DOCTYPE html>
196<html>
197 <head><title><%%= title %></title></head>
198 <body><%%= content %></body>
199</html>
200
201@@ welcome
202%% layout 'default';
203%% title 'Welcome';
204<h2><%%= $msg %></h2>
205<p>
206 This page was generated from the template "templates/example/welcome.html.ep"
207 and the layout "templates/layouts/default.html.ep",
208 <%%= link_to 'click here' => url_for %> to reload the page or
209 <%%= link_to 'here' => '/index.html' %> to move forward to a static page.
210 %% if (config 'perldoc') {
211 To learn more, you can also browse through the documentation
212 <%%= link_to 'here' => '/perldoc' %>.
213 %% }
214</p>
215
216@@ config
217% use Mojo::Util qw(sha1_sum steady_time);
218{
219 perldoc => 1,
220 secrets => ['<%= sha1_sum $$ . steady_time . rand %>']
221}
Note: See TracBrowser for help on using the repository browser.