Skip to content

Instantly share code, notes, and snippets.

@bear454
Created September 11, 2009 18:23
Show Gist options
  • Save bear454/185475 to your computer and use it in GitHub Desktop.
Save bear454/185475 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'gdata'
PROJECT_PATH = "/your/project/path"
DOMAIN = 'your_google_apps_domain_or_blank_for_any_google_account.com'
get '/' do
if $client && params[:token] && !$token
$client.authsub_token = params[:token] # extract the single-use token from the URL query params
$token = $client.auth_handler.upgrade()
$client.authsub_token = $token
end
if $client && $token
docs_xml = $client.get('http://docs.google.com/feeds/documents/private/full?q=.feature').to_xml
list = "%ul\n"
$doc_ids = []
$doc_titles = []
docs_xml.elements.each('entry') do |entry|
# Extract the href value from each <atom:link>
links = {}
entry.elements.each('link') do |link|
links[link.attribute('rel').value] = link.attribute('href').value
end
$doc_ids << entry.elements['id'].text
$doc_titles << entry.elements['title'].text
updated_at = DateTime.parse(entry.elements['updated'].text) + DateTime.now.offset
list << " %li\n"
list << " %a{:href => \"#{links['alternate']}\"}Edit\n"
list << " %a{:href => \"/#{$doc_ids.size - 1}\"}Cucumber\n"
list << " %b #{entry.elements['title'].text}\n"
list << " (updated #{updated_at.strftime("%d %b %Y at %I:%M %p")})\n"
end
haml list
else
$client ||= GData::Client::DocList.new
redirect $client.authsub_url(request.url, false, true, DOMAIN)
end
end
get '/:doc_id' do
redirect('/') unless $doc_ids && $client
doc_xml = REXML::Document.new($client.get($doc_ids[params[:doc_id].to_i]).body)
txt_doc = $client.get(doc_xml.elements["//content"].attribute('src').value + '&exportFormat=txt')
feature_path = "#{PROJECT_PATH}/features/#{$doc_titles[params[:doc_id].to_i]}"
file = File.open(feature_path, "w")
file.print txt_doc.body
file.close
`cd #{PROJECT_PATH}\ncucumber -s -f html #{feature_path}`
end
get '/*' do
redirect('/')
end
__END__
@@ layout
!!! xml
!!!
%html
%body
= yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment