Module: Middleman::Sitemap::Extensions::Traversal
- Included in:
- Resource
- Defined in:
- middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb
Instance Method Summary (collapse)
-
- (Array<Middleman::Sitemap::Resource>) children
This resource's child resources.
-
- (Boolean) directory_index?
Whether this resource either a directory index, or has the same name as an existing directory in the source.
-
- (Boolean) eponymous_directory?
Whether the resource has the same name as a directory in the source (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true).
-
- (String) eponymous_directory_path
The path for this resource if it were a directory, and not a file (e.g., for 'gallery.html' this would return 'gallery/').
-
- (Middleman::Sitemap::Resource?) parent
This resource's parent resource.
-
- (Array<Middleman::Sitemap::Resource>) siblings
This resource's sibling resources.
Instance Method Details
- (Array<Middleman::Sitemap::Resource>) children
This resource's child resources
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 26 def children return [] unless directory_index? if eponymous_directory? base_path = eponymous_directory_path prefix = %r|^#{base_path.sub("/", "\\/")}| else base_path = path.sub("#{app.index_file}", "") prefix = %r|^#{base_path.sub("/", "\\/")}| end store.resources.select do |sub_resource| if sub_resource.path == self.path || sub_resource.path !~ prefix false else inner_path = sub_resource.path.sub(prefix, "") parts = inner_path.split("/") if parts.length == 1 true elsif parts.length == 2 parts.last == app.index_file else false end end end end |
- (Boolean) directory_index?
Whether this resource either a directory index, or has the same name as an existing directory in the source
63 64 65 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 63 def directory_index? path.include?(app.index_file) || path =~ /\/$/ || eponymous_directory? end |
- (Boolean) eponymous_directory?
Whether the resource has the same name as a directory in the source (e.g., if the resource is named 'gallery.html' and a path exists named 'gallery/', this would return true)
70 71 72 73 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 70 def eponymous_directory? full_path = File.join(app.source_dir, eponymous_directory_path) !!(File.exists?(full_path) && File.directory?(full_path)) end |
- (String) eponymous_directory_path
The path for this resource if it were a directory, and not a file (e.g., for 'gallery.html' this would return 'gallery/')
78 79 80 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 78 def eponymous_directory_path path.sub(ext, '/').sub(/\/$/, "") + "/" end |
- (Middleman::Sitemap::Resource?) parent
This resource's parent resource
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 10 def parent parts = path.split("/") parts.pop if path.include?(app.index_file) return nil if parts.length < 1 parts.pop parts << app.index_file parent_path = "/" + parts.join("/") store.find_resource_by_destination_path(parent_path) end |
- (Array<Middleman::Sitemap::Resource>) siblings
This resource's sibling resources
56 57 58 59 |
# File 'middleman-core/lib/middleman-core/sitemap/extensions/traversal.rb', line 56 def siblings return [] unless parent parent.children.reject { |p| p == self } end |