Class: Bridgetown::Commands::Console
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Bridgetown::Commands::Console
- Extended by:
- Summarizable
- Includes:
- ConfigurationOverridable
- Defined in:
- lib/bridgetown-core/commands/console.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#console ⇒ Object
rubocop:disable Metrics.
Methods included from Summarizable
Methods included from ConfigurationOverridable
#configuration_with_overrides, included
Class Method Details
.banner ⇒ Object
39 40 41 |
# File 'lib/bridgetown-core/commands/console.rb', line 39 def self. "bridgetown console [options]" end |
Instance Method Details
#console ⇒ Object
rubocop:disable Metrics
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/bridgetown-core/commands/console.rb', line 63 def console # rubocop:disable Metrics require "irb" new_history_behavior = false begin require "irb/ext/save-history" rescue LoadError # Code path for Ruby 3.3+ new_history_behavior = true end require "amazing_print" unless [:"bypass-ap"] Bridgetown.logger.adjust_verbosity() Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta} " \ "(codename \"#{Bridgetown::CODE_NAME.yellow}\") " \ "consoleā¦" Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan = configuration_with_overrides() if [:"server-config"] require "puma" require "bridgetown-core/rack/boot" Bridgetown::Rack.boot else .run_initializers! context: :console end site = Bridgetown::Site.new() ConsoleMethods.site_reset(site) unless [:blank] IRB::ExtendCommandBundle.include ConsoleMethods IRB.setup(nil) workspace = IRB::WorkSpace.new workspace.main.define_singleton_method(:site) { Bridgetown::Current.site } workspace.main.define_singleton_method(:collections) { site.collections } workspace.main.define_singleton_method(:helpers) do Bridgetown::RubyTemplateView::Helpers.new end irb = IRB::Irb.new(workspace) IRB.conf[:IRB_RC]&.call(irb.context) IRB.conf[:MAIN_CONTEXT] = irb.context irb.context.io.load_history if new_history_behavior Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}" Bridgetown.logger.info "", "You can also access #{"collections".cyan} or perform a " \ "#{"reload!".cyan}" trap("SIGINT") do irb.signal_handle end begin catch(:IRB_EXIT) do unless [:"bypass-ap"] AmazingPrint.defaults = { indent: 2, } AmazingPrint.irb! end irb.eval_input end ensure IRB.conf[:AT_EXIT].each(&:call) irb.context.io.save_history if new_history_behavior end end |