lib/nanoc/cli/command_runner.rb in nanoc-3.5.0 vs lib/nanoc/cli/command_runner.rb in nanoc-3.6.0
- old
+ new
@@ -20,11 +20,11 @@
#
# @return [Nanoc::Site] The site in the current working directory
def site
# Load site if possible
@site ||= nil
- if File.file?('config.yaml') && @site.nil?
+ if self.is_in_site_dir? && @site.nil?
@site = Nanoc::Site.new('.')
end
@site
end
@@ -34,31 +34,44 @@
# @see http://rubydoc.info/gems/cri/Cri/CommandDSL#runner-instance_method
def self.call(opts, args, cmd)
self.new(opts, args, cmd).call
end
- protected
-
- # @return [Boolean] true if debug output is enabled, false if not
- #
- # @see Nanoc::CLI.debug?
- def debug?
- Nanoc::CLI.debug?
+ # @return [Boolean] true if the current working directory is a nanoc site
+ # directory, false otherwise
+ def is_in_site_dir?
+ Nanoc::Site.cwd_is_nanoc_site?
end
# Asserts that the current working directory contains a site
# ({Nanoc::Site} instance). If no site is present, prints an error
# message and exits.
#
# @return [void]
def require_site
- print "Loading site data… "
if site.nil?
- puts "error"
raise ::Nanoc::Errors::GenericTrivial, "The current working directory does not seem to be a nanoc site."
- else
- puts "done"
end
+ end
+
+ # Asserts that the current workign directory contains a site (just like
+ # {#require_site}) and loads the site into memory.
+ #
+ # @return [void]
+ def load_site
+ self.require_site
+ print "Loading site data… "
+ self.site.load
+ puts "done"
+ end
+
+ protected
+
+ # @return [Boolean] true if debug output is enabled, false if not
+ #
+ # @see Nanoc::CLI.debug?
+ def debug?
+ Nanoc::CLI.debug?
end
# Sets the data source's VCS to the VCS with the given name. Does nothing
# when the site's data source does not support VCSes (i.e. does not
# implement #vcs=).