fake node

This commit is contained in:
Kanezoh 2021-05-26 13:49:37 +09:00
parent 62a178f0da
commit bd90c4032c
5 changed files with 10 additions and 15 deletions

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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