Class: Webgen::Tag::Relocatable
- Inherits:
-
Object
- Object
- Webgen::Tag::Relocatable
- Includes:
- Base
- Defined in:
- lib/webgen/tag/relocatable.rb
Overview
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.
Instance Method Summary collapse
-
#call(tag, body, context) ⇒ Object
Return the relativized path for the path provided in the tag definition.
Methods included from Base
#create_tag_params, #param, #set_params
Methods included from WebsiteAccess
Methods included from Loggable
Instance Method Details
#call(tag, body, context) ⇒ Object
Return the relativized path for the path provided in the tag definition.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/webgen/tag/relocatable.rb', line 17 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.}" } context.dest_node.dirty = true end end result end |