Including:
- children() - get immediate children of entry
- parent($entry) - get immediate parent of entry
- days_for($container) - get days in a month or year
- months_for($year) - get months contained in a year
- basename($entry) - get basename of an entry
These are used in App::WRT::year() and App::WRT::month(), replacing
some dir_list() invocations and at least somewhat simplifying the code.
These display helptext and current version of the application,
respectively.
`wrt -h` and `wrt --help` still work, as do a new `wrt --version` and
`wrt -v`. I think the subcommand forms are useful (and echo a growing
norm for this kind of interface), but the others should be discoverable
for users with traditional expectations. Both basic help and version
info should be readily available without much thought, which I think
justifies the repetition.
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
wrt-ls is a provisional interface to the tools in WRT::EntryStore. It
should do more, but work is needed that I'm not going to put in before
releasing v5.0.0.
This seems like a good point to call things stable for this major release.
I have a bunch of ideas that I'd like to implement for a v6, which might
well break the API and underlying data structures.
This is all pretty academic since no one else actually uses this thing.
Adds a couple of hashes in the App::WRT::EntryStore::new() constructor
which stash arrays of properties for each entry, and arrays of entries
for each property, as File::Find works its way through the $entry_dir.
Uses props_for() in App::WRT::entry_topic_list() instead of dir_list().
This is maybe a tiny performance gain, but also probably more hassle
than it's worth unless other features are going to be built on these
methods (or other code that calls dir_list() simplified).
This also moves a chunk of logic out of EntryStore::all() and into the
constructor, and directly accesses $self->{source_files} in a couple of
methods instead of tossing around copies of the array.
I'm kind of iffy on whether any of this is worth doing.
I never could quite figure out why non-ASCII characters were getting
badly munged in XML::Atom::SimpleFeed output. Using Encode::decode() on
the content of entries turns out to fix this, although it's probably the
tip of an iceberg.
- uses file_get_contents() for include processing
- adds cache_includes setting
- uses include_cache on wrt instance to stash file contents in memory
I didn't expect that this would be substantially faster than just letting
the kernel worry about it, but on a large set of files with includes in
the template, it shaves about 100ms off a render.
I'm not actually sure this is worth it.
- get_all_source_files() -> EntryStore::all()
- get_date_entries_by_depth() -> EntryStore::dates_by_depth()
- get_recent_entries_by_depth() -> EntryStore::recent_by_depth()
...plus some convenience methods for accessing recent or all years /
months / days, and a next($entry) / previous($entry) for indexing into the
date lists.
An instance of App::WRT::EntryStore is stashed on an App::WRT instance.
- give absolute paths to imgsize() so it chills out on Cwd::getcwd() calls
- rip out App::WRT::MethodSpit's convenience accessors and just access
elements of $self directly
- kill local_path()
- stop using a() in entry_markup()
- cache get_date_entries_by_depth() results
- swap out state vars for stashing things on $self in
get_all_source_files()
This gets rendering the whole p1k3 repo back down in the neighborhood of
2.1 seconds, which is a lot more tolerable than 5 or 6.
It also kinda technically breaks the API, maybe, so I guess this'll be a
v5.0.0 after a while.
All replaced with get_recent_entries_by_depth().
Replaces generate_month_lists with more generic generate_date_hashes(),
which now puts year, month, and day level entries in the prev/next hashes.
Strips previous links out of month() - these can live in templates now,
I guess, and work for year, month, and day.
Replaces get_all_day_entries() with get_date_entries_by_depth(). Adds
generate_month_lists() to stash %prev_months and %next_months (this can
probably be generalized a bunch).
Generalizes sortable_date_from_entry() to work with different levels of
date. Assumes that no component of the date is more than 4 digits, which
is not very future proof. (Though if this code is still running in the
year 10000, the future will have gone very differently than I expect it
to.)
month_before() now uses the %prev_months and %next_months hashes.
Removes fulltext(), because you can just call get_date_entries_by_depth(3).
Much slower than it probably needs to be.
Shuffles a bit of stuff out of App::WRT::Renderer into App::WRT, including
the method now called get_all_source_files() and a new one called
get_all_day_entries() that returns a sorted listed of days.
Uses state variables to cache the get_all_source_files() data, as well
as month_before() data (this was previously memoized inside a closure).
App::WRT::feed_print() now takes a list of entries instead of a month to
render the feed for.
App::WRT::feed_print_latest() gets a feed with most recent feed_length
entries.
The default was `$0?`, which I think was probably a holdover from this
being invoked as a CGI script. `$0` would give the name of the current
script, so you'd wind up with `display.cgi?2008` or what-have-you.
Adds a wrt-init kind of on the model of git init for starting a stub
directory with wrt.json, archives/, publish/, and templates/.
Also starts to tweak POD a bit.