App-PFT

 view release on metacpan or  search on metacpan

bin/pft-grab  view on Meta::CPAN

# PFT is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# PFT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with PFT.  If not, see <http://www.gnu.org/licenses/>.

=encoding utf8

=head1 NAME

pft grab - Grab a file as attachment or picture

=head1 SYNOPSIS

B<pft grab> [I<options>] I<file> [I<file> ...]

=head1 DESCRIPTION

Grab one or more files as attachments or pictures, put it in the right
place under C<ROOT/content>.

The command will assume by default that the file is an I<attachment>, that
is a binary file to be stored under C<ROOT/content/attachments>. This
behavior can be overridden by means of the B<--picture> option: as
result the C<ROOT/content/pics> directory will be used instead as
destination.

This command outputs the I<Markdown> code for linking the grabbed content
item in a PFT page.  The output can be inserted in the PFT entry.
The output will be consistent with the attachment/picture choice: if
B<--picture> is specified, the Markdown notation for including a picture
will be used, otherwise the syntax for links will be used.  See L<EXAMPLE>.

Users of the I<ViM> editor may find useful to invoke this command from
within the editor as follows:

    :read ! pft grab [options] file [file...]

=head1 OPTIONS

=over

=item B<--today> | B<-t>

Store the file inside a content directory named after the current day. This
is meant to avoid name conflict with previously stored attachments or
pictures having the same name (see L<EXAMPLE>).

=item B<--picture> | B<-p>

Store the files into the C<I<ROOT>/content/pics> directory and output the
Markdown code required to show it as a picture.

Note that no check is performed on the file format to verify it is actually
a picture.

=item B<--rename>=I<name> | B<-r> I<name>

Rename the file. The alternate file name supplied with this option must
explicitly set the extension, if an extension is desired.  Supplying the
wrong extension will not imply a format change.

This option is not allowed if multiple files are grabbed with the same
command.

=item B<--year>=I<Y> | B<-y> I<Y>

When using B<--today>, overload year with I<Y>. Implies B<--today>.

=item B<--month>=I<M> | B<-m> I<M>

When using B<--today>, overload month with I<M>. Implies B<--today>.

=item B<--day>=I<D> | B<-d> <D>

When using B<--today>, overload day with I<D>. Implies B<--today>.

=item B<--help> | B<-h>

Show this help.

=back

=head1 EXAMPLE

 $ pft grab /tmp/tux.png
 [tux.png]: :attach:tux.png

 $ pft grab /tmp/tux.png --picture
 ![tux.png](:pic:tux.png)

 $ pft grab /tmp/tux.png --picture --today
 ![tux.png](:pic:2016-04-20/tux.png)

 $ pft grab --picture http://example.com/picture.png
 ![picture.png](:pic:picture.png)

=head1 SEE ALSO

L<pft-make(1)>

=cut

use strict;
use warnings;
use feature qw/say/;

use File::Spec::Functions qw/catfile catdir abs2rel/;
use File::Path qw/make_path/;
use File::Basename qw/basename/;
use File::Copy;

use Encode;
use Encode::Locale;



( run in 0.712 second using v1.01-cache-2.11-cpan-437f7b0c052 )