source: main/trunk/greenstone2/perllib/cpan/Mojo/Home.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: 1.8 KB
Line 
1package Mojo::Home;
2use Mojo::Base 'Mojo::File';
3
4use Mojo::Util 'class_to_path';
5
6sub detect {
7 my ($self, $class) = @_;
8
9 # Environment variable
10 my $home;
11 if ($ENV{MOJO_HOME}) { $home = Mojo::File->new($ENV{MOJO_HOME})->to_array }
12
13 # Location of the application class (Windows mixes backslash and slash)
14 elsif ($class && (my $path = $INC{my $file = class_to_path $class})) {
15 $home = Mojo::File->new($path)->to_array;
16 splice @$home, (my @dummy = split('/', $file)) * -1;
17 @$home && $home->[-1] eq $_ && pop @$home for qw(lib blib);
18 }
19
20 $$self = Mojo::File->new(@$home)->to_abs->to_string if $home;
21 return $self;
22}
23
24sub mojo_lib_dir { shift->new(__FILE__)->sibling('..') }
25
26sub rel_file { shift->child(split('/', shift)) }
27
281;
29
30=encoding utf8
31
32=head1 NAME
33
34Mojo::Home - Home sweet home
35
36=head1 SYNOPSIS
37
38 use Mojo::Home;
39
40 # Find and manage the project root directory
41 my $home = Mojo::Home->new;
42 $home->detect;
43 say $home->child('templates', 'layouts', 'default.html.ep');
44 say "$home";
45
46=head1 DESCRIPTION
47
48L<Mojo::Home> is a container for home directories based on L<Mojo::File>.
49
50=head1 METHODS
51
52L<Mojo::Home> inherits all methods from L<Mojo::File> and implements the
53following new ones.
54
55=head2 detect
56
57 $home = $home->detect;
58 $home = $home->detect('My::App');
59
60Detect home directory from the value of the C<MOJO_HOME> environment variable or
61the location of the application class.
62
63=head2 mojo_lib_dir
64
65 my $path = $home->mojo_lib_dir;
66
67Path to C<lib> directory in which L<Mojolicious> is installed as a L<Mojo::Home>
68object.
69
70=head2 rel_file
71
72 my $path = $home->rel_file('foo/bar.html');
73
74Return a new L<Mojo::Home> object relative to the home directory.
75
76=head1 OPERATORS
77
78L<Mojo::Home> inherits all overloaded operators from L<Mojo::File>.
79
80=head1 SEE ALSO
81
82L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
83
84=cut
Note: See TracBrowser for help on using the repository browser.