Class: Jekyll::EntryFilter
- Inherits:
-
Object
- Object
- Jekyll::EntryFilter
- Defined in:
- lib/jekyll/entry_filter.rb
Constant Summary collapse
- SPECIAL_LEADING_CHAR_REGEX =
%r!\A#{Regexp.union([".", "_", "#", "~"])}!o.freeze
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #backup?(entry) ⇒ Boolean
- #base_directory ⇒ Object
- #derive_base_directory(site, base_dir) ⇒ Object
- #excluded?(entry) ⇒ Boolean
- #filter(entries) ⇒ Object
-
#glob_include?(enumerator, entry) ⇒ Boolean
Check if an entry matches a specific pattern.
- #included?(entry) ⇒ Boolean
-
#initialize(site, base_directory = nil) ⇒ EntryFilter
constructor
A new instance of EntryFilter.
- #relative_to_source(entry) ⇒ Object
- #special?(entry) ⇒ Boolean
-
#symlink?(entry) ⇒ Boolean
– Check if a file is a symlink.
-
#symlink_outside_site_source?(entry) ⇒ Boolean
– NOTE: Pathutil#in_path? gets the realpath.
Constructor Details
#initialize(site, base_directory = nil) ⇒ EntryFilter
Returns a new instance of EntryFilter.
8 9 10 11 12 13 |
# File 'lib/jekyll/entry_filter.rb', line 8 def initialize(site, base_directory = nil) @site = site @base_directory = derive_base_directory( @site, base_directory.to_s.dup ) end |
Instance Attribute Details
#site ⇒ Object (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
55 56 57 |
# File 'lib/jekyll/entry_filter.rb', line 55 def backup?(entry) entry.end_with?("~") end |
#base_directory ⇒ Object
15 16 17 |
# File 'lib/jekyll/entry_filter.rb', line 15 def base_directory @base_directory.to_s end |
#derive_base_directory(site, base_dir) ⇒ Object
19 20 21 22 |
# File 'lib/jekyll/entry_filter.rb', line 19 def derive_base_directory(site, base_dir) base_dir[site.source] = "" if base_dir.start_with?(site.source) base_dir end |
#excluded?(entry) ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jekyll/entry_filter.rb', line 59 def excluded?(entry) glob_include?(site.exclude - site.include, relative_to_source(entry)).tap do |excluded| if excluded Jekyll.logger.debug( "EntryFilter:", "excluded #{relative_to_source(entry)}" ) end end end |
#filter(entries) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jekyll/entry_filter.rb', line 30 def filter(entries) entries.reject do |e| # Reject this entry if it is just a "dot" representation. # e.g.: '.', '..', '_movies/.', 'music/..', etc next true if e.end_with?(".") # Reject this entry if it is a symlink. next true if symlink?(e) # Do not reject this entry if it is included. next false if included?(e) # Reject this entry if it is special, a backup file, or excluded. special?(e) || backup?(e) || excluded?(e) end end |
#glob_include?(enumerator, entry) ⇒ Boolean
Check if an entry matches a specific pattern. Returns true if path matches against any glob pattern, else false.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/jekyll/entry_filter.rb', line 92 def glob_include?(enumerator, entry) entry_with_source = PathManager.join(site.source, entry) enumerator.any? do |pattern| case pattern when String pattern_with_source = PathManager.join(site.source, pattern) File.fnmatch?(pattern_with_source, entry_with_source) || entry_with_source.start_with?(pattern_with_source) when Regexp pattern.match?(entry_with_source) else false end end end |
#included?(entry) ⇒ Boolean
45 46 47 48 |
# File 'lib/jekyll/entry_filter.rb', line 45 def included?(entry) glob_include?(site.include, entry) || glob_include?(site.include, File.basename(entry)) end |
#relative_to_source(entry) ⇒ Object
24 25 26 27 28 |
# File 'lib/jekyll/entry_filter.rb', line 24 def relative_to_source(entry) File.join( base_directory, entry ) end |
#special?(entry) ⇒ Boolean
50 51 52 53 |
# File 'lib/jekyll/entry_filter.rb', line 50 def special?(entry) SPECIAL_LEADING_CHAR_REGEX.match?(entry) || SPECIAL_LEADING_CHAR_REGEX.match?(File.basename(entry)) end |
#symlink?(entry) ⇒ Boolean
– Check if a file is a symlink. NOTE: This can be converted to allowing even in safe,
since we use Pathutil#in_path? now.
–
75 76 77 |
# File 'lib/jekyll/entry_filter.rb', line 75 def symlink?(entry) site.safe && File.symlink?(entry) && symlink_outside_site_source?(entry) end |
#symlink_outside_site_source?(entry) ⇒ Boolean
– NOTE: Pathutil#in_path? gets the realpath. Check if a path is outside of our given root. –
84 85 86 87 88 |
# File 'lib/jekyll/entry_filter.rb', line 84 def symlink_outside_site_source?(entry) !Pathutil.new(entry).in_path?( site.in_source_dir ) end |