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_params_hash, #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.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/webgen/tag/relocatable.rb', line 18 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 log(:error) { "Error while parsing path for tag relocatable in <#{context.ref_node.alcn}>: #{e.}" } context.dest_node.flag(:dirty) end result end |