Class: Sitepress::AssetNodeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/sitepress/asset_node_mapper.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, node:) ⇒ AssetNodeMapper

Returns a new instance of AssetNodeMapper.



11
12
13
14
# File 'lib/sitepress/asset_node_mapper.rb', line 11

def initialize(path:, node:)
  @asset_paths = AssetPaths.new(path: path)
  @node = node
end

Instance Attribute Details

#asset_pathsObject (readonly)

Returns the value of attribute asset_paths.



9
10
11
# File 'lib/sitepress/asset_node_mapper.rb', line 9

def asset_paths
  @asset_paths
end

#nodeObject (readonly)

Returns the value of attribute node.



9
10
11
# File 'lib/sitepress/asset_node_mapper.rb', line 9

def node
  @node
end

Instance Method Details

#mapObject

Mounts the source files from the path to the given node.



17
18
19
20
21
22
23
24
25
# 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