lib/cuukie/server/server.rb in cuukie-0.3.0 vs lib/cuukie/server/server.rb in cuukie-0.3.1
- old
+ new
@@ -1,8 +1,7 @@
require 'rubygems'
require 'sinatra/base'
-require 'json'
require 'syntax/convertors/html'
module Cuukie
class Server < Sinatra::Base
set :features, []
@@ -111,15 +110,15 @@
helpers do
def code_snippet_for(exception)
return '' unless exception[:raw_lines]
result = '<pre class="ruby"><code>'
- linenum = exception[:first_line]
+ linenum = exception[:first_line].to_i
html_lines = htmlize(exception[:raw_lines]).split "\n"
html_lines.each do |html_line|
line = "<span class=\"linenum\">#{linenum}</span>#{html_line}"
- line = "<span class=\"offending\">#{line}</span>" if linenum == exception[:marked_line]
+ line = "<span class=\"offending\">#{line}</span>" if linenum.to_s == exception[:marked_line]
result << "#{line}<br/>"
linenum += 1
end
result << '</code></pre>'
end
@@ -188,20 +187,13 @@
def htmlize(ruby)
convertor = Syntax::Convertors::HTML.for_syntax("ruby")
convertor.convert(ruby, false)
end
- include Rack::Utils
-
def read_from_request
- data = JSON.parse request.body.read
result = {}
- data.each do |k, v|
- if v.class == String && k !~ /^raw_/
- result[k.to_sym] = escape_html(v)
- else
- result[k.to_sym] = v
- end
+ request.params.each do |k, v|
+ result[k.to_sym] = (k =~ /^raw_/) ? v : Rack::Utils.escape_html(v)
end
result
end
end
end