Sha256: 59bb0ecd268cb6f5eda904059fd32fe24f03ce8dadee21ebc480bd0b6585d27a

Contents?: true

Size: 1.33 KB

Versions: 11

Compression:

Stored size: 1.33 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
      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(:rule_dsl).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

11 entries across 11 versions & 1 rubygems

Version Path
nanoc-4.9.0 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.19 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.18 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.17 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.16 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.15 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.14 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.13 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.12 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.11 lib/nanoc/cli/commands/shell.rb
nanoc-4.8.10 lib/nanoc/cli/commands/shell.rb