lib/pow-index.rb in pow-index-0.0.6 vs lib/pow-index.rb in pow-index-0.0.7
- old
+ new
@@ -4,34 +4,42 @@
module PowIndex
class App < Sinatra::Base
POW_PATH = "#{ENV['HOME']}/.pow"
+ IMAGE_PATH = "#{File.expand_path(File.dirname(__FILE__)).chomp}/../public/snaps/"
enable :inline_templates
+ def image_generation(link)
+ system "webkit2png -D #{IMAGE_PATH} -o #{link} -C http://#{link}.dev" unless link.eql?("default")
+ end
+
get '/' do
- @pows = (Dir[POW_PATH + "/*"] - [ "#{ENV['HOME']}/.pow/#{request.host.gsub(/.dev$/, '')}" ]).map { |link| File.basename(link)}
+ @pows = (Dir["#{POW_PATH}/*"] - [ "#{POW_PATH}/#{request.host.gsub(/.dev$/, '')}" ]).map { |link| File.basename(link)}
haml :index
end
get '/cleanup' do
require 'fileutils'
Dir[POW_PATH + "/*"].map { |symlink| FileUtils.rm(symlink) unless File.exists? File.readlink(symlink) }
@pows = Dir[POW_PATH + "/*"].map { |link| File.basename(link)}
## Snapshots generation
- path = "#{File.expand_path(File.dirname(__FILE__)).chomp}/../public/snaps/"
@snaps = Dir[POW_PATH + "/*"].map { |symlink|
link = symlink.rpartition("/").last
- system "webkit2png -D #{path} -o #{link} -C http://#{link}.dev" unless link.eql?("default")
+ image_generation(link)
}
haml :linktable
end
get '/linktable' do
- @pows = (Dir[POW_PATH + "/*"] - [ "#{ENV['HOME']}/.pow/#{request.host.gsub(/.dev$/, '')}" ]).map { |link| File.basename(link)}
+ @pows = (Dir["#{POW_PATH}/*"] - [ "#{POW_PATH}/#{request.host.gsub(/.dev$/, '')}" ]).map { |link| File.basename(link)}
haml :linktable
end
+
+ get '/regenerate/:link' do
+ image_generation(params[:link])
+ end
end
end
__END__
@@ -72,40 +80,47 @@
%li.pow
%a{:href => "http://#{pow}.dev"}
%img{:src => "snaps/#{pow}-clipped.png"}
%a.title{:href => "http://#{pow}.dev"}
= pow
+ .action
+ %a.reload.btn{:href => '#', :onClick => "regenerateImage('#{pow}')", :alt => 'Regenerate Image'}
+ %i.icon-refresh
@@ js
:javascript
function loadtable(){
- $('#linktable').load('/linktable', function() {
- tableCenter();
- });
-
+ $('#linktable').load('/linktable');
}
+
function cleanup() {
$.ajax({
type: "GET",
url: "/cleanup",
dataType: "html",
success: function(){
loadtable();
$('#toggle').modal('hide');
+ },
+ statusCode: {
+ 500: function() {
+ $('#toggle').modal('hide');
+ alert("Sorry, there is some problem");
+ }
}
- })
+ });
}
- function tableCenter() {
- windowH = $(window).height();
- tableH = $('#linktable').height();
- footerH = $('#footer').height();
- topPos = ((windowH - tableH) / 2) - footerH
- $('#linktable').css('top', topPos)
+
+ function regenerateImage(pow) {
+ $.ajax({
+ type: "GET",
+ url: "/regenerate/" + pow,
+ dataType: "html",
+ success: function(){
+ location.reload(true);
+ }
+ });
}
+
$(document).ready(function(){
- loadtable();
-
- $(window).resize(function() {
- tableCenter();
- });
-
+ loadtable();
});