Sha256: d72b5ae1ac9953406d2036e93a48616547c50f2e5418c9409d68f4797cdc82e3

Contents?: true

Size: 894 Bytes

Versions: 1

Compression:

Stored size: 894 Bytes

Contents

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

require 'uri'

require 'site/template_error'
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?)
      path = Pathname.new(url)
      if (not path.relative?)
        path = path.relative_path_from(Pathname.new('/'))
      end
      href = path.relative_path_from(current_path.parent).to_s
    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-1.1.9 lib/buildmaster/site/templatelets/href.rb