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.
18 19 20 |
# File 'lib/sitepress/site.rb', line 18 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.
126 127 128 |
# File 'lib/sitepress/site.rb', line 126 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.
32 33 34 |
# File 'lib/sitepress/site.rb', line 32 def asset_node_mapper(root_node) AssetNodeMapper.new(path: pages_path, node: root_node) end |
#assets_path ⇒ Object
Location of rails assets
70 71 72 |
# File 'lib/sitepress/site.rb', line 70 def assets_path @assets_path ||= root_path.join("assets") end |
#assets_path=(path) ⇒ Object
74 75 76 |
# File 'lib/sitepress/site.rb', line 74 def assets_path=(path) @assets_path = Pathname.new(path) end |
#helpers_path ⇒ Object
Location of helper files.
61 62 63 |
# File 'lib/sitepress/site.rb', line 61 def helpers_path @helpers_path ||= root_path.join("helpers") end |
#helpers_path=(path) ⇒ Object
65 66 67 |
# File 'lib/sitepress/site.rb', line 65 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 “‘
120 121 122 |
# File 'lib/sitepress/site.rb', line 120 def manipulate(&block) resources_pipeline << Extensions::ProcManipulator.new(block) end |
#models_path ⇒ Object
Location of pages models.
79 80 81 |
# File 'lib/sitepress/site.rb', line 79 def models_path @models_path ||= root_path.join("models") end |
#models_path=(path) ⇒ Object
83 84 85 |
# File 'lib/sitepress/site.rb', line 83 def models_path=(path) @models_path = Pathname.new(path) end |
#pages_path ⇒ Object
Location of website pages.
52 53 54 |
# File 'lib/sitepress/site.rb', line 52 def pages_path @pages_path ||= root_path.join("pages") end |
#pages_path=(path) ⇒ Object
56 57 58 |
# File 'lib/sitepress/site.rb', line 56 def pages_path=(path) @pages_path = Pathname.new(path) end |
#reload! ⇒ Object
41 42 43 44 |
# File 'lib/sitepress/site.rb', line 41 def reload! @resources = @root = nil self end |
#resources ⇒ Object
Returns a list of all the resources within #root.
37 38 39 |
# File 'lib/sitepress/site.rb', line 37 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`.
24 25 26 27 28 29 |
# File 'lib/sitepress/site.rb', line 24 def root @root ||= Node.new.tap do |root| asset_node_mapper(root).map resources_pipeline.process root end end |