mythmon / wok

A static website generator - Toss some content, templates, and media in a pan and fry it up!
http://wok.mythmon.com
Other
113 stars 46 forks source link

support new config option ignore_files for issue #138 #139

Closed matt-garman closed 8 years ago

matt-garman commented 9 years ago

I created Issue #138, "Feature request - ignore pattern config item". I thought I'd take a stab at implementing this. These changes represent "works for me" status. :) The idea is a new config parameter is introduced, "ignore_files", which is a list. By default, this list is empty, which retains original behavior. But in my case, I put this in my config file:

ignore_files = [ '*~' ]

This, along with the corresponding code changes, allows Wok to ignore files that match that glob pattern. Those are backup files created by my editor (vim). Without this patch, I was basically doing a "find ./ -name "*~" -delete" before invoking Wok, else I would get this error for templates:

ERROR:root:Ambiguous template found. There are two files that match "default.*". Aborting.

and this for content files:

WARNING:root:No parser found for my_content.rst~. Using default renderer.

This is my first time using GitHub for anything other than a simple clone, please go easy on me!

edunham commented 9 years ago

:+1: Thank you for implementing this so quickly! My only nitpick before merge is that I'd like you to add a test for the new feature. To do this, just add some ignores to https://github.com/mythmon/wok/blob/master/test_site/config using your new syntax, and also commit a file into the test site which will be ignored by the rule.

When you push the commit with the tests to the master branch of your fork of this repo, it'll show up here in the PR.

matt-garman commented 9 years ago

I added the test cases, and updated the config file. Note I created the test to-be-ignored files in the format "filename.ext_ignore", because checking in vim tilde files just felt wrong. :)

I also made the suggested stylistic change. However, in wok/jinja.py, it is already doing like this:

import glob
# ...
glob.glob("whatever")

So I followed suit with fnmatch, and continue to use it explicitly as fnmatch.fnmatch().

Edit: I suppose it goes without saying, but please let me know if you guys think anything else needs tweaked. Thanks!