Skip to content

Commit

Permalink
generate README tables from sources
Browse files Browse the repository at this point in the history
closes #10.
  • Loading branch information
dwarring committed Nov 11, 2023
1 parent ed46ff5 commit 95ab5ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
DocProj=pdf-raku.github.io
DocRepo=https://github.com/pdf-raku/$(DocProj)
DocLinker=../$(DocProj)/etc/resolve-links.raku
RefMaker=etc/make-quick-ref.raku
TEST_JOBS ?= 8

POD = $(shell find lib -name \*.rakumod|xargs grep -le '=begin')
Expand Down Expand Up @@ -32,10 +33,14 @@ $(MD): docs/%.md: lib/%.rakumod
docs/index.md : README.md
cp $< $@

doc-refs :
@raku -I . $(RefMaker) README.md > README.tmp;
@mv README.tmp README.md;

$(DocLinker) :
(cd .. && git clone $(DocRepo) $(DocProj))

Pod-To-Markdown-installed :
@raku -M Pod::To::Markdown -c

doc : previews $(DocLinker) Pod-To-Markdown-installed $(MD) docs/index.md
doc : previews $(DocLinker) Pod-To-Markdown-installed $(MD) docs/index.md doc-refs
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ been mined from the PDF 32000 specification, e.g. ISO_32000::Table_28-Entries_in
## Classes Quick Reference

Class | Types | Accessors | Methods | Description | ISO-32000 References
------|-------|-----------|---------|-------------|----------
-------- | -------- | -------- | -------- | -------- | --------
[PDF::Class](https://pdf-raku.github.io/PDF-Class-raku/PDF/Class) | dict | Encrypt, ID, Info, Prev, Root(catalog), Size | Blob, Pages, add-page, add-pages, art-box, ast, bleed, bleed-box, core-font, creator, crop-box, crypt, delete-page, encrypt, fields, fields-hash, id, insert-page, iterate-pages, media-box, open, page, page-count, pages, permitted, save-as, trim-box, update, use-font, version | PDF entry-point. either a trailer dict or an XRef stream | ISO_32000::Table_15-Entries_in_the_file_trailer_dictionary
PDF::AcroForm | dict | CO(calculation-order), DA(default-appearance), DR(default-resources), Fields, NeedAppearances, Q(quadding), SigFlags, XFA | fields, take-fields | AcroForm role - see PDF::Catalog - /AcroForm entry | ISO_32000::Table_218-Entries_in_the_interactive_form_dictionary
PDF::Action::GoTo | dict | D(destination), Next, S(subtype), Type(type) | | /Action Subtype - GoTo | ISO_32000::Table_199-Additional_entries_specific_to_a_go-to_action ISO_32000::Table_193-Entries_common_to_all_action_dictionaries
Expand Down Expand Up @@ -431,5 +431,3 @@ PDF::ViewerPreferences | dict | CenterWindow, Direction, DisplayDocTitle, Duplex
[PDF::XObject::PS](https://pdf-raku.github.io/PDF-Class-raku/PDF/XObject/PS) | stream | Level1, Subtype(subtype), Type(type) | | Postscript XObjects /Type XObject /Subtype PS See [PDF 32000 Section 8.8.2 PostScript XObjects] | ISO_32000::Table_88-Additional_Entries_Specific_to_a_PostScript_XObject_Dictionary

*(generated by `etc/make-quick-ref.pl`)*

*(generated by `etc/make-quick-ref.pl`)*
2 changes: 0 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,3 @@ PDF::ViewerPreferences | dict | CenterWindow, Direction, DisplayDocTitle, Duplex
[PDF::XObject::PS](https://pdf-raku.github.io/PDF-Class-raku/PDF/XObject/PS) | stream | Level1, Subtype(subtype), Type(type) | | Postscript XObjects /Type XObject /Subtype PS See [PDF 32000 Section 8.8.2 PostScript XObjects] | ISO_32000::Table_88-Additional_Entries_Specific_to_a_PostScript_XObject_Dictionary

*(generated by `etc/make-quick-ref.pl`)*

*(generated by `etc/make-quick-ref.pl`)*
34 changes: 21 additions & 13 deletions etc/make-quick-ref.raku
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ my Set $stream-accessors .= new: <Length Filter DecodeParms F FFilter FDecodePar

my %classes;

my $Anchor = "\n*(generated by `etc/make-quick-ref.pl`)*\n";

sub MAIN(Str:D $md-file, :$class) {
my @classes = $class || do {
scan-classes('lib'.IO);
%classes.keys
}
my $doc = $md-file.IO.slurp;
my @table = gather { gen-table(@classes) }
unshift @table, ('--------' xx 6) .join(' | ' );
unshift @table, ('Class', 'Types', 'Accessors', 'Methods', 'Description', 'ISO-32000 References').join: ' | ';
print $doc.subst(/^^[[\N+"|"\N+\n]+]$Anchor/, @table.join("\n") ~ "\n" ~ $Anchor);
}

sub scan-classes($path) {

for $path.dir.sort {
Expand All @@ -36,20 +50,17 @@ sub scan-classes($path) {
}
}

sub MAIN(:$class is copy) {
$class //= do {
scan-classes('lib'.IO);
%classes.keys
}
for $class.list.sort({ when 'PDF::Class' {'A'}; when 'PDF::Catalog' {'B'}; default {$_}}) -> $name {
my $class = (require ::($name));
sub gen-table(@classes) {
for @classes.sort({ when 'PDF::Class' {'A'}; when 'PDF::Catalog' {'B'}; default {$_}}) -> $class-name {
$*ERR.print: ".";
my $class = (require ::($class-name));

my $type = do given $class {
when PDF::COS::Array|PDF::COS::Tie::Array {'array'}
when PDF::COS::Stream|PDF::Content::XObject {'stream'}
when PDF::COS::Dict|PDF::COS::Tie::Hash {'dict'}
default {
warn "ignoring class: $name ({$type.perl})";
warn "ignoring class: $class-name ({$class-name.raku})";
next;
}
};
Expand All @@ -70,13 +81,10 @@ sub MAIN(:$class is copy) {
.grep(* $stream-accessors).sort;

my @methods = $class.^methods.map(*.name).grep({!%seen{$_}}).grep(* $std-methods).sort.unique;
my $ref = make-class-reference($name);
say "$ref | $type | {@accessors.join: ', '} | {@methods.join: ', '} | $doc | {@see-also.join: ' '}";
my $ref = make-class-reference($class-name);
take "$ref | $type | {@accessors.join: ', '} | {@methods.join: ', '} | $doc | {@see-also.join: ' '}";

}

say '';
say '*(generated by `etc/make-quick-ref.pl`)*';
}

sub make-class-reference($name) {
Expand Down

0 comments on commit 95ab5ef

Please sign in to comment.