Class: Bridgetown::Commands::New

Inherits:
Thor::Group
  • Object
show all
Extended by:
Summarizable
Includes:
GitHelpers, Thor::Actions
Defined in:
lib/bridgetown-core/commands/new.rb

Constant Summary collapse

DOCSURL =
"https://bridgetownrb.com/docs"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Summarizable

summary

Methods included from GitHelpers

#destroy_existing_repo, #initialize_new_repo, #user_default_branch

Class Attribute Details

.created_site_dirObject

Returns the value of attribute created_site_dir.



59
60
61
# File 'lib/bridgetown-core/commands/new.rb', line 59

def created_site_dir
  @created_site_dir
end

Class Method Details



14
15
16
# File 'lib/bridgetown-core/commands/new.rb', line 14

def self.banner
  "bridgetown new PATH"
end

.exit_on_failure?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bridgetown-core/commands/new.rb', line 50

def self.exit_on_failure?
  false
end

.source_rootObject



54
55
56
# File 'lib/bridgetown-core/commands/new.rb', line 54

def self.source_root
  File.expand_path("../../site_template", __dir__)
end

Instance Method Details

#new_siteObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bridgetown-core/commands/new.rb', line 62

def new_site
  raise ArgumentError, "You must specify a path." if args.empty?

  new_site_path = File.expand_path(args.join(" "), Dir.pwd)
  @site_name = new_site_path.split(File::SEPARATOR).last

  if preserve_source_location?(new_site_path, options)
    say_status :conflict, "#{new_site_path} exists and is not empty.", :red
    Bridgetown.logger.abort_with(
      "Ensure #{new_site_path} is empty or else try again with `--force` to proceed and " \
      "overwrite any files."
    )
  end

  self.destination_root = self.class.created_site_dir = new_site_path

  say_status :create, new_site_path
  create_site new_site_path
  after_install new_site_path, args.join(" "), options
rescue ArgumentError => e
  say_status :alert, e.message, :red
ensure
  self.class.created_site_dir = nil # reset afterwards, otherwise hanging tmp dirs in test
end