Class: Mascot::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/mascot.rb

Overview

A collection of pages from a directory.

Constant Summary collapse

DEFAULT_GLOB =

Default file pattern to pick up in sitemap

"**/*.*".freeze
DEFAULT_ROOT_DIR =

Default root path for sitemap.

Pathname.new(".").freeze
DEFAULT_ROOT_REQUEST_PATH =

Default root request path

Pathname.new("/").freeze

Instance Method Summary collapse

Constructor Details

#initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH) ⇒ Sitemap

Returns a new instance of Sitemap.



65
66
67
68
# File 'lib/mascot.rb', line 65

def initialize(file_path: DEFAULT_ROOT_DIR, request_path: DEFAULT_ROOT_REQUEST_PATH)
  @file_path = Pathname.new(file_path)
  @request_path = Pathname.new(request_path)
end

Instance Method Details

#find_by_request_path(request_path) ⇒ Object

Find the page with a path.



78
79
80
# File 'lib/mascot.rb', line 78

def find_by_request_path(request_path)
  resources.find { |r| r.request_path == request_path }
end

#resources(glob = DEFAULT_GLOB) ⇒ Object

Lazy stream of resources.



71
72
73
74
75
# File 'lib/mascot.rb', line 71

def resources(glob = DEFAULT_GLOB)
  Dir[@file_path.join(glob)].lazy.map do |path|
    Resource.new request_path: request_path(path), file_path: path
  end
end