Class: Hollandaise::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/hollandaise/cli.rb

Instance Method Summary collapse

Instance Method Details

#cookObject



10
11
12
# File 'lib/hollandaise/cli.rb', line 10

def cook
  Hollandaise.projects.each(&:run)
end

#project(name) ⇒ Object



15
16
17
18
19
# File 'lib/hollandaise/cli.rb', line 15

def project(name)
  @name = name

  template 'hollandaise.rb.tt', 'hollandaise.rb'
end

#sauce(*browsers) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/hollandaise/cli.rb', line 23

def sauce(*browsers)
  if browsers.first && browsers.first[%r{^http}]
    url = browsers.shift
  else
    url = Hollandaise.url
  end

  if Hollandaise.browsers && browsers.empty?
    browsers = Hollandaise.browsers
  end

  browser_objects = Hollandaise::Browsers.for(browsers, options)

  browser_objects.run do |browser|
    browser.run_and_take_screenshot(url)
  end

  html = Arbre::Context.new do
    html do
      head do
        title "Sauce Labs screenshots for #{url}" 
      end

      body do
        table do
          thead do
            tr do
              browser_objects.each do |browser|
                th browser.browser
              end
            end
          end

          tbody do
            browser_objects.each do |browser|
              td(:valign => :top) do
                img(:src => browser.target)
              end
            end
          end
        end
      end
    end
  end

  File.open('index.html', 'wb') { |fh| fh.print html.to_s }
end