Class: Sitepress::Site
- Inherits:
-
Object
- Object
- Sitepress::Site
- Extended by:
- Forwardable
- Defined in:
- lib/sitepress/site.rb
Overview
A collection of pages from a directory.
Constant Summary collapse
- DEFAULT_GLOB =
Default file pattern to pick up in site
"**/**".freeze
- DEFAULT_ROOT_PATH =
Default root_path for site.
Pathname.new(".").freeze
- DEFAULT_NODE_MAPPER =
Maps Rail-ish template files & structures into the site’s node tree.
AssetNodeMapper
Instance Attribute Summary collapse
-
#node_mapper ⇒ Object
Returns the value of attribute node_mapper.
-
#resources_pipeline ⇒ Object
An array of procs that manipulate the tree and resources from the Node returned by #root.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Instance Method Summary collapse
- #assets_path ⇒ Object
- #helpers_path ⇒ Object
-
#initialize(root_path: DEFAULT_ROOT_PATH) ⇒ Site
constructor
A new instance of Site.
-
#manipulate(&block) ⇒ Object
Quick and dirty way to manipulate resources in the site without creating classes that implement the #process_resources method.
- #models_path ⇒ Object
-
#pages_path ⇒ Object
Location of website pages.
- #reload! ⇒ Object
-
#resources ⇒ Object
Returns a list of all the resources within #root.
-
#root ⇒ Object
A tree representation of the resourecs wthin the site.
Constructor Details
#initialize(root_path: DEFAULT_ROOT_PATH) ⇒ Site
Returns a new instance of Site.
25 26 27 28 |
# 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 |
Instance Attribute Details
#node_mapper ⇒ Object
Returns the value of attribute node_mapper.
19 20 21 |
# File 'lib/sitepress/site.rb', line 19 def node_mapper @node_mapper end |
#resources_pipeline ⇒ Object
An array of procs that manipulate the tree and resources from the Node returned by #root.
106 107 108 |
# File 'lib/sitepress/site.rb', line 106 def resources_pipeline @resources_pipeline ||= ResourcesPipeline.new end |
#root_path ⇒ Object
Returns the value of attribute root_path.
17 18 19 |
# File 'lib/sitepress/site.rb', line 17 def root_path @root_path end |
Instance Method Details
#assets_path ⇒ Object
63 64 65 |
# File 'lib/sitepress/site.rb', line 63 def assets_path root_path.join("assets") end |
#helpers_path ⇒ Object
59 60 61 |
# File 'lib/sitepress/site.rb', line 59 def helpers_path root_path.join("helpers") end |
#manipulate(&block) ⇒ Object
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 “‘
100 101 102 |
# File 'lib/sitepress/site.rb', line 100 def manipulate(&block) resources_pipeline << Extensions::ProcManipulator.new(block) end |
#models_path ⇒ Object
67 68 69 |
# File 'lib/sitepress/site.rb', line 67 def models_path root_path.join("models") end |
#pages_path ⇒ Object
Location of website pages.
55 56 57 |
# File 'lib/sitepress/site.rb', line 55 def pages_path root_path.join("pages") end |
#reload! ⇒ Object
44 45 46 47 |
# File 'lib/sitepress/site.rb', line 44 def reload! @resources = @root = nil self end |
#resources ⇒ Object
Returns a list of all the resources within #root.
40 41 42 |
# File 'lib/sitepress/site.rb', line 40 def resources @resources ||= ResourceCollection.new(node: root, root_path: pages_path) end |
#root ⇒ Object
A tree representation of the resourecs wthin the site. The root is a node that’s processed by the ‘resources_pipeline`.
32 33 34 35 36 37 |
# 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 |