From bd90c4032c41f3d9617fa19aed6e20aa9808ccf7 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Wed, 26 May 2021 13:49:37 +0900 Subject: [PATCH] fake node --- src/mechanize.cr | 2 +- src/mechanize/form.cr | 4 ++-- src/mechanize/form/check_box.cr | 2 +- src/mechanize/form/field.cr | 2 +- src/mechanize/node.cr | 15 +++++---------- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/mechanize.cr b/src/mechanize.cr index 866d132..dd4a30c 100644 --- a/src/mechanize.cr +++ b/src/mechanize.cr @@ -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" diff --git a/src/mechanize/form.cr b/src/mechanize/form.cr index a8a7e67..a2f2c52 100644 --- a/src/mechanize/form.cr +++ b/src/mechanize/form.cr @@ -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 diff --git a/src/mechanize/form/check_box.cr b/src/mechanize/form/check_box.cr index e7fbb77..3f63318 100644 --- a/src/mechanize/form/check_box.cr +++ b/src/mechanize/form/check_box.cr @@ -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) diff --git a/src/mechanize/form/field.cr b/src/mechanize/form/field.cr index 8c2d4f1..10cb583 100644 --- a/src/mechanize/form/field.cr +++ b/src/mechanize/form/field.cr @@ -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 diff --git a/src/mechanize/node.cr b/src/mechanize/node.cr index 168d1dd..5591286 100644 --- a/src/mechanize/node.cr +++ b/src/mechanize/node.cr @@ -1,13 +1,8 @@ +# This is a fake node. +# Real node is represented by Myhtml::Node + class Node < Hash(String,String) - property fake : Bool - def initialize(fake = false) - @fake = fake - super() - end - - def search(str) - if fake - [] of Hash(String,String) - end + def css(str) + [] of Hash(String,String) end end