Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to have static assets #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danbarbarito
Copy link

This PR adds the ability to have static assets. Now after running plerdall, all of the files in the assets/ directory will copied to the docroot/ directory.

@jmacdotorg
Copy link
Owner

Thanks for this! It will be a little bit before I can give it a proper examination, but I look forward to it.

@danbarbarito
Copy link
Author

No problem! Perl is far from my strongest language so I'm sure you will find many things that can be refactored 😆

@jmacdotorg
Copy link
Owner

At a glance, this code seems very well engineered!

Before I get nitpicky though, a question: What is the advantage of this approach versus placing asset files directly into the docroot as a separate step? I don't ask this rhetorically, I'm honestly curious about advantages here I may be overlooking.

In my years of using Plerd so far, when I (for example) prepare a post with an image attached, I will move the image into the docroot first, and then I'll publish the post. If I understand correctly, with this change in place, I'd instead move the image into a pre-declared asset directory, and then publish the post (at which point Plerd would copy it into the docroot for me). Is that correct?

@danbarbarito
Copy link
Author

@jmacdotorg Sorry for the late reply, I did not see this notification! Your assumption is correct. The only reason I made this change is because I would prefer to keep the docroot out of version control, but my static files in version control. This change allows you to keep your static files separate from your generated files.

@jmacdotorg
Copy link
Owner

Ugh, my turn to apologize... I didn't get the notification to your reply back in January. Dunno what's up with all those dropped telegrams...

Anyway, will ponder, in context of some re-thinking I hope to give to Plerd presently.

Copy link
Owner

@jmacdotorg jmacdotorg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good feature! I think that the logic can be simplified a bit by way of a different choice in CPAN modules; see the inline comments.

Also, I'd like to see the addition of test(s) to basic.t that put a file or two in an asset directory, and then confirm that they got copied over.

Please let me know if you'd like more advice or assistance with any of this!

use DateTime;
use DateTime::Format::W3CDTF;
use URI;
use File::Find;
use File::Copy;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on the right track, but I suspect that File::Copy::Recursive might be more appropriate. (See below.)

(This would also obviate the requirements of File::Path and File::Find.)

sub publish_assets {
my $self = shift;

find(sub { $self->_publish_asset($File::Find::name) if -f }, $self->asset_directory);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My sense is that this is more complicated that it needs to be.

If I understand your intention right, what should happen here is that every file inside the asset directory (if present) should get copied into the docroot. Correct?

If so, then rather than this call to a hand-rolled file-copying method (_publish_asset), how about making use of File::Copy::Recursive's dircopy method? It seems to me that one call to that would take care of everything.

@@ -325,6 +349,34 @@ sub _publish_feed {
) || $self->_throw_template_exception( $self->$template_file_method );
}

sub _publish_asset {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my hunch above is correct, then this method becomes unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants