Class: Middleman::Sitemap::Extensions::Ignores
- Defined in:
- lib/middleman-core/sitemap/extensions/ignores.rb
Overview
Class to handle managing ignores
Constant Summary
Constants included from Contracts
Instance Attribute Summary
Attributes inherited from Extension
Instance Method Summary collapse
- #create_ignore(path = nil, &block) ⇒ Object
- #ignored?(path) ⇒ Boolean
-
#initialize(app, config = {}, &block) ⇒ Ignores
constructor
A new instance of Ignores.
Methods inherited from Extension
activated_extension, #add_exposed_to_context, #after_build, #after_configuration, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, expose_to_application, expose_to_config, expose_to_template, helpers, #manipulate_resource_list, option, #ready, resources
Methods included from Contracts
Constructor Details
#initialize(app, config = {}, &block) ⇒ Ignores
Returns a new instance of Ignores.
14 15 16 17 18 19 20 21 |
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 14 def initialize(app, config={}, &block) super # Array of callbacks which can assign ignored @ignored_callbacks = Set.new @app.sitemap.define_singleton_method(:ignored?, &method(:ignored?)) end |
Instance Method Details
#create_ignore(path = nil, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 27 def create_ignore(path=nil, &block) if path.is_a? Regexp @ignored_callbacks << proc { |p| p =~ path } elsif path.is_a? String path_clean = ::Middleman::Util.normalize_path(path) if path_clean.include?('*') # It's a glob if defined? File::FNM_EXTGLOB @ignored_callbacks << proc { |p| File.fnmatch(path_clean, p, File::FNM_EXTGLOB) } else @ignored_callbacks << proc { |p| File.fnmatch(path_clean, p) } end else # Add a specific-path ignore unless that path is already covered return if ignored?(path_clean) @ignored_callbacks << proc { |p| p == path_clean } end elsif block_given? @ignored_callbacks << block end @app.sitemap.invalidate_resources_not_ignored_cache! end |
#ignored?(path) ⇒ Boolean
54 55 56 57 |
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 54 def ignored?(path) path_clean = ::Middleman::Util.normalize_path(path) @ignored_callbacks.any? { |b| b.call(path_clean) } end |