Module: Awestruct::Extensions::Relative

Included in:
Assets, Assets::Extension::Extension
Defined in:
lib/awestruct/extensions/relative.rb

Instance Method Summary collapse

Instance Method Details

#relative(href, p = page) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/awestruct/extensions/relative.rb', line 8

def relative(href, p = page)
  begin
    # Ignore absolute links
    if href.start_with?("http://") || href.start_with?("https://")
      result = href
    else
      pathname = Pathname.new(href).relative_path_from(Pathname.new(File.dirname(p.output_path)))
      result = pathname.to_s
      result << '/' if pathname.extname.empty?
    end
    result
  rescue Exception => e
    ExceptionHelper.log_building_error e, p.relative_source_path
  end
end