From cdf1299c27e65cd60bc2444fbb9c5aa141951fb6 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Tue, 16 Nov 2021 17:40:42 +0900 Subject: [PATCH] add element matcher comment --- src/mechanize/form.cr | 6 ++++++ src/mechanize/utils/element_matcher.cr | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/mechanize/form.cr b/src/mechanize/form.cr index 86da5bb..9be8082 100644 --- a/src/mechanize/form.cr +++ b/src/mechanize/form.cr @@ -8,14 +8,20 @@ require "./form/button" require "./form/select_list" require "./utils/element_matcher" +# THis class represents the form tag of html. class MechanizeCr::Form include MechanizeCr::ElementMatcher getter node : Node | Lexbor::Node + # returns an array of `MechanizeCr::FormContent::Field` in the form. getter fields : Array(FormContent::Field) + # returns an array of input tags whose type is checkbox in the form. getter checkboxes : Array(FormContent::CheckBox) + # returns an array of input tags whose type is radio in the form. getter radiobuttons : Array(FormContent::RadioButton) + # returns an array of input tags whose type is select in the form. getter selectboxes : Array(FormContent::MultiSelectList) + # returns an array of button tags and input tag whose type is button,submit,reset,image. getter buttons : Array(FormContent::Button) getter enctype : String getter method : String diff --git a/src/mechanize/utils/element_matcher.cr b/src/mechanize/utils/element_matcher.cr index b1a2e5f..0172f92 100644 --- a/src/mechanize/utils/element_matcher.cr +++ b/src/mechanize/utils/element_matcher.cr @@ -6,11 +6,26 @@ module MechanizeCr::ElementMatcher # Examples # ``` # # if you specify String like "foo", it searches form which name is "foo". - # # like <{{ singular.id }} name="foo"></form> + {% if ["form", "button"].includes?("#{singular.id}") %} + # # like <{{ singular.id }} name="foo"> + {% elsif "#{singular.id}" == "field" %} + # # like + {% elsif "#{singular.id}" == "radiobutton" %} + # # like + {% else %} + # # like + {% end %} # page.{{ plural.id }}_with("foo") - # # # you can also specify tag's attribute and its' value by NamedTuple or Hash(String, String). - # ex) <{{ singular.id }} class="foo"></form> + {% if ["form", "button"].includes?("#{singular.id}") %} + # # ex) <{{ singular.id }} class="foo"> + {% elsif "#{singular.id}" == "field" %} + # # ex) + {% elsif "#{singular.id}" == "radiobutton" %} + # # ex) + {% else %} + # # ex) + {% end %} # page.{{ plural.id }}_with("class" => "foo") # page.{{ plural.id }}_with(class: "foo") # ```