Sha256: ff49a513dcd9e4ea9ecfefe15c0371bae0bff3560ba20c86510822b4ed96d1f7

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

module Nanoc
  class Compiler

    attr_reader :stack

    def initialize(site)
      @site = site
    end

    def run(page=nil)
      # Give feedback
      log(:high, "Compiling #{page.nil? ? 'site' : 'page'}...")
      time_before = Time.now

      # Get the data we need
      @site.load_data
      eval(@site.code, $nanoc_binding)

      # Create output directory if necessary
      FileUtils.mkdir_p(@site.config[:output_dir])

      # Compile
      @stack = []
      pages = (page.nil? ? @site.pages : [ page ])
      pages.each do |current_page|
        begin
          current_page.compile
        rescue => exception
          handle_exception(exception, current_page, !page.nil?)
        end
      end

      # Give feedback
      log(:high, "No pages were modified.") unless pages.any? { |page| page.modified? }
      log(:high, "#{page.nil? ? 'Site' : 'Pages'} compiled in #{format('%.2f', Time.now - time_before)}s.")
    end

    def handle_exception(exception, page, single_page)
      raise exception if single_page

      log(:high, "ERROR: An exception occured while compiling page #{page.path}.", $stderr)
      log(:high, "", $stderr)
      log(:high, "If you think this is a bug in nanoc, please do report it at", $stderr)
      log(:high, "<http://nanoc.stoneship.org/trac/newticket> -- thanks!", $stderr)
      log(:high, "", $stderr)
      log(:high, 'Message:', $stderr)
      log(:high, '  ' + exception.message, $stderr)
      log(:high, 'Backtrace:', $stderr)
      log(:high, exception.backtrace.map { |t| '  - ' + t }.join("\n"), $stderr)

      exit(1)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nanoc-2.0.1 lib/nanoc/base/compiler.rb
nanoc-2.0 lib/nanoc/base/compiler.rb
nanoc-2.0.2 lib/nanoc/base/compiler.rb
nanoc-2.0.3 lib/nanoc/base/compiler.rb
nanoc-2.0.4 lib/nanoc/base/compiler.rb