@ -8,17 +8,20 @@ WRT - WRiting Tool
= head1 SYNOPSIS
wrt 2016 > 2016 . html
wrt - - render
$ wrt display 2016 > 2016 . html
Or:
#!/usr/bin/perl
$ wrt render
Or:
#!/usr/bin/env perl
use WRT ;
my $ w = WRT - > new (
root_dir = > 'archives' ,
url_root = > '/' ,
entry _dir = > 'archives' ,
url_root = > '/' ,
# etc.
) ;
print $ w - > display ( @ ARGV ) ;
@ -43,7 +46,7 @@ run as a CGI script. This is a better idea, for the most part.
The C <WRT> module will work with FastCGI , if called from the appropriate
wrapper script , such as C <wrt-fcgi> .
By default , entries are stored in a simple directory tree under C <root _dir> .
By default , entries are stored in a simple directory tree under C <entry _dir> .
Like:
@ -134,7 +137,7 @@ As it stands, freeverse, image, and list are not particularly robust.
package WRT ;
our ( $ VERSION ) = '2.0.1 ' ;
our ( $ VERSION ) = '3.0.0 ' ;
use strict ;
use warnings ;
@ -142,6 +145,7 @@ no warnings 'uninitialized';
use base 'WRT::MethodSpit' ;
use Cwd ;
use HTML::Entities ;
use JSON ;
use XML::Atom::SimpleFeed ;
@ -149,7 +153,7 @@ use XML::Atom::SimpleFeed;
use WRT::Date ;
use WRT::HTML qw( :all ) ;
use WRT::Image qw( image_size ) ;
use WRT::Markup qw( line_parse image_markup ) ;
use WRT::Markup qw( line_parse image_markup eval_perl ) ;
use WRT::Renderer qw( render ) ;
use WRT::Util qw( dir_list get_date ) ;
@ -164,7 +168,8 @@ See F<conf.pl> for a sample configuration.
= cut
my % default = (
root_dir = > 'archives' , # root dir for archived files
root_dir = > '.' , # dir for wrt repository
entry_dir = > 'archives' , # dir for entry files
url_root = > "$0?" , # root URL for building links
image_url_root = > '' , # same for images
template_dir = > 'templates' , # dir for template files
@ -219,7 +224,7 @@ A good way to ensure that this does not happen is to use patterns like:
... always marking the start and end of the string explicitly .
This will probab ly be rewritten to use an array so that the order can be
This may eventual ly be rewritten to use an array so that the order can be
explicitly specified .
= cut
@ -405,7 +410,7 @@ sub expand_option {
chop $ option if $ option =~ m {/$} ;
if ( $ option eq 'all' ) {
return dir_list ( $ self - > root _dir, 'high_to_low' , qr/^[0-9]{1,4}$/ ) ;
return dir_list ( $ self - > entry _dir, 'high_to_low' , qr/^[0-9]{1,4}$/ ) ;
} elsif ( $ option eq 'new' ) {
return $ self - > recent_month ( ) ;
} elsif ( $ option eq 'fulltext' ) {
@ -426,7 +431,7 @@ If a year file is text, returns that instead.
sub recent_month {
my $ self = shift ;
my ( $ dir ) = $ self - > root _dir;
my ( $ dir ) = $ self - > entry _dir;
my ( $ mon , $ year ) = get_date ( 'mon' , 'year' ) ;
@ -459,11 +464,11 @@ sub fulltext {
my @ individual_entries ;
my @ years = dir_list ( $ self - > root _dir, 'low_to_high' , qr/^[0-9]{1,4}$/ ) ;
my @ years = dir_list ( $ self - > entry _dir, 'low_to_high' , qr/^[0-9]{1,4}$/ ) ;
foreach my $ year ( @ years ) {
my @ months = dir_list ( $ self - > root _dir . '/' . $ year , 'low_to_high' , qr/^[0-9]+$/ ) ;
my @ months = dir_list ( $ self - > entry _dir . '/' . $ year , 'low_to_high' , qr/^[0-9]+$/ ) ;
foreach my $ month ( @ months ) {
my @ days = dir_list ( $ self - > root _dir . '/' . $ year . '/' . $ month , 'low_to_high' , qr/^[0-9]+$/ ) ;
my @ days = dir_list ( $ self - > entry _dir . '/' . $ year . '/' . $ month , 'low_to_high' , qr/^[0-9]+$/ ) ;
foreach my $ day ( @ days ) {
push @ individual_entries , "$year/$month/$day" ;
}
@ -960,42 +965,6 @@ sub fragment_slurp {
}
= item eval_perl
Evaluate embedded Perl in a string , replacing blocks enclosed with <perl> tags
with whatever they return ( well , evaluated in a scalar context ) . Returns the
modified string .
Also handles simple $ { variables } , replacing them from the keys to $ self .
= cut
sub eval_perl {
my $ self = shift ;
my ( $ text ) = @ _ ;
while ( $ text =~ m {<perl>(.*?)</perl>}s ) {
my $ block = $ 1 ;
# Run the $block, and include anything returned:
my $ output = eval $ block ;
if ( $@ ) {
# Errors - log and return an empty string:
print STDERR $@ ;
$ output = '' ;
}
$ text =~ s{<perl>\Q$block\E</perl>} {$output}s ;
}
# Interpolate variables:
$ text =~ s/\$\{([a-zA-Z_]+)\}/$self->{$1}/ge ;
return $ text ;
}
= item month_name
Turn numeric dates into English .
@ -1015,7 +984,7 @@ sub month_name {
= item root_locations ( $ file )
Given a file / entry , return the appropriate concatenations with
root _dir and url_root .
entry _dir and url_root .
= cut
@ -1035,7 +1004,7 @@ Arguably this is stupid and inefficient.
= cut
sub local_path {
return $ _ [ 0 ] - > root _dir . '/' . $ _ [ 1 ] ;
return $ _ [ 0 ] - > entry _dir . '/' . $ _ [ 1 ] ;
}
= item feed_print