Skip to content

Commit

Permalink
Revert "Use conneg"
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Pikesley committed Jan 11, 2016
1 parent e38982f commit 9d82031
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -8,7 +8,6 @@ gem 'rake'
gem 'kramdown'
gem 'activesupport'
gem 'rack-google-analytics'
gem 'rack-conneg'
gem 'chunky_png'
gem 'actionpack' #, '~> 4'

Expand Down
5 changes: 1 addition & 4 deletions Gemfile.lock
Expand Up @@ -113,8 +113,6 @@ GEM
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
rack-conneg (0.1.5)
rack (>= 1.0)
rack-google-analytics (1.2.0)
actionpack
activesupport
Expand Down Expand Up @@ -206,7 +204,6 @@ DEPENDENCIES
guard-rspec
haml
kramdown
rack-conneg
rack-google-analytics
rack-test
rake
Expand All @@ -217,4 +214,4 @@ DEPENDENCIES
thin

BUNDLED WITH
1.11.2
1.10.6
2 changes: 1 addition & 1 deletion config.ru
@@ -1,4 +1,4 @@
require 'rubygems'
require File.join(File.dirname(__FILE__), 'lib/uncle_clive.rb')

run Spectrum
run UncleClive
75 changes: 36 additions & 39 deletions lib/uncle_clive.rb
Expand Up @@ -11,23 +11,10 @@
require 'haml'
require 'kramdown'
require 'rack-google-analytics'
require 'rack/conneg'

class Spectrum < Sinatra::Base
use Rack::GoogleAnalytics, :tracker => 'UA-20895204-11'

use Rack::Conneg do |conneg|
conneg.set :accept_all_extensions, false
conneg.set :fallback, :html
conneg.ignore('/css/')
conneg.provide [
:html,
:json,
:text,
:png
]
end

@@locals = {
# :bootstrap_theme => '../lavish-bootstrap.css',
:additional_styles => [
Expand All @@ -49,37 +36,47 @@ class Spectrum < Sinatra::Base
end

get '/:text' do
respond params[:data]
end

post '/:text' do
respond params[:text]
end

def respond text
cs = UncleClive::FontGenerator.new

respond_to do |wants|
wants.json do
cs.formatter = UncleClive::Formatters::JSONFormatter.new
cs[params[:text]]
end
request.accept.each do |type|
case type.to_s

wants.html do
cs.formatter = UncleClive::Formatters::HTMLTableFormatter.new
haml :tabliser, :locals => @@locals.merge(
{
:title => params[:text],
:table => cs[params[:text]]
}
)
end
when 'application/json'
cs.formatter = UncleClive::Formatters::JSONFormatter.new
halt cs[params[:text]]

wants.text do
cs.formatter = UncleClive::Formatters::TextFormatter.new
cs.formatter.on = "[]"
cs[params[:text]]
end
when 'text/html'
cs.formatter = UncleClive::Formatters::HTMLTableFormatter.new
halt haml :tabliser, :locals => @@locals.merge(
{
:title => params[:text],
:table => cs[params[:text]]
}
)

when 'text/plain'
cs.formatter = UncleClive::Formatters::TextFormatter.new
cs.formatter.on = "[]"
halt cs[params[:text]]

when 'image/png'
cs.formatter = UncleClive::Formatters::PNGFormatter.new
content_type 'image/png'
f = File.open('x.png', 'w')
f.write cs[params[:text]]
f.close
redirect '/x.png'

wants.png do
cs.formatter = UncleClive::Formatters::PNGFormatter.new
content_type 'image/png'
f = File.open('x.png', 'w')
f.write cs[params[:text]]
f.close
redirect '/x.png'
else
halt "Nothing to see here"
end
end
end
Expand Down

0 comments on commit 9d82031

Please sign in to comment.