Class FileHandlers::CopyHandler
In: lib/webgen/plugins/filehandlers/copy.rb
Parent: DefaultHandler
Webgen::Plugin DefaultHandler FileHandler CopyHandler ThumbnailWriter SipttraHandler VirtualFileHandler GalleryHandler TemplateHandler DirectoryHandler PageHandler 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_50_0.png

A simple file handler which copies files specified by a pattern from the source to the output directory.

Methods

create_node   new   write_node  

Public Class methods

[Source]

    # File lib/webgen/plugins/filehandlers/copy.rb, line 44
44:     def initialize( plugin_manager )
45:       super
46:       param( 'paths' ).each {|path| register_path_pattern( path ) }
47:       param( 'erbPaths' ).each {|path| register_path_pattern( path ) }
48:     end

Public Instance methods

[Source]

    # File lib/webgen/plugins/filehandlers/copy.rb, line 50
50:     def create_node( path, parent, meta_info )
51:       processWithErb = param( 'erbPaths' ).any? {|pattern| File.fnmatch( pattern, path, File::FNM_DOTMATCH )}
52:       name = File.basename( path )
53:       name = name.sub( /\.r([^.]+)$/, '.\1' ) if processWithErb
54: 
55:       node = parent.find {|c| c =~ name }
56:       if node.nil?
57:         node = Node.new( parent, name )
58:         node['title'] = name
59:         node.meta_info.update( meta_info )
60:         node.node_info[:src] = path
61:         node.node_info[:processor] = self
62:         node.node_info[:preprocess] = processWithErb
63:       else
64:         log(:warn) { "Can't create node <#{node.full_path}> as it already exists (node handled by #{node.node_info[:processor].class.plugin_name})!" }
65:       end
66:       node
67:     end

Copy the file to the destination directory if it has been modified.

[Source]

    # File lib/webgen/plugins/filehandlers/copy.rb, line 70
70:     def write_node( node )
71:       if @plugin_manager['Core/FileHandler'].file_modified?( node.node_info[:src], node.full_path )
72:         if node.node_info[:preprocess]
73:           File.open( node.full_path, 'w+' ) {|f| f.write( ERB.new( File.read( node.node_info[:src] ) ).result( binding ) ) }
74:         else
75:           FileUtils.cp( node.node_info[:src], node.full_path )
76:         end
77:       end
78:     end

[Validate]