You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2013/06/30 22:15:43 UTC
[lucy-commits] git commit: refs/heads/master - Create documentation index pages as
.mdtext files
Updated Branches:
refs/heads/master 0a36c4cb8 -> acc7158f6
Create documentation index pages as .mdtext files
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/acc7158f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/acc7158f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/acc7158f
Branch: refs/heads/master
Commit: acc7158f6295821328f6fa775fa7795fb55e8bc9
Parents: 0a36c4c
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sun Jun 30 22:14:36 2013 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Jun 30 22:14:36 2013 +0200
----------------------------------------------------------------------
devel/bin/pod2html.pl | 58 ----------------
devel/bin/pod2mdtext.pl | 155 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 155 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/acc7158f/devel/bin/pod2html.pl
----------------------------------------------------------------------
diff --git a/devel/bin/pod2html.pl b/devel/bin/pod2html.pl
deleted file mode 100755
index 9e93152..0000000
--- a/devel/bin/pod2html.pl
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/perl
-
-use File::Find;
-use File::Path qw(make_path);
-use File::Slurp;
-use Pod::Simple::HTML;
-
-sub pod2html {
- my ($base_dir, $filename) = @_;
-
- my @path_comps = split('/', $filename);
- pop(@path_comps);
-
- my $out_dir = join('/', 'html', @path_comps);
- make_path($out_dir);
-
- my $out_filename = "html/$filename";
- $out_filename =~ s"(\.[^/.]*)?$".mdtext";
-
- open(my $out_file, '>', $out_filename)
- or die("$out_filename: $!");
-
- my $p = Pod::Simple::HTML->new;
-
- $p->batch_mode(1);
- $p->batch_mode_current_level(scalar(@path_comps) + 1);
- $p->html_header_before_title('Title: ');
- $p->html_header_after_title(" - Apache Lucy Documentation\n\n<div>\n");
- $p->html_footer("\n</div>\n");
-
- $p->output_fh($out_file);
- $p->parse_file("$base_dir/$filename");
-
- close($out_file);
-}
-
-for my $dir (qw(lib)) {
- my $wanted = sub {
- my $filename = $_;
-
- return if -d $filename;
-
- if ($filename =~ /\.pm$/) {
- my $content = read_file($filename);
- return unless $content =~ /^=head1/m;
- }
- elsif ($filename !~ /\.pod$/) {
- return;
- }
-
- $filename =~ s"^$dir/"";
-
- pod2html($dir, $filename);
- };
-
- find({ wanted => $wanted, no_chdir => 1 }, $dir);
-}
-
http://git-wip-us.apache.org/repos/asf/lucy/blob/acc7158f/devel/bin/pod2mdtext.pl
----------------------------------------------------------------------
diff --git a/devel/bin/pod2mdtext.pl b/devel/bin/pod2mdtext.pl
new file mode 100755
index 0000000..e83652d
--- /dev/null
+++ b/devel/bin/pod2mdtext.pl
@@ -0,0 +1,155 @@
+#!/usr/bin/perl
+use strict;
+
+package NameExtractor;
+
+use base qw(Pod::Simple);
+
+# Extremely dirty extraction of NAME sections.
+
+sub _handle_element_start {
+ my ($parser, $element_name, $attr_hash_r) = @_;
+
+ if ($element_name eq 'head1') {
+ $parser->{in_head1} = 1;
+ $parser->{head1_content} = '';
+ }
+}
+
+sub _handle_text {
+ my ($parser, $text) = @_;
+
+ if ($parser->{in_head1}) {
+ $parser->{head1_content} .= $text;
+ }
+ elsif ($parser->{after_head1}) {
+ $parser->{extracted_name} = $text;
+ $parser->{after_head1} = undef;
+ }
+}
+
+sub _handle_element_end {
+ my ($parser, $element_name, $attr_hash_r) = @_;
+
+ if ($element_name eq 'head1') {
+ if ($parser->{head1_content} eq 'NAME') {
+ $parser->{after_head1} = 1;
+ }
+ $parser->{in_head1} = undef;
+ }
+}
+
+package main;
+
+use File::Find;
+use File::Path qw(make_path);
+use File::Slurp;
+use Getopt::Std;
+use Pod::Simple::HTML;
+
+sub pod2html {
+ my ($base_dir, $filename) = @_;
+
+ my @path_comps = split('/', $filename);
+ pop(@path_comps);
+
+ my $out_dir = join('/', 'html', @path_comps);
+ make_path($out_dir);
+
+ my $out_filename = "html/$filename";
+ $out_filename =~ s"(\.[^/.]*)?$".mdtext";
+
+ open(my $out_file, '>', $out_filename)
+ or die("$out_filename: $!");
+
+ my $p = Pod::Simple::HTML->new;
+
+ $p->batch_mode(1);
+ $p->batch_mode_current_level(scalar(@path_comps) + 1);
+ $p->html_header_before_title('Title: ');
+ $p->html_header_after_title(" - Apache Lucy Documentation\n\n<div>\n");
+ $p->html_footer("\n</div>\n");
+
+ $p->output_fh($out_file);
+ $p->parse_file("$base_dir/$filename");
+
+ close($out_file);
+
+ my $name_ext = NameExtractor->new;
+ $name_ext->parse_file("$base_dir/$filename");
+
+ my $html_filename = $filename;
+ $html_filename =~ s"(\.[^/.]*)?$".html";
+
+ return {
+ name => $name_ext->{extracted_name},
+ html_filename => $html_filename,
+ };
+}
+
+my %opts;
+getopt('v', \%opts);
+my $version = $opts{v}
+ or die("Usage: $0 -v version\n");
+
+my @pod_infos;
+
+for my $dir (qw(lib)) {
+ my $wanted = sub {
+ my $filename = $_;
+
+ return if -d $filename;
+
+ if ($filename =~ /\.pm$/) {
+ my $content = read_file($filename);
+ return unless $content =~ /^=head1/m;
+ }
+ elsif ($filename !~ /\.pod$/) {
+ return;
+ }
+
+ $filename =~ s"^$dir/"";
+
+ my $pod_info = pod2html($dir, $filename);
+
+ if (!defined($pod_info->{name})) {
+ print STDERR (
+ "Warning: Section NAME not found in ",
+ $pod_info->{html_filename}, "\n",
+ );
+ }
+ else {
+ push(@pod_infos, $pod_info);
+ }
+ };
+
+ find({ wanted => $wanted, no_chdir => 1 }, $dir);
+}
+
+my $index_filename = "html/index.mdtext";
+open(my $index_file, '>', $index_filename)
+ or die("$index_filename: $!");
+
+print $index_file (<<EOF);
+Title: Perl API documentation for Apache Lucy $version
+
+#### Perl API documentation for Apache Lucy $version
+
+EOF
+
+for my $pod_info (sort { $a->{name} cmp $b->{name} } @pod_infos) {
+ my $name = $pod_info->{name};
+ my $html_filename = $pod_info->{html_filename};
+
+ if ($name !~ /(\S+)\s+-\s+(.*)/) {
+ print STDERR ("Warning: Invalid NAME in $html_filename: $name\n");
+ next;
+ }
+
+ my ($class, $desc) = ($1, $2);
+
+ print $index_file (" - [$class]($html_filename) - $desc\n");
+}
+
+close($index_filename);
+