v6.0.0: expand EntryStore, test more, cache harder
This commit is something of a hairball, the result of evenings-and-weekends
hacking building up a set of changes that got out of hand in parallel.
If I had the energy to spare, I would break it apart into
semantically-related changes, but I don't - and I suppose all this crap
being rolled together is at least reflective of how the code was
written.
These changes are really half-finished, at best. Eventual goals:
- App::WRT shouldn't directly touch the filesystem
- App::WRT::EntryStore should model the entry archive completely
- App::WRT::Renderer should say what to write to the publication
directory
- This one's a maybe: Filesystem interaction should pass through
App::WRT::FileIO or something like it so that EntryStore and Renderer
can be more usefully tested, with mocked writes (maybe)
I do think this represents an inflection point in the long, silly life of
this program: It includes a handful of new tests, and a number of the
code changes were in turn easy to make because the test suite begins to
model the code in a useful way. It's less and less necessary to run wrt
against the p1k3.com archives to be sure that I haven't trashed something.
Breaking changes to note:
- Will no longer render HTML for nonexistent entries
- Months and years which are flatfiles or contain an index are handled
differently, albeit less brokenly
- EntryStore includes index files in its overall list of entries
(this seems to break less than I thought), which trickles out to
bin/wrt-ls
Overall changes herein:
- App::WRT::Date
- Move month_name() in here from App::WRT, add tests.
- App::WRT::EntryStore
- Hash file types for entries (directory or flatfile)
- Use keys of file type hash for complete list of entries.
- has_prop($entry, $property)
- is_dir($entry), is_file($entry), is_extant($entry)
- parent_of($entry)
- has_index($entry)
- Make EntryStore cache whether a file is a flatfile or a directory, as
well as its existence, in a single hash.
- Include index flatfiles in @source_files for use by has_index()
- Various tests.
- App::WRT::FileIO
- Still duplicates a bunch of shit from Util, so that needs sorted.
- App::WRT::Renderer
- Convert to a proper class.
- Add experimental FileIO class to use in Renderer (imperfect,
tricky, still thinking about this). The idea is to separate out the
concerns of reading and writing the filesystem.
- App::WRT
- Refactor display() and improve tests
- Use "@entries" instead of "@options" for clarity
- Handle entry names that might evaluate as false
- Test running display() without any params
- Rename expand_option() -> expand_alias(), refactor
- Use EntryStore::has_prop() to detect wrt-noexpand.prop
- year(), month(), entry() partially rewritten to use EntryStore
- year() should handle months which are a flatfile
- Refactor icon_markup() to use is_file() / is_dir() / is_extant(),
add tests.
- Add subtitle to feeds
- bin/wrt-ls is now a "modulino" with tests
- bin/display errors on non-existent entries
- Build.PL
- Remove bogus XML::Feed dependency
5 years ago v6.0.0: expand EntryStore, test more, cache harder
This commit is something of a hairball, the result of evenings-and-weekends
hacking building up a set of changes that got out of hand in parallel.
If I had the energy to spare, I would break it apart into
semantically-related changes, but I don't - and I suppose all this crap
being rolled together is at least reflective of how the code was
written.
These changes are really half-finished, at best. Eventual goals:
- App::WRT shouldn't directly touch the filesystem
- App::WRT::EntryStore should model the entry archive completely
- App::WRT::Renderer should say what to write to the publication
directory
- This one's a maybe: Filesystem interaction should pass through
App::WRT::FileIO or something like it so that EntryStore and Renderer
can be more usefully tested, with mocked writes (maybe)
I do think this represents an inflection point in the long, silly life of
this program: It includes a handful of new tests, and a number of the
code changes were in turn easy to make because the test suite begins to
model the code in a useful way. It's less and less necessary to run wrt
against the p1k3.com archives to be sure that I haven't trashed something.
Breaking changes to note:
- Will no longer render HTML for nonexistent entries
- Months and years which are flatfiles or contain an index are handled
differently, albeit less brokenly
- EntryStore includes index files in its overall list of entries
(this seems to break less than I thought), which trickles out to
bin/wrt-ls
Overall changes herein:
- App::WRT::Date
- Move month_name() in here from App::WRT, add tests.
- App::WRT::EntryStore
- Hash file types for entries (directory or flatfile)
- Use keys of file type hash for complete list of entries.
- has_prop($entry, $property)
- is_dir($entry), is_file($entry), is_extant($entry)
- parent_of($entry)
- has_index($entry)
- Make EntryStore cache whether a file is a flatfile or a directory, as
well as its existence, in a single hash.
- Include index flatfiles in @source_files for use by has_index()
- Various tests.
- App::WRT::FileIO
- Still duplicates a bunch of shit from Util, so that needs sorted.
- App::WRT::Renderer
- Convert to a proper class.
- Add experimental FileIO class to use in Renderer (imperfect,
tricky, still thinking about this). The idea is to separate out the
concerns of reading and writing the filesystem.
- App::WRT
- Refactor display() and improve tests
- Use "@entries" instead of "@options" for clarity
- Handle entry names that might evaluate as false
- Test running display() without any params
- Rename expand_option() -> expand_alias(), refactor
- Use EntryStore::has_prop() to detect wrt-noexpand.prop
- year(), month(), entry() partially rewritten to use EntryStore
- year() should handle months which are a flatfile
- Refactor icon_markup() to use is_file() / is_dir() / is_extant(),
add tests.
- Add subtitle to feeds
- bin/wrt-ls is now a "modulino" with tests
- bin/display errors on non-existent entries
- Build.PL
- Remove bogus XML::Feed dependency
5 years ago |
|
- #!/usr/bin/env perl
-
- =pod
-
- =head1 NAME
-
- wrt-display - print static HTML from wrt entries
-
- =head1 USAGE
-
- wrt display new # newest entries
- wrt display all # table of contents for all dated entries
- wrt display 2016/4/1 # a specific date
- wrt display 2016/4 # all entries for a specific month
- wrt display 2016/4 # summary of entries for a year
- wrt display fulltext # complete text of archive
- wrt display feed # Atom feed of most recent month's entries
-
- # Take list of entries to display from standard input:
- echo 2016/4/1 | wrt display --stdin
-
- # Specify a different config file:
- wrt display --config ./wrt.json ...
-
- # Display help:
- wrt display --help
-
- =head1 DESCRIPTION
-
- C<wrt-display> displays HTML for the given entry or entries in the current wrt
- repository to F<stdout>. Entries may be specified by date or name.
-
- =head2 Special Entries
-
- B<new> will return entries for the most recent month.
-
- B<feed> will return an Atom feed for the most recent month.
-
- B<all> will return a table-of-contents for all date-based entries.
-
- B<fulltext> will return the full content of all date-based entries in the
- archive.
-
- Months in the form of B<yyyy/mm> will return all entries for that month.
-
- Years in the form of B<yyyy> will return a summary of entries for the year.
-
- Detailed documentation can be found in the L<App::WRT> man page or at
- L<https://code.p1k3.com/gitea/brennen/wrt>.
-
- =head1 LICENSE
-
- wrt is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- =head1 AUTHOR
-
- Brennen Bearnes <code@p1k3.com>
-
- =cut
-
- use 5.10.0;
-
- use strict;
- use warnings;
- no warnings 'uninitialized';
-
- # use Data::Dumper;
- use App::WRT;
-
- use Carp;
- use Getopt::Long;
- use Pod::Usage;
-
- # Handle options, including help generated from the POD above. See:
- # - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options
- # - https://metacpan.org/pod/Pod::Usage
- # - http://michael.thegrebs.com/2014/06/08/Pod-Usage/
- my $from_stdin = 0;
- my $config_file = 'wrt.json';
- GetOptions(
- stdin => \$from_stdin,
- 'config=s' => \$config_file,
- help => sub { pod2usage(0) },
- ) or pod2usage(2);
-
- unless (-e $config_file) {
- croak "No wrt config file found. Tried: $config_file";
- }
-
- my $w = App::WRT::new_from_file($config_file);
-
- # With --stdin, take names of entries to display from standard input, one line
- # per name. Otherwise, take names from arguments.
- my @to_display = ();
- if ($from_stdin) {
- while (my $entry = <>) {
- chomp($entry);
- push @to_display, $entry;
- }
- } else {
- (@to_display) = @ARGV;
- }
-
- # TODO: Better error reporting strategy, print this on stderr:
- foreach my $entry (map { $w->expand_alias($_) } @to_display) {
- unless ($w->{entries}->is_extant($entry) || $entry eq $w->{feed_alias}) {
- say("No such entry: $entry");
- exit(1);
- }
- }
- print $w->display(@to_display);
- exit(0);
|