Class: Webgen::SourceHandler::Main

Inherits:
Object
  • Object
show all
Includes:
Loggable, WebsiteAccess
Defined in:
lib/webgen/sourcehandler.rb

Overview

This class is used by Website to do the actual rendering of the website. It

  • collects all source paths using the source classes

  • creates nodes using the source handler classes

  • writes changed nodes out using an output class

  • deletes old nodes

Instance Method Summary collapse

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Constructor Details

#initializeMain

:nodoc:



37
38
39
40
41
42
43
44
45
46
# File 'lib/webgen/sourcehandler.rb', line 37

def initialize #:nodoc:
  website.blackboard.add_service(:create_nodes, method(:create_nodes))
  website.blackboard.add_service(:create_nodes_from_paths, method(:create_nodes_from_paths))
  website.blackboard.add_service(:source_paths, method(:find_all_source_paths))
  website.blackboard.add_listener(:node_meta_info_changed?, method(:meta_info_changed?))

  website.blackboard.add_listener(:before_node_deleted) do |node|
    website.blackboard.invoke(:output_instance).delete(node.path)
  end if website.config['output.do_deletion']
end

Instance Method Details

#renderObject

Render the current website. Before the actual rendering is done, the sources are checked for changes, i.e. nodes for deleted sources are deleted, nodes for new and changed sources are updated.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/webgen/sourcehandler.rb', line 51

def render
  begin
    website.logger.mark_new_cycle if website.logger

    puts "Updating tree..."
    time = Benchmark.measure do
      website.cache.reset_volatile_cache
      update_tree
    end
    puts "...done in " + ('%2.4f' % time.real) + ' seconds'

    if !website.tree.root
      puts 'No source files found - maybe not a webgen website?'
      return nil
    end

    puts "Writing changed nodes..."
    time = Benchmark.measure do
      write_tree
    end
    puts "...done in " + ('%2.4f' % time.real) + ' seconds'
  end while website.tree.node_access[:alcn].any? {|name,node| node.flagged?(:created) || node.flagged?(:reinit)}
  :success
end