Sha256: db60b68a0a4e8a58c9688ef12a86a09b8f991f4cbfeb82a652ded0080d884d10

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

usage 'view [options]'
summary 'start the web server that serves static files'
description <<~EOS
  Start the static web server. Unless specified, the web server will run on port
  3000 and listen on all IP addresses. Running this static web server requires
  `adsf` (not `asdf`!).
EOS

required :H, :handler, 'specify the handler to use (webrick/mongrel/...)'
required :o, :host,    'specify the host to listen on (default: 127.0.0.1)', default: '127.0.0.1'
required :p, :port,    'specify the port to listen on (default: 3000)', transform: Nanoc::CLI::Transform::Port, default: 3000
flag :L, :'live-reload', 'reload on changes'
no_params

module Nanoc::CLI::Commands
  class View < ::Nanoc::CLI::CommandRunner
    DEFAULT_HANDLER_NAME = :thin

    def run
      load_adsf

      config = Nanoc::Int::ConfigLoader.new.new_from_cwd

      # Create output dir so that viewer/watcher doesn’t explode.
      FileUtils.mkdir_p(config.output_dir)

      server =
        Adsf::Server.new(
          root: File.absolute_path(config.output_dir),
          live: options[:'live-reload'],
          index_filenames: config[:index_filenames],
          host: options[:host],
          port: options[:port],
          handler: options[:handler],
        )

      server.run
    end

    protected

    def load_adsf
      # Load adsf
      begin
        require 'adsf'
        return
      rescue LoadError
        $stderr.puts "Could not find the required 'adsf' gem, " \
          'which is necessary for the view command.'
      end

      # Check asdf
      begin
        require 'asdf'
        $stderr.puts "You appear to have 'asdf' installed, " \
          "but not 'adsf'. Please install 'adsf' (check the spelling)!"
      rescue LoadError
      end

      # Done
      exit 1
    end
  end
end

runner Nanoc::CLI::Commands::View

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nanoc-4.11.12 lib/nanoc/cli/commands/view.rb
nanoc-4.11.11 lib/nanoc/cli/commands/view.rb
nanoc-4.11.10 lib/nanoc/cli/commands/view.rb
nanoc-4.11.9 lib/nanoc/cli/commands/view.rb
nanoc-4.11.8 lib/nanoc/cli/commands/view.rb
nanoc-4.11.7 lib/nanoc/cli/commands/view.rb
nanoc-4.11.6 lib/nanoc/cli/commands/view.rb