Sha256: 164976d5ed2fb0dbe61cb1d1b3b01047d87fd786574e89241a73009b2c5304af

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

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.
"
flag :p, :preprocess, 'run preprocessor'

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

      @site = load_site(preprocess: 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(: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,
        compilation_context: nil,
        snapshot_repo: 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

6 entries across 6 versions & 1 rubygems

Version Path
nanoc-4.8.9 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.8 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.7 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.6 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.5 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.4 lib/nanoc/cli/commands/shell.rb