class Middleman::Cli::Build

The CLI Build class

def build

Returns:
  • (void) -
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
  
  self.class.shared_instance(options["verbose"] || false)
  
  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)
  self.class.shared_instance.run_hook :after_build, self
end

def exit_on_failure?

def exit_on_failure?
  true
end

def render_to_file(resource)

Returns:
  • (String) - The full path of the file that was written

Parameters:
  • resource (Middleman::Sitemap::Resource) --
def render_to_file(resource)
  build_dir = self.class.shared_instance.build_dir
  output_file = File.join(build_dir, resource.destination_path)
  begin
    response = self.class.shared_rack.get(URI.escape(resource.destination_path))
    if response.status == 200
      create_file(output_file, response.body, { :force => true })
    else
      raise Thor::Error.new response.body
    end
  rescue => e
    say_status :error, output_file, :red
    raise Thor::Error.new "#{e}\n#{e.backtrace.join("\n")}"
  end
  output_file
end

def shared_instance(verbose=false)

Returns:
  • (Middleman::Application) -
def shared_instance(verbose=false)
  @_shared_instance ||= ::Middleman::Application.server.inst do
    set :environment, :build
    set :logging,     verbose
  end
end

def shared_rack

Returns:
  • (Rack::Test::Session) -
def shared_rack
  @_shared_rack ||= begin
    mock = ::Rack::MockSession.new(shared_server.to_rack_app)
    sess = ::Rack::Test::Session.new(mock)
    response = sess.get("__middleman__")
    sess
  end
end

def shared_server

Returns:
  • (Middleman::Application) -
def shared_server
  @_shared_server ||= shared_instance.class
end

def source_root

Set the root path to the Middleman::Application's root
def source_root
  shared_instance.root
end