class Middleman::Cli::Build
The CLI Build
class
Attributes
debugging[R]
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/middleman-core/cli/build.rb, line 80 def exit_on_failure? true end
source_root()
click to toggle source
Set the root path to the Middleman::Application
‘s root
# File lib/middleman-core/cli/build.rb, line 109 def source_root shared_instance.root end
Public Instance Methods
binary_encode(string)
click to toggle source
# File lib/middleman-core/cli/build.rb, line 164 def binary_encode(string) if string.respond_to?(:force_encoding) string.force_encoding("ascii-8bit") end string end
build()
click to toggle source
Core build Thor
command @return [void]
# File lib/middleman-core/cli/build.rb, line 43 def build if !ENV["MM_ROOT"] raise Thor::Error, "Error: Could not find a Middleman project config, perhaps you are in the wrong folder?" end # Use Rack::Test for inspecting a running server for output require "rack" require "rack/test" require 'find' @debugging = Middleman::Cli::Base.respond_to?(:debugging) && Middleman::Cli::Base.debugging @had_errors = false self.class.shared_instance(options["verbose"], options["instrument"]) self.class.shared_rack opts = {} opts[:glob] = options["glob"] if options.has_key?("glob") opts[:clean] = options["clean"] if options.has_key?("clean") action GlobAction.new(self, opts) if @had_errors && !@debugging cmd = "middleman build --verbose" cmd = "bundle exec '#{cmd}'" if defined?(Bundler) self.shell.say "There were errors during this build, re-run with `#{cmd}` to see the full exception." end exit(1) if @had_errors self.class.shared_instance.run_hook :after_build, self end
handle_error(file_name, response, e=Thor::Error.new(response))
click to toggle source
# File lib/middleman-core/cli/build.rb, line 152 def handle_error(file_name, response, e=Thor::Error.new(response)) @had_errors = true say_status :error, file_name, :red if self.debugging raise e exit(1) elsif options["verbose"] self.shell.error(response) end end
render_to_file(resource)
click to toggle source
Render a resource to a file.
@param [Middleman::Sitemap::Resource] resource @return [String] The full path of the file that was written
# File lib/middleman-core/cli/build.rb, line 119 def render_to_file(resource) build_dir = self.class.shared_instance.build_dir output_file = File.join(build_dir, resource.destination_path) if resource.binary? if !File.exists?(output_file) say_status :create, output_file, :green elsif FileUtils.compare_file(resource.source_file, output_file) say_status :identical, output_file, :blue return output_file else say_status :update, output_file, :yellow end FileUtils.mkdir_p(File.dirname(output_file)) FileUtils.cp(resource.source_file, output_file) else begin response = self.class.shared_rack.get(URI.escape(resource.destination_path)) if response.status == 200 create_file(output_file, binary_encode(response.body)) else handle_error(output_file, response.body) end rescue => e handle_error(output_file, "#{e}\n#{e.backtrace.join("\n")}", e) end end output_file end