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 glob support to include,exclude option #743

Merged
merged 8 commits into from Jan 13, 2013
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/jekyll/site.rb
Expand Up @@ -318,15 +318,19 @@ def site_payload
# Returns the Array of filtered entries.
def filter_entries(entries)
entries.reject do |e|
unless self.include.include?(e)
unless glob_include?(self.include, e)
['.', '_', '#'].include?(e[0..0]) ||
e[-1..-1] == '~' ||
self.exclude.include?(e) ||
glob_include?(self.exclude, e) ||
File.symlink?(e)
end
end
end

def glob_include?(exps, e)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this should be a core extension instead of randomly in Jekyll. Jekyll#glob_include? just feels weirder to me than Array#glob_include? or something.

Copy link
Member

Choose a reason for hiding this comment

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

I must admin it was my thought as well.
I think it should be Array#glob_include?.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My choose is Enumerable#glob_include?

!(exps.index { |exp| File.fnmatch?(exp, e) }).nil?
Copy link
Member

Choose a reason for hiding this comment

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

It's better to use Enumerable#any? here:

exps.any? { |exp| File.fnmatch?(exp, e) }

end

# Get the implementation class for the given Converter.
#
# klass - The Class of the Converter to fetch.
Expand Down
8 changes: 4 additions & 4 deletions test/test_site.rb
Expand Up @@ -154,13 +154,13 @@ class TestSite < Test::Unit::TestCase
excludes = %w[README TODO]
files = %w[index.html site.css .htaccess]

@site.exclude = excludes
assert_equal files, @site.filter_entries(excludes + files)
@site.exclude = excludes + ["exclude*"]
assert_equal files, @site.filter_entries(excludes + files + ["excludeA"])
end

should "not filter entries within include" do
includes = %w[_index.html .htaccess]
files = %w[index.html _index.html .htaccess]
includes = %w[_index.html .htaccess include*]
files = %w[index.html _index.html .htaccess includeA]

@site.include = includes
assert_equal files, @site.filter_entries(files)
Expand Down