Skip to content

Commit 9e6ea27

Browse files
committed
Extract repeated html-writing code into its own routine
1 parent c5e2c11 commit 9e6ea27

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

lib/Pod/Htmlify.pm6

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,37 +163,33 @@ class Website is export {
163163
my $category-key = $category.key;
164164
say "Creating example files for category: $category-key";
165165
my $html-dir = $!base-html-dir ~ "/categories/$category-key/";
166-
my @files = files-in-category($category-key, base-dir => $!base-categories-dir);
167-
for @files -> $file {
168-
next unless $file.IO.e;
169-
my $example = $category.examples{$file.IO.basename};
170-
my $pod = format-author-heading($example);
171-
$pod.push: source-reference($file, $category-key);
172-
my $html-file = $file.IO.basename.subst(/\.p(l|6)$/, ".html");
173-
$html-file = $html-dir ~ $html-file;
174-
spurt $html-file, self.p2h($pod);
175-
}
166+
self.write-example-html($category, $!base-categories-dir, $html-dir);
176167
if $category.subcategories {
177168
for $category.subcategories.categories-list -> $subcategory {
178169
my $subcategory-key = $subcategory.key;
179170
say "Creating example files for subcategory: $subcategory-key";
180171
my $base-dir = $!base-categories-dir ~ "/" ~ $category-key;
181-
my @files = files-in-category($subcategory-key, base-dir => $base-dir);
182172
my $html-dir = $!base-html-dir ~ "/categories/$category-key/$subcategory-key/";
183-
for @files -> $file {
184-
next unless $file.IO.e;
185-
my $example = $subcategory.examples{$file.IO.basename};
186-
my $pod = format-author-heading($example);
187-
$pod.push: source-reference($file, $subcategory-key);
188-
my $html-file = $file.IO.basename.subst(/\.p(l|6)$/, ".html");
189-
$html-file = $html-dir ~ $html-file;
190-
spurt $html-file, self.p2h($pod);
191-
}
173+
self.write-example-html($subcategory, $base-dir, $html-dir);
192174
}
193175
}
194176
}
195177
}
196178

179+
#| write example html to file
180+
method write-example-html($category, $category-dir, $html-dir) {
181+
my @files = files-in-category($category.key, base-dir => $category-dir);
182+
for @files -> $file {
183+
next unless $file.IO.e;
184+
my $example = $category.examples{$file.IO.basename};
185+
my $pod = format-author-heading($example);
186+
$pod.push: source-reference($file, $category.key);
187+
my $html-file = $file.IO.basename.subst(/\.p(l|6)$/, ".html");
188+
$html-file = $html-dir ~ $html-file;
189+
spurt $html-file, self.p2h($pod);
190+
}
191+
}
192+
197193
#| convert the POD into html
198194
method p2h($pod) {
199195
my $head = slurp 'template/head.html';

0 commit comments

Comments
 (0)