Class Webgen::Path
In: lib/webgen/path.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

General Information

A Path object provides information about a path that is used to create one or more nodes as well as methods for accessing the path‘s content. So a Path object always refers to a source path. In contrast, output paths are always strings and just specify the location where a specific node should be written to.

Note the path and source_path attributes of a Path object:

  • The source_path specifies a path string that was directly created by a Source object. Each Path object must have such a valid source path sothat webgen can infer the Path the lead to the creation of a Node object later.
  • In contrast, the path attribute specifies the path that is used to create the canonical name (and by default the output path) of a Node object. Normally it is the same as the source_path but can differ (e.g. when fragment nodes are created for page file nodes).

A Path object can represent one of three different things: a directory, a file or a fragment. If the path ends with a slash character, then the path object represents a directory, if the path contains a hash character anywhere, then the path object represents a fragment and else it represents a file. Have a look at the webgen manual to see the exact format of a path!

Relation to Source classes

A webgen source class needs to derive a specialized path class from this class and implement an approriate changed? method that returns true if the path‘s content has changed since the last webgen run.

Methods

<=>   ==   acn   alcn   analyse   analyse_directory   analyse_file   analyse_fragment   changed?   cn   dup   eql?   io   lcn   lcn   make_absolute   match   mount_at   new   passive?  

Included Modules

Comparable

Classes and Modules

Class Webgen::Path::SourceIO

Constants

FILENAME_RE = /^(?:(\d+)\.)?(\.?[^.]*?)(?:\.(\w\w\w?)(?=\.))?(?:\.(.*))?$/

External Aliases

to_s -> to_str

Attributes

basename  [RW]  The canonical name of the path without the extension.
ext  [RW]  The extension of the path.
meta_info  [RW]  Extracted meta information for the path.
parent_path  [R]  The string specifying the parent path
passive  [W]  Specifies whether this path should be used during the "tree update" phase of a webgen run or only later during node resolution.
path  [R]  The full path for which this Path object was created.
source_path  [R]  A string specifying the path that lead to the creation of this path.

Public Class methods

Utility method for creating the lcn from the cn and the language lang.

[Source]

     # File lib/webgen/path.rb, line 185
185:     def self.lcn(cn, lang)
186:       if lang.nil?
187:         cn
188:       else
189:         cn.split('.').insert((cn =~ /^\./ ? 2 : 1), lang.to_s).join('.')
190:       end
191:     end

Make the given path absolute by prepending the absolute directory path base if necessary. Also resolves all ’..’ and ’.’ references in path.

[Source]

    # File lib/webgen/path.rb, line 75
75:     def self.make_absolute(base, path)
76:       raise(ArgumentError, 'base has to be an absolute path, ie. needs to start with a slash') unless base =~ /^\//
77:       Pathname.new(path =~ /^\// ? path : File.join(base, path)).cleanpath.to_s + (path =~ /.\/$/ ? '/' : '')
78:     end

Return true if the given path matches the given pattern. For information on which patterns are supported, have a look at the documentation of File.fnmatch.

[Source]

    # File lib/webgen/path.rb, line 82
82:     def self.match(path, pattern)
83:       pattern += '/' if path.to_s =~ /\/$/ && pattern !~ /\/$|^$/
84:       File.fnmatch(pattern, path.to_s, File::FNM_DOTMATCH|File::FNM_CASEFOLD|File::FNM_PATHNAME)
85:     end

Create a new Path object for path. The optional source_path parameter specifies the path string that lead to the creation of this path. The optional block needs to return an IO object for getting the content of the path.

The path needs to be in a well defined format which can be looked up in the webgen manual.

[Source]

     # File lib/webgen/path.rb, line 122
122:     def initialize(path, source_path = path, &ioblock)
123:       @meta_info = {}
124:       @io = block_given? ? SourceIO.new(&ioblock) : nil
125:       @source_path = source_path
126:       @passive = false
127:       analyse(path)
128:     end

Public Instance methods

Compare the path of this object to other.path

[Source]

     # File lib/webgen/path.rb, line 230
230:     def <=>(other)
231:       @path <=> other.path
232:     end

Equality — Return true if other is a Path object with the same path or if other is a String equal to the path. Else return false.

[Source]

     # File lib/webgen/path.rb, line 218
218:     def ==(other)
219:       if other.kind_of?(Path)
220:         other.path == @path
221:       elsif other.kind_of?(String)
222:         other == @path
223:       else
224:         false
225:       end
226:     end

The absolute canonical name of this path.

[Source]

     # File lib/webgen/path.rb, line 199
199:     def acn
200:       if @path =~ /#/
201:         self.class.new(@parent_path).acn + cn
202:       else
203:         @parent_path + cn
204:       end
205:     end

The absolute localized canonical name of this path.

[Source]

     # File lib/webgen/path.rb, line 208
208:     def alcn
209:       if @path =~ /#/
210:         self.class.new(@parent_path).alcn + lcn
211:       else
212:         @parent_path + lcn
213:       end
214:     end

Has the content of this path changed since the last webgen run? This default implementation always returns true, a specialized sub class needs to override this behaviour!

[Source]

     # File lib/webgen/path.rb, line 166
166:     def changed?
167:       true
168:     end

The canonical name created from the path (namely from the parts basename and extension).

[Source]

     # File lib/webgen/path.rb, line 180
180:     def cn
181:       @basename + (@ext.length > 0 ? '.' + @ext : '') + (@basename != '/' && @path =~ /.\/$/ ? '/' : '')
182:     end

Duplicate the path object.

[Source]

     # File lib/webgen/path.rb, line 158
158:     def dup
159:       temp = super
160:       temp.instance_variable_set(:@meta_info, @meta_info.dup)
161:       temp
162:     end
eql?(other)

Alias for #==

The SourceIO object associated with the path.

[Source]

     # File lib/webgen/path.rb, line 171
171:     def io
172:       if @io
173:         @io
174:       else
175:         raise "No IO object defined for the path #{self}"
176:       end
177:     end

The localized canonical name created from the path.

[Source]

     # File lib/webgen/path.rb, line 194
194:     def lcn
195:       self.class.lcn(cn, @meta_info['lang'])
196:     end

Mount this path at the mount point mp, optionally stripping prefix from the parent path, and return the new path object.

The parameters mp and prefix have to be absolute directory paths, ie. they have to start and end with a slash and must not contain any hash characters!

[Source]

     # File lib/webgen/path.rb, line 139
139:     def mount_at(mp, prefix = nil)
140:       raise(ArgumentError, "The mount point (#{mp}) must be a valid directory path") if mp =~ /^[^\/]|#|[^\/]$/
141:       raise(ArgumentError, "The strip prefix (#{prefix}) must be a valid directory path") if !prefix.nil? && prefix =~ /^[^\/]|#|[^\/]$/
142: 
143:       temp = dup
144:       strip_re = /^#{Regexp.escape(prefix.to_s)}/
145:       temp.instance_variable_set(:@path, temp.path.sub(strip_re, ''))
146:       reanalyse = (@path == '/' || temp.path == '')
147:       temp.instance_variable_set(:@path, File.join(mp, temp.path))
148:       temp.instance_variable_set(:@source_path, temp.path) if @path == @source_path
149:       if reanalyse
150:         temp.send(:analyse, temp.path)
151:       else
152:         temp.instance_variable_set(:@parent_path, File.join(mp, temp.parent_path.sub(strip_re, '')))
153:       end
154:       temp
155:     end

Is this path only used later during node resolution? Defaults to false, i.e. used during the "tree update" phase.

[Source]

     # File lib/webgen/path.rb, line 114
114:     def passive?; @passive; end

Private Instance methods

Analyse the path and fill the object with the extracted information.

[Source]

     # File lib/webgen/path.rb, line 252
252:     def analyse(path)
253:       @path = path
254:       if @path =~ /#/
255:         analyse_fragment
256:       elsif @path =~ /\/$/
257:         analyse_directory
258:       else
259:         analyse_file
260:       end
261:       @meta_info['title'] = @basename.tr('_-', ' ').capitalize
262:       @ext ||= ''
263:       raise "The basename of a path may not be empty: #{@path}" if @basename.empty? || @basename == '#'
264:       raise "The parent path must start with a slash: #{@path}" if @path !~ /^\// && @path != '/'
265:     end

Analyse the path assuming it is a directory.

[Source]

     # File lib/webgen/path.rb, line 268
268:     def analyse_directory
269:       @parent_path = (@path == '/' ? '' : File.join(File.dirname(@path), '/'))
270:       @basename = File.basename(@path)
271:     end

Analyse the path assuming it is a file.

[Source]

     # File lib/webgen/path.rb, line 276
276:     def analyse_file
277:       @parent_path = File.join(File.dirname(@path), '/')
278:       match_data = FILENAME_RE.match(File.basename(@path))
279: 
280:       if !match_data[1].nil? && match_data[3].nil? && match_data[4].nil? # handle special case of sort_info.basename as basename.ext
281:         @basename = match_data[1]
282:         @ext = match_data[2]
283:       else
284:         @meta_info['sort_info'] = (match_data[1].nil? ? nil : match_data[1].to_i)
285:         @basename               = match_data[2]
286:         @meta_info['lang']      = Webgen::LanguageManager.language_for_code(match_data[3])
287:         @ext                    = (@meta_info['lang'].nil? && !match_data[3].nil? ? match_data[3].to_s + '.' : '') + match_data[4].to_s
288:       end
289:     end

Analyse the path assuming it is a fragment.

[Source]

     # File lib/webgen/path.rb, line 292
292:     def analyse_fragment
293:       @parent_path, @basename =  @path.scan(/^(.*?)(#.*?)$/).first
294:       raise "The parent path of a fragment path must be a file path and not a directory path: #{@path}" if @parent_path =~ /\/$/
295:       raise "A fragment path must only contain one hash character: #{path}" if @path.count("#") > 1
296:     end

[Validate]