class Jekyll::EntryFilter
Constants
- SPECIAL_LEADING_CHARACTERS
Attributes
site[R]
Public Class Methods
new(site, base_directory = nil)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 10 def initialize(site, base_directory = nil) @site = site @base_directory = derive_base_directory( @site, base_directory.to_s.dup ) end
Public Instance Methods
backup?(entry)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 50 def backup?(entry) entry[-1..-1] == "~" end
base_directory()
click to toggle source
# File lib/jekyll/entry_filter.rb, line 17 def base_directory @base_directory.to_s end
derive_base_directory(site, base_dir)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 21 def derive_base_directory(site, base_dir) base_dir[site.source] = "" if base_dir.start_with?(site.source) base_dir end
excluded?(entry)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 54 def excluded?(entry) glob_include?(site.exclude, relative_to_source(entry)).tap do |excluded| if excluded Jekyll.logger.debug( "EntryFilter:", "excluded #{relative_to_source(entry)}" ) end end end
filter(entries)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 32 def filter(entries) entries.reject do |e| unless included?(e) special?(e) || backup?(e) || excluded?(e) || symlink?(e) end end end
glob_include?(enum, entry)
click to toggle source
– Check if an entry matches a specific pattern and return true,false. Returns true if path matches against any glob pattern. –
# File lib/jekyll/entry_filter.rb, line 89 def glob_include?(enum, entry) entry_path = Pathutil.new(site.in_source_dir).join(entry) enum.any? do |exp| # Users who send a Regexp knows what they want to # exclude, so let them send a Regexp to exclude files, # we will not bother caring if it works or not, it's # on them at this point. if exp.is_a?(Regexp) entry_path =~ exp else item = Pathutil.new(site.in_source_dir).join(exp) # If it's a directory they want to exclude, AKA # ends with a "/" then we will go on to check and # see if the entry falls within that path and # exclude it if that's the case. if entry.end_with?("/") entry_path.in_path?( item ) else File.fnmatch?(item, entry_path) || entry_path.to_path.start_with?( item ) end end end end
included?(entry)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 40 def included?(entry) glob_include?(site.include, entry) || glob_include?(site.include, File.basename(entry)) end
relative_to_source(entry)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 26 def relative_to_source(entry) File.join( base_directory, entry ) end
special?(entry)
click to toggle source
# File lib/jekyll/entry_filter.rb, line 45 def special?(entry) SPECIAL_LEADING_CHARACTERS.include?(entry[0..0]) || SPECIAL_LEADING_CHARACTERS.include?(File.basename(entry)[0..0]) end
symlink?(entry)
click to toggle source
– Check if a file is a symlink. NOTE: This can be converted to allowing even in safe,
since we use Pathutil#in_path? now.
–
# File lib/jekyll/entry_filter.rb, line 70 def symlink?(entry) site.safe && File.symlink?(entry) && symlink_outside_site_source?(entry) end
symlink_outside_site_source?(entry)
click to toggle source
– NOTE: Pathutil#in_path? gets the realpath. @param [<Anything>] entry the entry you want to validate. Check if a path is outside of our given root. –
# File lib/jekyll/entry_filter.rb, line 79 def symlink_outside_site_source?(entry) !Pathutil.new(entry).in_path?( site.in_source_dir ) end