class Teaspoon::Exporter

Public Class Methods

new(suite, url, output_path) click to toggle source
# File lib/teaspoon/exporter.rb, line 5
def initialize(suite, url, output_path)
  @suite = suite
  @url = url
  @output_path = File.join(File.expand_path(output_path || "export"), @suite.to_s)
end

Public Instance Methods

export() click to toggle source
# File lib/teaspoon/exporter.rb, line 11
def export
  Dir.mktmpdir do |temp_path|
    Dir.chdir(temp_path) do
      %x{#{executable} --convert-links --adjust-extension --page-requisites --span-hosts #{@url.shellescape} 2>&1}
      raise Teaspoon::DependencyError.new("Unable to export #{@suite} suite.") unless $?.exitstatus == 0
      create_export(File.join(temp_path, @url.match(/^http:\/\/([^\/]+).*/)[1]))
    end
  end
end

Private Instance Methods

cleanup_output() click to toggle source
# File lib/teaspoon/exporter.rb, line 43
def cleanup_output
  FileUtils.rm_r(Dir["{.#{Teaspoon.configuration.mount_at},robots.txt.html}"])
end
create_export(path) click to toggle source
# File lib/teaspoon/exporter.rb, line 30
def create_export(path)
  Dir.chdir(path) do
    update_relative_paths
    cleanup_output
    move_output
  end
end
executable() click to toggle source
# File lib/teaspoon/exporter.rb, line 23
def executable
  return @executable if @executable
  @executable = which("wget")
  return @executable unless @executable.blank?
  raise Teaspoon::MissingDependencyError.new("Unable to locate `wget` for exporter.")
end
move_output() click to toggle source
# File lib/teaspoon/exporter.rb, line 47
def move_output
  FileUtils.mkdir_p(@output_path)
  FileUtils.mv(Dir["*"], @output_path, force: true)
end
update_relative_paths() click to toggle source
# File lib/teaspoon/exporter.rb, line 38
def update_relative_paths
  html = File.read(".#{Teaspoon.configuration.mount_at}/#{@suite}.html")
  File.write("index.html", html.gsub!('"../', '"'))
end