Class: Awestruct::Extensions::Assets::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/assets.rb

Instance Method Summary collapse

Instance Method Details

#asset(site, page, href) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/awestruct/extensions/assets.rb', line 21

def asset(site, page, href)
  if site.assets_url
    File.join(site.assets_url, href)
  else
    relative(page, File.join("/#{site.assets_path||'assets'}", href))
  end
end

#relative(page, href) ⇒ Object

FIXME this is not DRY at all



18
19
20
# File 'lib/awestruct/extensions/assets.rb', line 18

def relative(page, href)
  Pathname.new(href).relative_path_from(Pathname.new(File.dirname(page.output_path))).to_s
end

#transform(site, page, input) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/awestruct/extensions/assets.rb', line 28

def transform(site, page, input)
  if page.output_path =~ /\.html/
    input.gsub('asset://', asset(site, page, "#{File.basename(File.basename(page.source_path, ".md"))}") + "/")
  else
    input
  end
end