Class Tags::RelocatableTag
In: lib/webgen/plugins/tags/relocatable.rb
Parent: DefaultTag
DefaultTag MetaTag BreadcrumbTrailTag RelocatableTag IncludeFileTag DateTag LangbarTag WikiLinkTag SitemapTag ResourceTag ExecuteCommandTag CustomVarTag BlockTag MenuTag DownloadTag HtmlMetaInfo Webgen::Plugin TagProcessor lib/webgen/plugins/tags/date.rb lib/webgen/plugins/tags/menu.rb lib/webgen/plugins/tags/sitemap.rb lib/webgen/plugins/tags/wikilink.rb lib/webgen/plugins/tags/executecommand.rb lib/webgen/plugins/tags/langbar.rb lib/webgen/plugins/tags/breadcrumbtrail.rb lib/webgen/plugins/tags/includefile.rb lib/webgen/plugins/tags/relocatable.rb lib/webgen/plugins/tags/meta.rb lib/webgen/plugins/tags/htmlmetainfo.rb lib/webgen/plugins/tags/download.rb lib/webgen/plugins/tags/block.rb lib/webgen/plugins/tags/tag_processor.rb lib/webgen/plugins/coreplugins/resourcemanager.rb lib/webgen/plugins/tags/customvar.rb Tags dot/m_29_0.png

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

Methods

Public Instance methods

[Source]

    # 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

Private Instance methods

[Source]

    # 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

[Source]

    # 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

[Validate]