fake node
parent
62a178f0da
commit
bd90c4032c
|
@ -20,7 +20,7 @@ class Mechanize
|
|||
end
|
||||
|
||||
def post(uri : String | URI, headers = HTTP::Headers.new, query : Hash(String, String | Array(String)) = Hash(String,String).new)
|
||||
node = Node.new(fake: true)
|
||||
node = Node.new
|
||||
node["method"] = "POST"
|
||||
node["enctype"] = "application/x-www-form-urlencoded"
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class MechanizeCr::Form
|
|||
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
||||
getter enctype : String
|
||||
|
||||
def initialize(node : Node)
|
||||
def initialize(node : Node | Myhtml::Node)
|
||||
@enctype = node["enctype"] || "application/x-www-form-urlencoded"
|
||||
@node = node
|
||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
||||
|
@ -49,7 +49,7 @@ class MechanizeCr::Form
|
|||
def parse
|
||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
||||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||
@node.search("input").not_nil!.each do |node|
|
||||
@node.css("input").not_nil!.each do |node|
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
|||
property :checked
|
||||
property :form
|
||||
|
||||
def initialize(node : Node, value : String = node.fetch("value", ""))
|
||||
def initialize(node : Node | Myhtml::Node, value : String = node.fetch("value", ""))
|
||||
@checked = !!node["checked"]
|
||||
@form = form
|
||||
super(node)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class MechanizeCr::FormContent::Field
|
||||
property :node, :value, :name
|
||||
def initialize(node : Node, value : String = node.fetch("value", ""), name : String = node.fetch("name", ""))
|
||||
def initialize(node : Node | Myhtml::Node, value : String = node.fetch("value", ""), name : String = node.fetch("name", ""))
|
||||
@node = node
|
||||
@name = name
|
||||
#@raw_value = value
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
class Node < Hash(String,String)
|
||||
property fake : Bool
|
||||
def initialize(fake = false)
|
||||
@fake = fake
|
||||
super()
|
||||
end
|
||||
# This is a fake node.
|
||||
# Real node is represented by Myhtml::Node
|
||||
|
||||
def search(str)
|
||||
if fake
|
||||
class Node < Hash(String,String)
|
||||
def css(str)
|
||||
[] of Hash(String,String)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue