Class: Multigiri::XML

Inherits:
HTML
  • Object
show all
Defined in:
lib/multigiri.rb

Constant Summary collapse

DEFAULT_TYPES =

XML has many MIME types, if you want to work with all posible XML MIME types, you can use use Multigiri, mime_type: /xml/

["text/xml"]

Constants inherited from HTML

HTML::CONTENT_LENGTH, HTML::CONTENT_TYPE

Instance Attribute Summary

Attributes inherited from HTML

#block, #options

Instance Method Summary collapse

Methods inherited from HTML

#call, #initialize, #use

Constructor Details

This class inherits a constructor from Multigiri::HTML

Instance Method Details

#run(env, status, headers, chunks) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/multigiri.rb', line 73

def run(env, status, headers, chunks)
  # the only what we know about body is that it has to respond to #each
  body = String.new
  chunks.each { |chunk| body += chunk }
  document = Nokogiri::XML(body) # before
  @stack = lambda { |env| [status, headers, document] }

  # get middlewares
  self.instance_eval(&@block) if @block

  # convert back to a [String]
  status, headers, document = @stack.call(env)
  body = document.to_xml(indentation: options[:indentation]) # TODO
  headers[CONTENT_LENGTH] = body.bytesize.to_s
  return [status, headers, [body]]
end