Sha256: 72c8b802365fcc5e7b3c9f9e7895740017187021843ee16af731a4cf22da7a18

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require 'rexml/element'

module BuildMaster
class Link
  def initialize(site_spec)
    @site_spec = site_spec
  end

  def process(target, template, source)
    target_path = get_href_as_relative_path(template)
    result = nil
    if (target_path == source.path)
      result = REXML::Element.new('div')
      result.attributes['class'] = 'current'
    else
      result = REXML::Element.new('a')
      href = target_path.relative_path_from(source.path.parent)
     result.attributes['href'] = href.to_s
    end
    template.attributes.each do |name, value|
      result.attributes[name] = value unless name == 'href'
    end
    template.each_child do |element|
      runner = TemplateRunner.new(result, @site_spec.load_element_processor, source)
      runner.process template
    end
    target.add(result)
  end
  
  private
  def get_href_as_relative_path(template)
    href = Pathname.new(template.attribute_value!('href'))
    if (href.absolute?)
      href = href.relative_path_from(Pathname.new('/'))
    end
    return href
  end
  
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
BuildMaster-1.0.6 lib/buildmaster/site/templatelets/link.rb
BuildMaster-1.0.9 lib/buildmaster/site/templatelets/link.rb
BuildMaster-1.1.12 lib/buildmaster/site/templatelets/link.rb
BuildMaster-1.1.9 lib/buildmaster/site/templatelets/link.rb