Parent

Included Modules

Class 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 18
18:     def call(tag, body, context)
19:       path = param('tag.relocatable.path')
20:       result = ''
21:       begin
22:         result = (Webgen::Node.url(path, false).absolute? ? path : resolve_path(path, context))
23:       rescue URI::InvalidURIError => e
24:         raise Webgen::RenderError.new("Error while parsing path '#{path}': #{e.message}",
25:                                       self.class.name, context.dest_node, context.ref_node)
26:       end
27:       result
28:     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 36
36:     def resolve_path(path, context)
37:       dest_node = context.ref_node.resolve(path, context.dest_node.lang)
38:       if dest_node
39:         context.dest_node.node_info[:used_meta_info_nodes] << dest_node.alcn
40:         context.dest_node.route_to(dest_node)
41:       else
42:         log(:error) { "Could not resolve path '#{path}' in <#{context.ref_node}>" }
43:         context.dest_node.flag(:dirty)
44:         ''
45:       end
46:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.