Skip to content

Commit

Permalink
helper render script for previewing
Browse files Browse the repository at this point in the history
  • Loading branch information
evilmarty committed Aug 1, 2012
1 parent ec8ddb5 commit 07c83cd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Rakefile
Expand Up @@ -10,4 +10,18 @@ desc 'Start up server'
task :server do
require 'rack'
Rack::Server.start :Port => 3000, :environment => ENV['RACK_ENV'], :pid => nil, :Host => '0.0.0.0', :AccessLog => [], :config => 'config.ru'
end

desc 'Render equip'
task :render do
command = `which phantomjs`.strip
if $?.exitstatus == 1
puts "Please ensure phantom.js is installed and in your path."
exit -1
end

script = File.expand_path('../build/render.js', __FILE__)
output = ENV['OUTPUT'] || File.join(Dir.pwd, 'equip.jpg')

system "#{command} \"#{script}\" \"#{output}\""
end
29 changes: 29 additions & 0 deletions build/render.js
@@ -0,0 +1,29 @@
var page = require('webpage').create(),
output = phantom.args[0],
viewportWidth = parseInt(phantom.args[1]) || 1200;

if (!output) {
console.log("Usage: render.js <output file>");
phantom.exit(-1);
}

page.viewportSize = {width: viewportWidth, height: 400};
page.open("http://localhost:3000", function(status) {
if (!status) {
console.log("Could not connect to server. Ensure you've run `rake server` prior to running this script.");
phantom.exit(-1);
}

var viewport = page.evaluate(function() {
return {
width: document.body.clientWidth,
height: document.body.clientHeight
};
});
page.viewportSize = viewport;

console.log("Rendering equip to", output);
page.render(output);
console.log("Done.");
phantom.exit();
});

0 comments on commit 07c83cd

Please sign in to comment.