Sha256: 7f8ae869e9e0d3d329b0d25a9376319a3921096d301f983326ac911b618dfca8

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

$:.unshift(File.join('..', File.dirname(__FILE__)))

require 'uri'

require 'template_exception'
require 'template_runner'

module BuildMaster

class Href
  def initialize(site_spec)
    @site_spec = site_spec
  end
  
  def process(target, template, source)
    url = template.attribute_value!('url')
    href = construct_href(url, source.path)
    target.attributes[name_based_on_target(target)] = href
  end
  
  private
  def construct_href(url, current_path)
    href = url
    if (URI.parse(url).scheme.nil?)
      href = Pathname.new(url).relative_path_from(current_path.parent)
    end  
    return href
  end
  
  def name_based_on_target(target)
    name = target.name
    if (name == 'img')
      return 'src'
    else
      return 'href'
    end
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
BuildMaster-0.8.0 lib/buildmaster/templatelets/href.rb