class Middleman::Cli::Build

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)
  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, 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