lib/bunch.rb in bunch-0.0.10 vs lib/bunch.rb in bunch-0.0.11
- old
+ new
@@ -19,10 +19,11 @@
require 'bunch/abstract_node'
require 'bunch/directory_node'
require 'bunch/file_node'
require 'bunch/coffee_node'
require 'bunch/sass_node'
+require 'bunch/null_node'
module Bunch
class CompileError < StandardError
def initialize(exception, filename)
@exception = exception
@@ -34,16 +35,28 @@
end
end
end
class << Bunch
+ IGNORED_PATTERNS = []
+
+ def load_ignores(path='.')
+ fn = File.join(path, '.bunchignore')
+ if File.exist?(fn)
+ IGNORED_PATTERNS.concat File.readlines(fn).map { |f| Regexp.new(f.chomp) }
+ IGNORED_PATTERNS.uniq!
+ end
+ end
+
def content_for(path)
tree_for(normalized_path(path)).content
end
def tree_for(path)
case
+ when IGNORED_PATTERNS.any? { |p| File.basename(path) =~ p }
+ Bunch::NullNode.new(path)
when File.directory?(path)
Bunch::DirectoryNode.new(path)
when path =~ /\.coffee$/
Bunch::CoffeeNode.new(path)
when path =~ /\.s(a|c)ss$/
@@ -67,5 +80,7 @@
else
raise Errno::ENOENT, path.to_s
end
end
end
+
+Bunch.load_ignores