require 'base64' require 'turnip_formatter/step_template/exception' require 'gnawrnip/developer' module Gnawrnip class StepScreenshot < TurnipFormatter::StepTemplate::Exception on_failed :build def self.scss File.read(File.dirname(__FILE__) + '/gnawrnip.scss') end def build(example) images = example.metadata[:gnawrnip][:screenshot] case images.length when 0 '' when 1 single_image(images.first) else animation_image(images) end end private def animation_image(paths) text = <<-EOS
EOS text += develop(paths) text + <<-EOS
EOS end def single_image(path) text = '
' text += develop([path]) text + '
' end def develop(paths) paths.map do |path| image = developer.develop(path) image.to_html end.join end def developer @developer ||= Developer.new end end end TurnipFormatter.configure do |c| c.add_javascript('http://cdnjs.cloudflare.com/ajax/libs/jquery.cycle2/20130801/jquery.cycle2.min.js') c.add_stylesheet('http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css') c.add_javascript(File.dirname(__FILE__) + '/gnawrnip.js') end