Module: Textus::Key::Path

Defined in:
lib/textus/key/path.rb

Class Method Summary collapse

Class Method Details

.normalize_relative_path(path) ⇒ Object



21
22
23
24
25
# File 'lib/textus/key/path.rb', line 21

def self.normalize_relative_path(path)
  return path if path.start_with?("data/")

  File.join("data", path)
end

.resolve(data, mentry) ⇒ Object

Returns the absolute filesystem path for a manifest entry (the leaf file, not a nested directory). Adds the format’s primary extension when the manifest entry’s ‘path:` is extensionless.

The first argument is a Manifest::Data (or anything responding to .root); callers historically passed the whole Manifest but should now pass ‘manifest.data`.



11
12
13
14
15
16
17
18
19
# File 'lib/textus/key/path.rb', line 11

def self.resolve(data, mentry)
  primary_ext = Entry.for_format(mentry.format).extensions.first
  rel_path = normalize_relative_path(mentry.path)
  if File.extname(mentry.path) == ""
    File.join(data.root, rel_path + primary_ext)
  else
    File.join(data.root, rel_path)
  end
end