Class FileHandlers::DefaultHandler
In: lib/webgen/plugins/filehandlers/filehandler.rb
Parent: Webgen::Plugin
Webgen::Plugin DefaultHandler FileHandler CopyHandler ThumbnailWriter SipttraHandler VirtualFileHandler GalleryHandler TemplateHandler PageHandler DirectoryHandler Listener lib/webgen/plugins/filehandlers/filehandler.rb lib/webgen/plugins/filehandlers/copy.rb lib/webgen/plugins/filehandlers/directory.rb lib/webgen/plugins/filehandlers/page.rb lib/webgen/plugins/filehandlers/sipttra.rb lib/webgen/plugins/filehandlers/gallery.rb lib/webgen/plugins/filehandlers/template.rb FileHandlers dot/m_26_0.png

The default handler which is the super class of all file handlers. It defines methods thata should be used by the subclasses to specify which files should be handled. There are two types of path patterns: constant ones defined using the class methods and dynamic ones defined using the instance methods. The dynamic path patterns should be defined during the initialization!

During a webgen run the FileHandler retrieves all plugins which derive from the DefaultHandler and uses the constant and dynamic path patterns defined for each file handler plugin for finding the handled files.

Methods

Constants

EXTENSION_PATH_PATTERN = "**/*.%s"
DEFAULT_RANK = 100

Public Class methods

Sets the default meta information for the file handler. This meta information can later be overridden by the +Core/FileHandler:defaultMetaInfo+ parameter and values set in the meta information backing file. The so updated meta information is then passed to the create_node method.

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 376
376:     def self.default_meta_info( hash )
377:       self.config.infos[:default_meta_info] = hash
378:     end

Specify the files handled by the class via the extension. The parameter ext should be the pure extension without the dot. Also see DefaultHandler.register_path_pattern !

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 351
351:     def self.register_extension( ext, rank = DEFAULT_RANK )
352:       register_path_pattern( EXTENSION_PATH_PATTERN % [ext], rank )
353:     end

Specify the path pattern which should be handled by the class. The rank is used for sorting the patterns so that the creation order of nodes can be influenced. If a file is matched by more than one path pattern defined by a single file handler plugin, it is only used once for the first pattern.

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 345
345:     def self.register_path_pattern( path, rank = DEFAULT_RANK )
346:       (self.config.infos[:path_patterns] ||= []) << [rank, path]
347:     end

Public Instance methods

Asks the plugin to create a node for the given path and the parent, using meta_info as default meta data for the node. Should return the node for the path (the newly created node or, if a node with the path already exists, the existing one) or nil if the node could not be created.

Has to be overridden by the subclass!!!

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 386
386:     def create_node( path, parent, meta_info )
387:       raise NotImplementedError
388:     end

Returns a HTML link to the node from ref_node or, if node and ref_node are the same and the parameter linkToCurrentPage is false, a span element with the link text.

You can optionally specify additional attributes for the html element in the attr Hash. Also, the meta information linkAttrs of the given node is used, if available, to set attributes. However, the attr parameter takes precedence over the linkAttrs meta information. If the special value +:link_text+ is present in the attributes, it will be used as the link text; otherwise the title of the node will be used. Be aware that all key-value pairs with Symbol keys are removed before the attributes are written. Therefore you always need to specify general attributes with Strings!

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 413
413:     def link_from( node, ref_node, attr = {} )
414:       attr = node['linkAttrs'].merge( attr ) if node['linkAttrs'].kind_of?( Hash )
415:       link_text = attr[:link_text] || node['title']
416:       context = attr[:context]
417:       attr.delete_if {|k,v| k.kind_of?( Symbol )}
418: 
419:       use_link = ( node != ref_node || param( 'linkToCurrentPage' ) )
420:       attr['href'] = ref_node.route_to( node ) if use_link
421:       attrs = attr.collect {|name,value| "#{name.to_s}=\"#{value}\"" }.sort.unshift( '' ).join( ' ' )
422:       if !node['link_callback'].nil?
423:         result = begin
424:                    instance_eval(node['link_callback'])
425:                  rescue
426:                    log(:error) { "Error while evaluating link callback from node <#{node.node_info[:src]}>: #{$!.message}" }
427:                    nil
428:                  end
429:       end
430:       if result.nil?
431:         ( use_link ? "<a#{attrs}>#{link_text}</a>" : "<span#{attrs}>#{link_text}</span>" )
432:       else
433:         result
434:       end
435:     end

Returns the node which has the same data as node but in language lang; or nil if such a node does not exist. The default behaviour assumes that node has the data for all languages.

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 399
399:     def node_for_lang( node, lang )
400:       node
401:     end

Returns all (i.e. static and dynamic) path patterns defined for the file handler.

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 368
368:     def path_patterns
369:       (self.class.config.infos[:path_patterns] || []) + (@path_patterns ||= [])
370:     end

Asks the plugin to write out the node.

Has to be overridden by the subclass!!!

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 393
393:     def write_node( node )
394:       raise NotImplementedError
395:     end

Protected Instance methods

See DefaultHandler.register_extension

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 362
362:     def register_extension( ext, rank = DEFAULT_RANK )
363:       register_path_pattern( EXTENSION_PATH_PATTERN % [ext], rank )
364:     end

See DefaultHandler.register_path_pattern

[Source]

     # File lib/webgen/plugins/filehandlers/filehandler.rb, line 356
356:     def register_path_pattern( path, rank = DEFAULT_RANK )
357:       (@path_patterns ||= []) << [rank, path]
358:     end

[Validate]