Class: Mascot::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/mascot/sitemap.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_PATH =

Default root path for sitemap.

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

Default root request path

Pathname.new("/").freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: DEFAULT_ROOT_PATH, request_path: DEFAULT_ROOT_REQUEST_PATH) ⇒ Sitemap

Returns a new instance of Sitemap.



15
16
17
18
19
# File 'lib/mascot/sitemap.rb', line 15

def initialize(root: DEFAULT_ROOT_PATH, request_path: DEFAULT_ROOT_REQUEST_PATH)
  self.root = root
  self.request_path = request_path
  @extensions = []
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



13
14
15
# File 'lib/mascot/sitemap.rb', line 13

def extensions
  @extensions
end

#request_pathObject

Returns the value of attribute request_path.



13
14
15
# File 'lib/mascot/sitemap.rb', line 13

def request_path
  @request_path
end

#rootObject

Returns the value of attribute root.



13
14
15
# File 'lib/mascot/sitemap.rb', line 13

def root
  @root
end

Instance Method Details

#assets(glob = DEFAULT_GLOB) ⇒ Object

Lazy stream of files that will be rendered by resources.



22
23
24
25
26
# File 'lib/mascot/sitemap.rb', line 22

def assets(glob = DEFAULT_GLOB)
  safe_root.glob(root.join(glob)).select(&File.method(:file?)).lazy.map do |path|
    Asset.new(path: path)
  end
end

#get(request_path) ⇒ Object

Find the page with a path.



37
38
39
# File 'lib/mascot/sitemap.rb', line 37

def get(request_path)
  resources.get(request_path)
end

#resourcesObject

Returns a list of resources.



29
30
31
32
33
34
# File 'lib/mascot/sitemap.rb', line 29

def resources
  Resources.new(root_file_path: root).tap do |resources|
    assets.each { |a| resources.add_asset a }
    process_resources resources
  end
end