class Middleman::Tansu::Drawer

Drawer search empty(index.html.* isn’t exist) directory in app.config.source

example: ary = Drawer.new(app, options, exclude_path).empty

Public Class Methods

new(app, options, exclude_path = []) click to toggle source
# File lib/middleman-tansu/drawer.rb, line 9
def initialize(app, options, exclude_path = [])
  @config       = app.config
  @options      = options
  @dirs         = ['/']
  @exclude_path = exclude(exclude_path)
end

Public Instance Methods

empty() click to toggle source
# File lib/middleman-tansu/drawer.rb, line 16
def empty
  search_directory(@config.source)
  empty = []
  @dirs.each do |dir|
    glob_path = File.join(@config.source, dir,
                          "#{@config.tansu[:default_document].strip}*")
    empty.push(dir) if Dir.glob(glob_path).length == 0
  end
  empty
end
exclude(path) click to toggle source
# File lib/middleman-tansu/drawer.rb, line 37
def exclude(path)
  default = [
    @config.images_dir,
    @config.js_dir,
    @config.css_dir,
    @config.layouts_dir,
    @options.templates_dir
  ]
  default | path
end
exclude?(path) click to toggle source
# File lib/middleman-tansu/drawer.rb, line 48
def exclude?(path)
  regex = Regexp.new("^#{@config.source}/(#{@exclude_path.join('|')})")
  regex =~ path
end
search_directory(dir) click to toggle source
# File lib/middleman-tansu/drawer.rb, line 27
def search_directory(dir)
  regex = Regexp.new('^' + @config.source)
  Dir.glob(File.join(dir, '*')).each do |path|
    if File.ftype(path) == 'directory' && !exclude?(path)
      @dirs.push(path.gsub(regex, ''))
      search_directory(path)
    end
  end
end