add element matcher comment

This commit is contained in:
Kanezoh 2021-11-16 17:40:42 +09:00
parent b3c4c46616
commit cdf1299c27
2 changed files with 24 additions and 3 deletions

View File

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

View File

@ -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"></{{ singular.id }}>
{% elsif "#{singular.id}" == "field" %}
# # like <input name="foo"></input>
{% elsif "#{singular.id}" == "radiobutton" %}
# # like <input type="radio" name="foo"></input>
{% else %}
# # like <input type="{{ singular.id }}" name="foo"></input>
{% end %}
# page.{{ plural.id }}_with("foo")
#
# # you can also specify tag's attribute and its' value by NamedTuple or Hash(String, String).
# ex) &lt;{{ singular.id }} class="foo"&gt;&lt;/form&gt;
{% if ["form", "button"].includes?("#{singular.id}") %}
# # ex) <{{ singular.id }} class="foo"></{{ singular.id }}>
{% elsif "#{singular.id}" == "field" %}
# # ex) <input class="foo"></input>
{% elsif "#{singular.id}" == "radiobutton" %}
# # ex) <input type="radio" class="foo"></input>
{% else %}
# # ex) <input type="{{ singular.id }}" class="foo"></input>
{% end %}
# page.{{ plural.id }}_with("class" => "foo")
# page.{{ plural.id }}_with(class: "foo")
# ```