fake node

master
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 end
def post(uri : String | URI, headers = HTTP::Headers.new, query : Hash(String, String | Array(String)) = Hash(String,String).new) 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["method"] = "POST"
node["enctype"] = "application/x-www-form-urlencoded" node["enctype"] = "application/x-www-form-urlencoded"

View File

@ -6,7 +6,7 @@ class MechanizeCr::Form
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox) getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
getter enctype : String getter enctype : String
def initialize(node : Node) def initialize(node : Node | Myhtml::Node)
@enctype = node["enctype"] || "application/x-www-form-urlencoded" @enctype = node["enctype"] || "application/x-www-form-urlencoded"
@node = node @node = node
@fields = Array(MechanizeCr::FormContent::Field).new @fields = Array(MechanizeCr::FormContent::Field).new
@ -49,7 +49,7 @@ class MechanizeCr::Form
def parse def parse
@fields = Array(MechanizeCr::FormContent::Field).new @fields = Array(MechanizeCr::FormContent::Field).new
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).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
end end

View File

@ -2,7 +2,7 @@ class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
property :checked property :checked
property :form 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"] @checked = !!node["checked"]
@form = form @form = form
super(node) super(node)

View File

@ -1,6 +1,6 @@
class MechanizeCr::FormContent::Field class MechanizeCr::FormContent::Field
property :node, :value, :name 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 @node = node
@name = name @name = name
#@raw_value = value #@raw_value = value

View File

@ -1,13 +1,8 @@
class Node < Hash(String,String) # This is a fake node.
property fake : Bool # Real node is represented by Myhtml::Node
def initialize(fake = false)
@fake = fake
super()
end
def search(str) class Node < Hash(String,String)
if fake def css(str)
[] of Hash(String,String) [] of Hash(String,String)
end
end end
end end