Class Webgen::Tag::Relocatable
In: lib/webgen/tag/relocatable.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Node Tree FileSystem Sitemap Coderay Sitemap IncludeFile Langbar BreadcrumbTrail TikZ Menu Feed Copy Virtual Sitemap Directory Page Fragment Template Metainfo Memory Resource Tags Fragments Website Tidy Head Kramdown Less Xmllint Blocks Helpers Configuration Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand ExecuteCommand Link Date Relocatable Metainfo WebsiteAccess Main Loggable OutputPathHelpers ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils TarArchive Stacked FileSystem RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/blackboard.rb lib/webgen/website.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/context/tags.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI ClassMethods WebsiteAccess LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor Loggable Webgen dot/m_81_0.png

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.

Methods

call   resolve_path  

Included Modules

Webgen::Tag::Base

Public Instance methods

Return the relativized path for the path provided in the tag definition.

[Source]

    # 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 the path path using the reference node and return the correct relative path from the destination node.

[Source]

    # 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

[Validate]