class Sitepress::AssetNodeMapper
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.
Attributes
asset_paths[R]
node[R]
Public Class Methods
new(path:, node:)
click to toggle source
# File lib/sitepress/asset_node_mapper.rb, line 11 def initialize(path:, node:) @asset_paths = AssetPaths.new(path: path) @node = node end
Public Instance Methods
map()
click to toggle source
Mounts the source files from the path to the given node.
# File lib/sitepress/asset_node_mapper.rb, line 17 def map asset_paths.each do |path| if path.directory? process_directory path else process_asset path end end end
Protected Instance Methods
process_asset(path)
click to toggle source
# File lib/sitepress/asset_node_mapper.rb, line 34 def process_asset(path) asset = Asset.new(path: path) node.add_child(asset.node_name).formats.add(format: asset.format, asset: asset) end
process_directory(path)
click to toggle source
# File lib/sitepress/asset_node_mapper.rb, line 29 def process_directory(path) node_name = File.basename path node_mapper path: path, node: node.add_child(node_name) end
Private Instance Methods
node_mapper(*args, **kwargs)
click to toggle source
# File lib/sitepress/asset_node_mapper.rb, line 41 def node_mapper(*args, **kwargs) self.class.new(*args, **kwargs).map end