Class: Jekyll::EntryFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/entry_filter.rb

Constant Summary collapse

SPECIAL_LEADING_CHARACTERS =
['.', '_', '#'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, base_directory = nil) ⇒ EntryFilter

Returns a new instance of EntryFilter.



7
8
9
10
# File 'lib/jekyll/entry_filter.rb', line 7

def initialize(site, base_directory = nil)
  @site = site
  @base_directory = derive_base_directory(@site, base_directory.to_s.dup)
end

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'lib/jekyll/entry_filter.rb', line 5

def site
  @site
end

Instance Method Details

#backup?(entry) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/jekyll/entry_filter.rb', line 44

def backup?(entry)
  entry[-1..-1] == '~'
end

#base_directoryObject



12
13
14
# File 'lib/jekyll/entry_filter.rb', line 12

def base_directory
  @base_directory.to_s
end

#derive_base_directory(site, base_dir) ⇒ Object



16
17
18
19
20
21
# File 'lib/jekyll/entry_filter.rb', line 16

def derive_base_directory(site, base_dir)
  if base_dir.start_with?(site.source)
    base_dir[site.source] = ""
  end
  base_dir
end

#ensure_leading_slash(path) ⇒ Object



58
59
60
# File 'lib/jekyll/entry_filter.rb', line 58

def ensure_leading_slash(path)
  path[0..0] == "/" ? path : "/#{path}"
end

#excluded?(entry) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/jekyll/entry_filter.rb', line 48

def excluded?(entry)
  excluded = glob_include?(site.exclude, relative_to_source(entry))
  Jekyll.logger.debug "EntryFilter:", "excluded #{relative_to_source(entry)}" if excluded
  excluded
end

#filter(entries) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/jekyll/entry_filter.rb', line 27

def filter(entries)
  entries.reject do |e|
    unless included?(e)
      special?(e) || backup?(e) || excluded?(e) || symlink?(e)
    end
  end
end

#glob_include?(enum, e) ⇒ Boolean

Returns true if path matches against any glob pattern. Look for more detail about glob pattern in method File::fnmatch.

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/jekyll/entry_filter.rb', line 64

def glob_include?(enum, e)
  entry = ensure_leading_slash(e)
  enum.any? do |exp|
    item = ensure_leading_slash(exp)
    File.fnmatch?(item, entry) || entry.start_with?(item)
  end
end

#included?(entry) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/jekyll/entry_filter.rb', line 35

def included?(entry)
  glob_include?(site.include, entry)
end

#relative_to_source(entry) ⇒ Object



23
24
25
# File 'lib/jekyll/entry_filter.rb', line 23

def relative_to_source(entry)
  File.join(base_directory, entry)
end

#special?(entry) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/jekyll/entry_filter.rb', line 39

def special?(entry)
  SPECIAL_LEADING_CHARACTERS.include?(entry[0..0]) ||
    SPECIAL_LEADING_CHARACTERS.include?(File.basename(entry)[0..0])
end

#symlink?(entry) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/jekyll/entry_filter.rb', line 54

def symlink?(entry)
  File.symlink?(entry) && site.safe
end