Class: Nanoc::Int::ItemRepRouter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/base/services/item_rep_router.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Assigns paths to reps.

Defined Under Namespace

Classes: IdenticalRoutesError

Instance Method Summary collapse

Constructor Details

#initialize(reps, action_provider, site) ⇒ ItemRepRouter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ItemRepRouter.



12
13
14
15
16
# File 'lib/nanoc/base/services/item_rep_router.rb', line 12

def initialize(reps, action_provider, site)
  @reps = reps
  @action_provider = action_provider
  @site = site
end

Instance Method Details

#route_rep(rep, snapshot_action, paths_to_reps) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nanoc/base/services/item_rep_router.rb', line 28

def route_rep(rep, snapshot_action, paths_to_reps)
  basic_path = snapshot_action.path
  return if basic_path.nil?
  basic_path = basic_path.encode('UTF-8')

  # Check for duplicate paths
  if paths_to_reps.key?(basic_path)
    raise IdenticalRoutesError.new(basic_path, paths_to_reps[basic_path], rep)
  else
    paths_to_reps[basic_path] = rep
  end

  rep.raw_paths[snapshot_action.snapshot_name] = @site.config[:output_dir] + basic_path
  rep.paths[snapshot_action.snapshot_name] = strip_index_filename(basic_path)
end

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
25
26
# File 'lib/nanoc/base/services/item_rep_router.rb', line 18

def run
  paths_to_reps = {}
  @reps.each do |rep|
    mem = @action_provider.memory_for(rep)
    mem.snapshot_actions.each do |snapshot_action|
      route_rep(rep, snapshot_action, paths_to_reps)
    end
  end
end

#strip_index_filename(basic_path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
51
52
53
# File 'lib/nanoc/base/services/item_rep_router.rb', line 44

def strip_index_filename(basic_path)
  @site.config[:index_filenames].each do |index_filename|
    slashed_index_filename = '/' + index_filename
    if basic_path.end_with?(slashed_index_filename)
      return basic_path[0..-index_filename.length - 1]
    end
  end

  basic_path
end