Parent

Included Modules

Class/Module Index [+]

Quicksearch

Webgen::Tag::Relocatable

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.

Public Instance Methods

call(tag, body, context) click to toggle source

Return the relativized path for the path provided in the tag definition.

# File lib/webgen/tag/relocatable.rb, line 17
def call(tag, body, context)
  path = param('tag.relocatable.path')
  result = ''
  begin
    result = (Webgen::Node.url(path, false).absolute? ? path : resolve_path(path, context))
  rescue URI::InvalidURIError => e
    raise Webgen::RenderError.new("Error while parsing path '#{path}': #{e.message}",
                                  self.class.name, context.dest_node, context.ref_node)
  end
  result
end

Private Instance Methods

resolve_path(path, context) click to toggle source

Resolve the path path using the reference node and return the correct relative path from the destination node.

# File lib/webgen/tag/relocatable.rb, line 35
def resolve_path(path, context)
  dest_node = context.ref_node.resolve(path, context.dest_node.lang)
  if dest_node
    context.dest_node.node_info[:used_meta_info_nodes] << dest_node.alcn
    context.dest_node.route_to(dest_node)
  else
    log(:error) { "Could not resolve path '#{path}' in <#{context.ref_node}>" }
    context.dest_node.flag(:dirty)
    ''
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.