class Sitepress::Site

A collection of pages from a directory.

Constants

DEFAULT_GLOB

Default file pattern to pick up in site

DEFAULT_NODE_MAPPER

Maps a tree of Directory and Asset objects in a a tree of nodes that format the navigational structure of a website. You can override this this in a site to deal with different file systems. For example, Notion has a completely different file structure for its content than Rails, so we could extend this class to properly map those differences into a tree of nodes.

DEFAULT_ROOT_PATH

Default root_path for site.

Attributes

node_mapper[RW]
resources_pipeline[W]
root_path[R]

Public Class Methods

new(root_path: DEFAULT_ROOT_PATH) click to toggle source
# File lib/sitepress/site.rb, line 25
def initialize(root_path: DEFAULT_ROOT_PATH)
  self.root_path = root_path
  self.node_mapper = DEFAULT_NODE_MAPPER
end

Public Instance Methods

assets_path() click to toggle source
# File lib/sitepress/site.rb, line 63
def assets_path
  root_path.join("assets")
end
helpers_path() click to toggle source
# File lib/sitepress/site.rb, line 59
def helpers_path
  root_path.join("helpers")
end
manipulate(&block) click to toggle source

Quick and dirty way to manipulate resources in the site without creating classes that implement the process_resources method.

A common example may be adding data to a resource if it begins with a certain path:

“`ruby Sitepress.site.manipulate do |resource, root|

if resource.request_path.start_with? "/videos/"
  resource.data["layout"] = "video"
end

end “`

A more complex, contrived example that sets index.html as the root node in the site:

“`ruby Sitepress.site.manipulate do |resource, root|

if resource.request_path == "/index"
  # Remove the HTML format of index from the current resource level
  # so we can level it up.
  node = resource.node
  node.formats.remove ".html"
  node.remove
  root.add path: "/", asset: resource.asset # Now we can get to this from `/`.
end

end “`

# File lib/sitepress/site.rb, line 96
def manipulate(&block)
  resources_pipeline << Extensions::ProcManipulator.new(block)
end
pages_path() click to toggle source

Location of website pages.

# File lib/sitepress/site.rb, line 55
def pages_path
  root_path.join("pages")
end
reload!() click to toggle source
# File lib/sitepress/site.rb, line 44
def reload!
  @resources = @root = nil
  self
end
resources() click to toggle source

Returns a list of all the resources within root.

# File lib/sitepress/site.rb, line 40
def resources
  @resources ||= ResourceCollection.new(node: root, root_path: pages_path)
end
resources_pipeline() click to toggle source

An array of procs that manipulate the tree and resources from the Node returned by root.

# File lib/sitepress/site.rb, line 102
def resources_pipeline
  @resources_pipeline ||= ResourcesPipeline.new
end
root() click to toggle source

A tree representation of the resourecs wthin the site. The root is a node that's processed by the `resources_pipeline`.

# File lib/sitepress/site.rb, line 32
def root
  @root ||= Node.new.tap do |node|
    node_mapper.new(path: pages_path, node: node).map
    resources_pipeline.process node
  end
end
root_path=(path) click to toggle source

Root path to website project. Contains helpers, pages, and more.

# File lib/sitepress/site.rb, line 50
def root_path=(path)
  @root_path = Pathname.new(path)
end