Class: Multigiri::HTML5::Forms

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

Overview

Browsers supporting HTML 5 should can submit forms through PUT or DELETE natively.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Forms

Returns a new instance of Forms.



11
12
13
# File 'lib/multigiri/html5.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/multigiri/html5.rb', line 15

def call(env)
  status, headers, document = @app.call(env)
  nodes = document.css("form[method=PUT]") + document.css("form[method=DELETE]")
  nodes.each do |form|
    input = Nokogiri::XML::Node.new("input", document)
    input["type"] = "hidden"
    input["name"] = "_method"
    input["value"] = form["method"]
    form["method"] = "POST"
    form.add_child(input)
  end
  [status, headers, document]
end