App-DocKnot
view release on metacpan or search on metacpan
lib/App/DocKnot/Spin/Thread.pm view on Meta::CPAN
$output .= '</p>';
} else {
$output .= "\n";
}
# Close the HTML tag and return the output.
$output .= "</blockquote>\n";
return (1, $output);
}
# Given the name of a product, return the release date of the product.
sub _cmd_release {
my ($self, $package) = @_;
$package = $self->_parse($package);
if (!$self->{versions}) {
$self->_warning('no package release information available');
return (0, q{});
}
my $date = $self->{versions}->release_date($package);
if (!defined($date)) {
$self->_warning(qq(no release date known for "$package"));
return (0, q{});
}
return (0, $date);
}
# Used to save RSS feed information for the page. Doesn't output anything
# directly; the RSS feed information is used later in _cmd_heading.
sub _cmd_rss {
my ($self, $url, $title) = @_;
$url = $self->_parse($url);
$title = $self->_parse($title);
push($self->{rss}->@*, [$url, $title]);
return (1, q{});
}
# Used to end each page, this adds the navigation links and my standard
# address block.
sub _cmd_signature {
my ($self) = @_;
my $input_path = $self->{input}[-1][1];
my $output = $self->_border_end();
# If we're spinning from standard input to standard output, don't add any
# of the standard footer, just close the HTML tags.
if (!defined($input_path) && !defined($self->{out_path})) {
$output .= "</body>\n</html>\n";
return (1, $output);
}
# Add the end-of-page navbar if we have sitemap information.
if ($self->{sitemap} && $self->{output}) {
my $page = $self->{out_path}->relative($self->{output});
$output .= join(q{}, $self->{sitemap}->navbar($page)) . "\n";
}
# Figure out the modification dates. Use the Git repository if available.
my $now = strftime('%Y-%m-%d', gmtime());
my $modified = $now;
if (defined($input_path)) {
$modified = strftime('%Y-%m-%d', gmtime($input_path->stat()->[9]));
}
if ($self->{repository} && $self->{source}) {
if (path($self->{source})->subsumes($input_path)) {
my $repository = $self->{repository};
$modified = $self->{repository}->run(
'log', '-1', '--format=%ct', "$input_path",
);
if ($modified) {
$modified = strftime('%Y-%m-%d', gmtime($modified));
}
}
}
# Determine which template to use and substitute in the appropriate times.
$output .= "<address>\n";
my $link = qq{<a href="$URL">spun</a>};
if ($modified eq $now) {
$output .= " Last modified and\n $link $modified\n";
} else {
$output .= " Last $link\n";
$output .= " $now from $self->{input_type} modified $modified\n";
}
# Close out the document.
$output .= "</address>\n</body>\n</html>\n";
return (1, $output);
}
# Insert the formatted size in bytes, kilobytes, or megabytes of some local
# file. We could use Number::Format here, but what we're doing is simple
# enough and doesn't seem worth the trouble of another dependency.
sub _cmd_size {
my ($self, $file) = @_;
$file = $self->_file_path($self->_parse($file));
# Get the size of the file.
my $size;
if ($file->exists()) {
$size = $file->stat()->[7];
}
if (!defined($size)) {
$self->_warning("cannot stat file $file: $!");
return (0, q{});
}
# Format the size using SI units.
my @suffixes = qw(Ki Mi Gi Ti);
my $suffix = q{};
while ($size > 1024 && @suffixes) {
$size /= 1024;
$suffix = shift(@suffixes);
}
# Return the result.
return (0, sprintf('%.0f', $size) . $suffix . 'B');
}
# Generates a HTML version of the sitemap and outputs that.
sub _cmd_sitemap {
my ($self) = @_;
if (!$self->{sitemap}) {
$self->_warning('no sitemap file found');
return (1, q{});
}
my $sitemap = join(q{}, $self->{sitemap}->sitemap());
return (1, $self->_border_end() . $sitemap);
}
# Start a table. Takes any additional HTML attributes to set for the table
# (this is ugly, but <table> takes so many attributes for which there is no
# style sheet equivalent that it's unavoidable) and the body of the table
# (which should consist of \tablehead and \tablerow lines).
sub _cmd_table {
my ($self, $format, $options, $body) = @_;
my $tag = $options ? "table $options" : 'table';
return $self->_block($tag, q{}, $format, $body);
}
# A heading of a table. Takes the contents of the cells in that heading.
sub _cmd_tablehead {
my ($self, $format, @cells) = @_;
my $output = ' <tr' . $self->_format_attr($format) . ">\n";
for (@cells) {
my $text = $self->_parse($_) . $self->_border_end();
$output .= (q{ } x 4) . $self->_enclose('th', $text) . "\n";
}
$output .= " </tr>\n";
return (1, $output);
}
# A data line of a table. Takes the contents of the cells in that row.
sub _cmd_tablerow {
my ($self, $format, @cells) = @_;
my $output = ' <tr' . $self->_format_attr($format) . ">\n";
for (@cells) {
my $text = $self->_parse($_) . $self->_border_end();
$output .= (q{ } x 4) . $self->_enclose('td', $text) . "\n";
}
$output .= " </tr>\n";
( run in 2.187 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )