Class: Middleman::Tansu::Drawer

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-tansu/drawer.rb

Overview

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

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options, exclude_path = []) ⇒ Drawer



9
10
11
12
13
14
# 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

Instance Method Details

#emptyObject



16
17
18
19
20
21
22
23
24
25
# 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) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Boolean



48
49
50
51
# 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) ⇒ Object



27
28
29
30
31
32
33
34
35
# 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