Sha256: a57e4ff31c4f692e0b8e0fdfd99ce6f1dfd8f106cd7caa4401c74940bafeb01e

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

usage 'shell'
summary 'open a shell on the Nanoc environment'
aliases 'console'
description "
Open an IRB shell on a context that contains @items, @layouts, and @config.
"

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

      load_site

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

    protected

    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(:rule_dsl).for(site)
        builder = Nanoc::Int::ItemRepBuilder.new(site, action_provider, reps)
        builder.run
      end
    end

    def self.view_context_for(site)
      Nanoc::ViewContext.new(
        reps: reps_for(site),
        items: site.items,
        dependency_tracker: Nanoc::Int::DependencyTracker::Null.new,
        compiler: nil,
      )
    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

8 entries across 8 versions & 1 rubygems

Version Path
nanoc-4.4.4 lib/nanoc/cli/commands/shell.rb
nanoc-4.4.3 lib/nanoc/cli/commands/shell.rb
nanoc-4.4.2 lib/nanoc/cli/commands/shell.rb
nanoc-4.4.1 lib/nanoc/cli/commands/shell.rb
nanoc-4.4.0 lib/nanoc/cli/commands/shell.rb
nanoc-4.3.8 lib/nanoc/cli/commands/shell.rb
nanoc-4.3.7 lib/nanoc/cli/commands/shell.rb
nanoc-4.3.6 lib/nanoc/cli/commands/shell.rb