Method: Fronde::Source#source_for

Defined in:
lib/fronde/source.rb

#source_for(file_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fronde/source.rb', line 58

def source_for(file_name)
  relative_file_path = file_name.delete_prefix "#{publication_path}/"
  # file_name does not begin with source path.
  return if relative_file_path == file_name

  # Looks like a file at a deeper level, but current source is not
  # recursive.
  return if relative_file_path.include?('/') && !recursive?

  # Looks like a match. But does a source file for this one actually
  # exists?
  relative_source_path = relative_file_path.sub(
    /#{@config['ext']}\z/, '.org'
  )
  source_path = File.join(@config['path'], relative_source_path)
  return unless File.file?(source_path)

  source_path
end