Method: Imaginizer::Parser.output

Defined in:
lib/imaginizer/parser.rb

.output(images, output) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/imaginizer/parser.rb', line 85

def self.output(images, output)
  case output
  when :image
    images.each {|image| `open #{image.image_path}`}
  when :html
    tmp_file = '/tmp/imaginizer.html'
    File.open tmp_file, 'w' do |f|
      f.write <<-HTML
  <!DOCTYPE html>
  <html>
    <head>
      <meta charset="UTF-8" />
      <style>
        body {background-color: #ccc}
        figure {float: left}
      </style>
      <title>Imaginizer output</title>
    </head>
    <body>
      #{images.map do |size, path|
        '<figure>' +
        '<img src="' + path + '" />' +
        '<figcaption>Size: ' + size.to_s + '</figcaption>' +
        '</figure>'
      end.join}
    </body>
  </html>
  HTML
    end
    `open #{tmp_file}`
  end
end