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_ROOT_PATH =
Default root_path for site.
Pathname.new(".").freeze
Instance Attribute Summary collapse
-
#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
-
#asset_node_mapper(root_node) ⇒ Object
Maps a path of directories and files into the root node.
-
#assets_path ⇒ Object
Location of rails assets.
- #assets_path=(path) ⇒ Object
-
#helpers_path ⇒ Object
Location of helper files.
- #helpers_path=(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
Location of pages models.
- #models_path=(path) ⇒ Object
-
#pages_path ⇒ Object
Location of website pages.
- #pages_path=(path) ⇒ Object
- #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.
19 20 21 |
# File 'lib/sitepress/site.rb', line 19 def initialize(root_path: DEFAULT_ROOT_PATH) self.root_path = root_path end |
Instance Attribute Details
#resources_pipeline ⇒ Object
An array of procs that manipulate the tree and resources from the Node returned by #root.
127 128 129 |
# File 'lib/sitepress/site.rb', line 127 def resources_pipeline @resources_pipeline ||= ResourcesPipeline.new end |
#root_path ⇒ Object
Returns the value of attribute root_path.
11 12 13 |
# File 'lib/sitepress/site.rb', line 11 def root_path @root_path end |
Instance Method Details
#asset_node_mapper(root_node) ⇒ Object
Maps a path of directories and files into the root node.
33 34 35 |
# File 'lib/sitepress/site.rb', line 33 def asset_node_mapper(root_node) AssetNodeMapper.new(path: pages_path, node: root_node) end |
#assets_path ⇒ Object
Location of rails assets
71 72 73 |
# File 'lib/sitepress/site.rb', line 71 def assets_path @assets_path ||= root_path.join("assets") end |
#assets_path=(path) ⇒ Object
75 76 77 |
# File 'lib/sitepress/site.rb', line 75 def assets_path=(path) @assets_path = Pathname.new(path) end |
#helpers_path ⇒ Object
Location of helper files.
62 63 64 |
# File 'lib/sitepress/site.rb', line 62 def helpers_path @helpers_path ||= root_path.join("helpers") end |
#helpers_path=(path) ⇒ Object
66 67 68 |
# File 'lib/sitepress/site.rb', line 66 def helpers_path=(path) @helpers_path = Pathname.new(path) 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 |root|
root.get("videos").each do |resource|
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 |root|
root.get("blog").each do |post|
post.move_to root
end
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 “‘
121 122 123 |
# File 'lib/sitepress/site.rb', line 121 def manipulate(&block) resources_pipeline << Extensions::ProcManipulator.new(block) end |
#models_path ⇒ Object
Location of pages models.
80 81 82 |
# File 'lib/sitepress/site.rb', line 80 def models_path @models_path ||= root_path.join("models") end |
#models_path=(path) ⇒ Object
84 85 86 |
# File 'lib/sitepress/site.rb', line 84 def models_path=(path) @models_path = Pathname.new(path) end |
#pages_path ⇒ Object
Location of website pages.
53 54 55 |
# File 'lib/sitepress/site.rb', line 53 def pages_path @pages_path ||= root_path.join("pages") end |
#pages_path=(path) ⇒ Object
57 58 59 |
# File 'lib/sitepress/site.rb', line 57 def pages_path=(path) @pages_path = Pathname.new(path) end |
#reload! ⇒ Object
42 43 44 45 |
# File 'lib/sitepress/site.rb', line 42 def reload! @resources = @root = nil self end |
#resources ⇒ Object
Returns a list of all the resources within #root.
38 39 40 |
# File 'lib/sitepress/site.rb', line 38 def resources @resources ||= ResourceIndexer.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`.
25 26 27 28 29 30 |
# File 'lib/sitepress/site.rb', line 25 def root @root ||= Node.new.tap do |root| asset_node_mapper(root).map resources_pipeline.process root end end |