Class: Shutterbug::Rackapp
- Inherits:
-
Object
- Object
- Shutterbug::Rackapp
- Defined in:
- lib/shutterbug/rackapp.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #do_convert(req) ⇒ Object
-
#initialize(app) {|@config| ... } ⇒ Rackapp
constructor
A new instance of Rackapp.
Constructor Details
#initialize(app) {|@config| ... } ⇒ Rackapp
Returns a new instance of Rackapp.
6 7 8 9 10 11 12 |
# File 'lib/shutterbug/rackapp.rb', line 6 def initialize(app, &block) @config = Configuration.instance yield @config if block_given? @app = app @shutterbug = Service.new(@config) log "initialized" end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shutterbug/rackapp.rb', line 25 def call env req = Rack::Request.new(env) case req.path when @config.convert_regex do_convert(req) when @config.png_regex good_response(@shutterbug.get_png_file($1),'image/png') when @config.html_regex good_response(@shutterbug.get_html_file($1),'text/html') when @config.js_regex good_response(@shutterbug.get_shutterbug_file, 'application/javascript') else skip(env) end end |
#do_convert(req) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/shutterbug/rackapp.rb', line 14 def do_convert(req) html = req.POST()['content'] || "" width = req.POST()['width'] || 1000 height = req.POST()['height'] || 700 css = req.POST()['css'] || "" signature = @shutterbug.convert(@config.base_url(req), html, css, width, height) response_text = "<img src='#{@config.png_path(signature)}' alt='#{signature}'>" return good_response(response_text,'text/plain') end |