Class: NanDoc::DataSource::Orphanage

Inherits:
Object
  • Object
show all
Includes:
ItemMethods
Defined in:
lib/nandoc/support/orphanage.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ItemMethods

#dot_dot_has?, #dot_dot_strip, #dot_dot_strip_assert, #find_parent, #identifier_bare_rootname, #identifier_bare_rootname_assert, #parent_identifier, #site_root, #slash_strip, #slash_strip_assert

Class Method Details

.rescue_orphans(config, items) ⇒ Object



9
10
11
# File 'lib/nandoc/support/orphanage.rb', line 9

def rescue_orphans config, items
  new(config, items).rescue_orphans
end

Instance Method Details

#rescue_orphansObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nandoc/support/orphanage.rb', line 15

def rescue_orphans
  fail("must have site root to continue hacking") unless site_root
  items = @items.map # we are going to add to it in loop below
  items.each do |item|
    next unless is_orphan? item
    id = item.identifier
    parent_id = parent_identifier(id)
    bare_root = identifier_bare_rootname_assert(id)
    bare_parent = slash_strip_assert(parent_id)
    new_id = nil
    @renamer = nil
    if @basenames.include?(bare_root)
      # then we need to hack a rename to the identifier
      @renamer = /\A\/#{Regexp.escape(bare_root)}\/(.+)\Z/
      new_id = rename(id)
    end
    if (!new_id || bare_parent!=bare_root) && is_orphan?(item, new_id)
      make_surrogate_parent parent_id
    end
    item.identifier = new_id if new_id
  end
end