add form(s)_with method
This commit is contained in:
parent
33e94c110e
commit
301a58568e
@ -9,6 +9,7 @@ require "./utils/element_matcher"
|
||||
class MechanizeCr::Form
|
||||
include MechanzeCr::ElementMatcher
|
||||
|
||||
getter node : Node | Myhtml::Node
|
||||
getter fields : Array(FormContent::Field)
|
||||
getter checkboxes : Array(FormContent::CheckBox)
|
||||
getter radiobuttons : Array(FormContent::RadioButton)
|
||||
|
@ -1,6 +1,8 @@
|
||||
require "./file"
|
||||
require "./utils/element_matcher"
|
||||
|
||||
class MechanizeCr::Page < MechanizeCr::File
|
||||
include MechanzeCr::ElementMatcher
|
||||
delegate :css, to: parser
|
||||
|
||||
def initialize(uri, response, body, code)
|
||||
@ -27,4 +29,9 @@ class MechanizeCr::Page < MechanizeCr::File
|
||||
form
|
||||
end.to_a
|
||||
end
|
||||
|
||||
# generate form_with, forms_with methods
|
||||
# ex) form_with({:name => "login_form"})
|
||||
# it detects form(s) which match conditions.
|
||||
elements_with "form"
|
||||
end
|
||||
|
@ -10,9 +10,9 @@ module MechanzeCr::ElementMatcher
|
||||
if criteria.is_a?(String)
|
||||
criteria = {"name" => criteria}
|
||||
else
|
||||
# now,
|
||||
criteria = criteria.each_with_object(Hash(String,String).new) do |(k, v), h|
|
||||
h[k] = v
|
||||
# TODO: to deal with when key is "text"
|
||||
#case k = k.to_s
|
||||
#when "id"
|
||||
# h["id"] = v
|
||||
@ -25,7 +25,7 @@ module MechanzeCr::ElementMatcher
|
||||
end
|
||||
f = {{plural.id}}.select do |elm|
|
||||
criteria.all? do |k,v|
|
||||
v === elm.node.fetch(k,"x")
|
||||
v === elm.node.fetch(k,"")
|
||||
end
|
||||
end
|
||||
yield f
|
||||
|
Loading…
Reference in New Issue
Block a user