More itex Metal Refactoring

This commit is contained in:
Jacques Distler 2010-03-02 13:59:50 -06:00
parent e07960a897
commit 932c42c24a

View file

@ -14,9 +14,6 @@ class Itex
private private
ESTART = "<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>"
EEND = "</mtext></merror></math>"
# plugable XML parser; falls back to REXML # plugable XML parser; falls back to REXML
begin begin
require 'nokogiri' require 'nokogiri'
@ -30,6 +27,12 @@ class Itex
end end
end end
#error message to return
def self.error(str)
"<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><merror><mtext>" +
str + "</mtext></merror></math>"
end
# itex2MML parser # itex2MML parser
begin begin
require 'itextomml' require 'itextomml'
@ -38,10 +41,11 @@ class Itex
end end
rescue LoadError rescue LoadError
def self.parse_itex(tex, filter) def self.parse_itex(tex, filter)
ESTART + "Please install the itex2MML Ruby bindings." + EEND error("Please install the itex2MML Ruby bindings.")
end end
end end
# the actual response
def self.response(env) def self.response(env)
params = Rack::Request.new(env).params params = Rack::Request.new(env).params
tex = (params['tex'] || '').purify.strip tex = (params['tex'] || '').purify.strip
@ -59,13 +63,13 @@ class Itex
begin begin
xmlparse(doc) xmlparse(doc)
rescue rescue
return ESTART +"Ill-formed XML." + EEND return error("Ill-formed XML.")
end end
return doc return doc
rescue Itex2MML::Error => e rescue Itex2MML::Error => e
ESTART + e.to_s + EEND error(e.to_s)
rescue rescue
ESTART + "Unknown Error" + EEND error("Unknown Error")
end end
end end
end end