Class: Middleman::Sitemap::Extensions::OnDisk
- Inherits:
-
Extension
- Object
- Extension
- Middleman::Sitemap::Extensions::OnDisk
show all
- Defined in:
- lib/middleman-core/sitemap/extensions/on_disk.rb
Constant Summary
Constants included
from Contracts
Contracts::PATH_MATCHER
Instance Attribute Summary
Attributes inherited from Extension
#app, #options
Instance Method Summary
collapse
Methods inherited from Extension
activated_extension, #add_exposed_to_context, #after_build, #after_configuration, #after_extension_activated, after_extension_activated, #before_build, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, option, resources
Methods included from Contracts
#Contract
Constructor Details
#initialize(app, config = {}, &block) ⇒ OnDisk
Returns a new instance of OnDisk.
10
11
12
13
14
15
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 10
def initialize(app, config={}, &block)
super
@file_paths_on_disk = Set.new
@waiting_for_ready = true
end
|
Instance Method Details
#before_configuration ⇒ Object
25
26
27
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 25
def before_configuration
app.files.on_change(:source, &method(:update_files))
end
|
#files_for_sitemap ⇒ Object
55
56
57
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 55
def files_for_sitemap
@app.files.by_type(:source).files.reject(&method(:ignored?))
end
|
#ignored?(file) ⇒ Boolean
30
31
32
33
34
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 30
def ignored?(file)
@app.config[:ignored_sitemap_matchers].any? do |_, callback|
callback.call(file, @app)
end
end
|
#manipulate_resource_list(resources) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 62
def manipulate_resource_list(resources)
resources + files_for_sitemap.map do |file|
::Middleman::Sitemap::Resource.new(
@app.sitemap,
@app.sitemap.file_to_path(file),
file
)
end
end
|
#ready ⇒ Object
17
18
19
20
21
22
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 17
def ready
@waiting_for_ready = false
app.sitemap.ensure_resource_list_updated!
end
|
#update_files(updated_files, removed_files) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/middleman-core/sitemap/extensions/on_disk.rb', line 40
def update_files(updated_files, removed_files)
return if (updated_files + removed_files).all?(&method(:ignored?))
@app.sitemap.rebuild_resource_list!(:touched_file)
@app.sitemap.ensure_resource_list_updated! unless @waiting_for_ready || @app.build?
end
|