Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Extract example file metadata collection into its own routine
  • Loading branch information
Paul Cochrane committed Mar 30, 2015
1 parent 83a3a67 commit b245c5a
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/Pod/Htmlify.pm6
Expand Up @@ -67,39 +67,47 @@ class Website is export {
}
}

#| collect metadata for all example files
method collect-all-metadata {
for $!categories.categories-list -> $category, {
my $subcategory = "";
my $category-key = $category.key;
my @files = files-in-category($category-key, base-dir => $!base-categories-dir);
for @files -> $file {
say "Collecting metadata from $file";
my $perl-pod = qqx{perl6-m -Ilib --doc=Perl $file};
my $pod = EVAL $perl-pod;
my $file-basename = $file.basename;
if !$pod {
my @contents = $file.lines.join("\n");
$pod = Array.new(pod-with-title($file-basename,
pod-code(@contents),
));
}
my $example-title = pod-title-contents($pod, $file-basename);
my $author = pod-author-contents($pod, $file-basename);
my $link = pod-link($file-basename, "categories/$category-key/$file-basename");
my $example = Example.new(
title => $example-title,
author => $author,
category => $category-key,
subcategory => $subcategory,
filename => $file,
pod-link => $link,
pod-contents => $pod,
);
%!examples-metadata{$category-key}{$subcategory}{$file-basename} = $example;
my $example = self.collect-example-metadata($file, $category-key, $subcategory);
%!examples-metadata{$category-key}{$subcategory}{$file.basename} = $example;
}
}
}

#| collect metadata for a given example
method collect-example-metadata($file, $category-key, $subcategory) {
say "Collecting metadata from $file";
my $perl-pod = qqx{perl6-m -Ilib --doc=Perl $file};
my $pod = EVAL $perl-pod;
my $file-basename = $file.basename;
if !$pod {
my @contents = $file.lines.join("\n");
$pod = Array.new(pod-with-title($file-basename,
pod-code(@contents),
));
}
my $example-title = pod-title-contents($pod, $file-basename);
my $author = pod-author-contents($pod, $file-basename);
my $link = pod-link($file-basename, "categories/$category-key/$file-basename");
my $example = Example.new(
title => $example-title,
author => $author,
category => $category-key,
subcategory => $subcategory,
filename => $file,
pod-link => $link,
pod-contents => $pod,
);

return $example;
}

method p2h($pod) {
my $head = slurp 'template/head.html';
my $footer = footer-html;
Expand Down

0 comments on commit b245c5a

Please sign in to comment.