Navigation Menu

Skip to content

Commit

Permalink
support debug mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Dec 22, 2010
1 parent 6ebf3f9 commit 02ec92b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions app.rb
Expand Up @@ -16,6 +16,16 @@

include ERB::Util

@@configurations = {
:debug => false,
:rendering_mode => :big,
}
@@configurations[:debug] = true if ENV["RACK_ENV"] == "development"

def debug?
@@configurations[:debug]
end

get '/' do
erb :index
end
Expand Down Expand Up @@ -43,7 +53,8 @@ def make_surface(paper, scale, format, output, &block)
surface.write_to_png(output)
end
else
raise Sinatra::NotFound
raise "invalid format: #{format.inspect}" if debug?
not_found
end
end

Expand All @@ -52,7 +63,8 @@ def make_layout(context, text, width, height, font)
layout.text = text
layout.width = width * Pango::SCALE
unless @@font_families.any? {|family| family == font}
raise Sinatra::NotFound
raise "failed to find font family: #{font.inspect}" if debug?
not_found
end
font_description = Pango::FontDescription.new
font_description.family = font
Expand Down Expand Up @@ -227,7 +239,10 @@ def cache_public_file(data, *path)
def prepare_font_name(name)
if name.respond_to?(:force_encoding)
name.force_encoding("UTF-8")
raise Sintara::NotFound unless name.valid_encoding?
unless name.valid_encoding?
raise "invalid encoding name: #{name.inspect}" if debug?
not_found
end
end
name
end
Expand All @@ -243,7 +258,8 @@ def prepare_font_name(name)
"fonts", font, "thumbnails", "#{user}.#{format}")
nameplate
rescue
raise Sinatra::NotFound
raise if debug?
not_found
end
end

Expand All @@ -261,7 +277,8 @@ def prepare_font_name(name)
cache_public_file(nameplate, "fonts", font, "#{user}.#{format}")
nameplate
rescue
raise Sinatra::NotFound
raise if debug?
not_found
end
end

Expand All @@ -287,6 +304,7 @@ def prepare_font_name(name)
cache_putblic_file(nameplate, "#{user}.#{format}")
nameplate
rescue
raise Sinatra::NotFound
raise if debug?
not_found
end
end

0 comments on commit 02ec92b

Please sign in to comment.