Sha256: 47469fe8ac2919e53eddcfbe728584fa33b11b43830aae60986f98a64dac8e1c
Contents?: true
Size: 1.67 KB
Versions: 8
Compression:
Stored size: 1.67 KB
Contents
require 'webgen/tag' require 'uri' module Webgen::Tag # Makes a path relative. This is very useful for templates. For example, you normally include a # stylesheet in a template. If you specify the filename of the stylesheet directly, the reference # to the stylesheet in the output file of a page file that is not in the same directory as the # template would be invalid. # # By using the +relocatable+ tag you ensure that the path stays valid. class Relocatable include Webgen::Tag::Base # Return the relativized path for the path provided in the tag definition. def call(tag, body, context) uri_string = param('tag.relocatable.path') result = '' unless uri_string.nil? begin uri = URI.parse(uri_string) if uri.absolute? result = uri_string else result = resolve_path(uri_string, context) end if result.empty? log(:error) { "Could not resolve path '#{uri_string}' in <#{context.ref_node.absolute_lcn}>" } context.dest_node.dirty = true end rescue URI::InvalidURIError => e log(:error) { "Error while parsing path for tag relocatable in <#{context.ref_node.absolute_lcn}>: #{e.message}" } context.dest_node.dirty = true end end result end ####### private ####### # Resolve the path +uri+ using the reference node and return the correct relative path from the # destination node. def resolve_path(uri, context) dest_node = context.ref_node.resolve(uri, context.dest_node.lang) (dest_node ? context.dest_node.route_to(dest_node) : '') end end end
Version data entries
8 entries across 8 versions & 2 rubygems