Class: Middleman::Sitemap::Extensions::Ignores::IgnoreManager

Inherits:
Object
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb

Overview

Class to handle managing ignores

Instance Method Summary (collapse)

Constructor Details

- (IgnoreManager) initialize(app)

A new instance of IgnoreManager



52
53
54
55
56
57
# File 'middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb', line 52

def initialize(app)
  @app = app

  # Array of callbacks which can ass ignored
  @ignored_callbacks = []
end

Instance Method Details

- (void) ignore(path = nil, &block)

This method returns an undefined value.

Ignore a path or add an ignore callback

Parameters:

  • path (String, Regexp) (defaults to: nil)

    Path glob expression, or path regex



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb', line 62

def ignore(path=nil, &block)
  original_callback_size = @ignored_callbacks.size

  if path.is_a? Regexp
    @ignored_callbacks << Proc.new {|p| p =~ path }
  elsif path.is_a? String
    path_clean = ::Middleman::Util.normalize_path(path)
    if path_clean.include?("*") # It's a glob
      @ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
    else
      # Add a specific-path ignore unless that path is already covered
      @ignored_callbacks << Proc.new {|p| p == path_clean } unless ignored?(path_clean)
    end
  elsif block_given?
    @ignored_callbacks << block
  end
end

- (Boolean) ignored?(path)

Whether a path is ignored

Parameters:

  • path (String)

Returns:

  • (Boolean)


83
84
85
86
# File 'middleman-core/lib/middleman-core/sitemap/extensions/ignores.rb', line 83

def ignored?(path)
  path_clean = ::Middleman::Util.normalize_path(path)
  @ignored_callbacks.any? { |b| b.call(path_clean) }
end