Sha256: 42edf672751eb212b3b15099f81da409df75a1e31831342bcb4f2c4d8ffda9be

Contents?: true

Size: 1.49 KB

Versions: 12

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

usage 'shell'
summary 'open a shell on the Nanoc environment'
aliases 'console', 'sh'
description "
Open an IRB shell on a context that contains @items, @layouts, and @config.
"
flag :p, :preprocess, 'run preprocessor'
no_params

module Nanoc::CLI::Commands
  class Shell < ::Nanoc::CLI::CommandRunner
    def run
      require 'pry'

      # Needed to make pry behave properly sometimes -- see nanoc/nanoc#1309
      Signal.trap('SIGINT') { raise Interrupt }

      @site = load_site
      Nanoc::Int::Compiler.new_for(@site).run_until_preprocessed if options[:preprocess]

      Nanoc::Int::Context.new(env).pry
    end

    def env
      self.class.env_for_site(@site)
    end

    def self.reps_for(site)
      Nanoc::Int::ItemRepRepo.new.tap do |reps|
        action_provider = Nanoc::Int::ActionProvider.named(site.config.action_provider).for(site)
        builder = Nanoc::Int::ItemRepBuilder.new(site, action_provider, reps)
        builder.run
      end
    end

    def self.view_context_for(site)
      Nanoc::ViewContextForShell.new(
        items: site.items,
        reps: reps_for(site),
      )
    end

    def self.env_for_site(site)
      view_context = view_context_for(site)

      {
        items: Nanoc::ItemCollectionWithRepsView.new(site.items, view_context),
        layouts: Nanoc::LayoutCollectionView.new(site.layouts, view_context),
        config: Nanoc::ConfigView.new(site.config, view_context),
      }
    end
  end
end

runner Nanoc::CLI::Commands::Shell

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nanoc-4.11.0 lib/nanoc/cli/commands/shell.rb
nanoc-4.10.4 lib/nanoc/cli/commands/shell.rb
nanoc-4.10.3 lib/nanoc/cli/commands/shell.rb
nanoc-4.10.2 lib/nanoc/cli/commands/shell.rb
nanoc-4.10.1 lib/nanoc/cli/commands/shell.rb
nanoc-4.10.0 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.9 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.8 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.7 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.6 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.5 lib/nanoc/cli/commands/shell.rb
nanoc-4.9.4 lib/nanoc/cli/commands/shell.rb