Sha256: 7715f83e8f9207be751a142c381d167bf48823936f4abb19196b69b4d57da5f8

Contents?: true

Size: 1.91 KB

Versions: 9

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8

module Nanoc3::CLI::Commands

  class Autocompile < Cri::Command

    def name
      'autocompile'
    end

    def aliases
      [ 'aco' ]
    end

    def short_desc
      'start the autocompiler'
    end

    def long_desc
      'Start the autocompiler web server. Unless specified, the web ' +
      'server will run on port 3000 and listen on all IP addresses. ' +
      'Running the autocompiler requires \'mime/types\' and \'rack\'.'
    end

    def usage
      "nanoc3 autocompile [options]"
    end

    def option_definitions
      [
        # --server
        {
          :long => 'server', :short => 's', :argument => :required,
          :desc => 'specify the server to use (webrick/mongrel)'
        },
        # --host
        {
          :long => 'host', :short => 'o', :argument => :required,
          :desc => 'specify the host to listen on (default: 0.0.0.0)'
        },
        # --port
        {
          :long => 'port', :short => 'p', :argument => :required,
          :desc => 'specify the port to listen on (default: 3000)'
        }
      ]
    end

    def run(options, arguments)
      require 'rack'

      # Make sure we are in a nanoc site directory
      @base.require_site

      # Set options
      options_for_rack = {
        :Port      => (options[:port] || 3000).to_i,
        :Host      => (options[:host] || '0.0.0.0')
      }

      # Guess which handler we should use
      unless handler = Rack::Handler.get(options[:server])
        begin
          handler = Rack::Handler::Mongrel
        rescue LoadError => e
          handler = Rack::Handler::WEBrick
        end
      end

      # Build app
      autocompiler = Nanoc3::Extra::AutoCompiler.new('.')
      app = Rack::Builder.new do
        use Rack::CommonLogger, $stderr
        use Rack::ShowExceptions
        run autocompiler
      end.to_app

      # Run autocompiler
      handler.run(app, options_for_rack)
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nanoc3-3.0.9 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.8 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.7 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.6 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.5 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.4 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.3 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.2 lib/nanoc3/cli/commands/autocompile.rb
nanoc3-3.0.1 lib/nanoc3/cli/commands/autocompile.rb