| Class | Tags::RelocatableTag |
| In: |
lib/webgen/plugins/tags/relocatable.rb
|
| Parent: | DefaultTag |
Changes the path of file. 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.
Tag parameter: the name of the file which should be relocated
# File lib/webgen/plugins/tags/relocatable.rb, line 50
50: def process_tag( tag, chain )
51: uri_string = param( 'path' )
52: result = ''
53: unless uri_string.nil?
54: begin
55: uri = URI.parse( uri_string )
56: if uri.absolute?
57: result = uri_string
58: else
59: result = resolve_path( uri, chain )
60: end
61: log(:error) { "Could not resolve path '#{uri_string}' in <#{chain.first.node_info[:src]}>" } if result.empty?
62: rescue URI::InvalidURIError => e
63: log(:error) { "Error while parsing path for tag relocatable in <#{chain.first.node_info[:src]}>: #{e.message}" }
64: end
65: end
66: result
67: end
# File lib/webgen/plugins/tags/relocatable.rb, line 73
73: def query_fragment( uri )
74: (uri.query.nil? ? '' : '?'+ uri.query ) + (uri.fragment.nil? ? '' : '#' + uri.fragment)
75: end
# File lib/webgen/plugins/tags/relocatable.rb, line 77
77: def resolve_path( uri, chain )
78: dest_node = chain.first.resolve_node( uri.path )
79: if !dest_node.nil? && (File.basename( uri.path ) == dest_node.node_info[:pagename] || dest_node.is_directory?)
80: dest_node = dest_node.node_for_lang( chain.last['lang'] )
81: end
82: if !dest_node.nil? && !uri.fragment.nil? && param( 'resolveFragment' )
83: dest_node = dest_node.resolve_node( '#' + uri.fragment )
84: end
85: if dest_node.nil?
86: ''
87: else
88: chain.last.route_to( dest_node.is_fragment? ? dest_node.parent : dest_node ) + query_fragment( uri )
89: end
90: end