add comment page and element_matcher

master
Kanezoh 2021-11-16 12:55:37 +09:00
parent 4e0b85e791
commit f1fbaf6668
2 changed files with 11 additions and 11 deletions

View File

@ -2,10 +2,9 @@ require "./file"
require "./utils/element_matcher"
require "./page/link"
# This class represents the page of response.
# If you send request, it returns the instance of Page.
# You can get status code, title, and page body, and search html node using css selector.
# This class represents the result of http response.
# If you send a request, it returns the instance of `MechanizeCr::Page`.
# You can get status code, title, and page body, and search html node using css selector from page instance.
class MechanizeCr::Page < MechanizeCr::File
include MechanizeCr::ElementMatcher

View File

@ -1,18 +1,18 @@
module MechanizeCr::ElementMatcher
macro elements_with(singular, plural = "")
{% plural = "#{singular.id}s" if plural.empty? %}
# search {{ singular.id }} which matches condition.
# search {{ plural.id }} which match condition.
#
# Examples
# ```
# # if you specify String like "foo", it searches form which name is "foo".
# # like {<form name="foo"></form>}
# page.form_with("foo")
# # like &lt;{{ singular.id }} name="foo"&gt;&lt;/form&gt;
# page.{{ plural.id }}_with("foo")
#
# # you can specify tag's attribute and its' value by NamedTuple or Hash(String, String).
# ex) <form class="foo"></form>
# page.form_with("class" => "foo")
# page.form_with(class: "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;
# page.{{ plural.id }}_with("class" => "foo")
# page.{{ plural.id }}_with(class: "foo")
# ```
def {{plural.id}}_with(criteria : String | NamedTuple | Hash(String,String))
{{plural.id}}_with(criteria){}
@ -43,6 +43,7 @@ module MechanizeCr::ElementMatcher
f
end
# returns first element of `#{{ plural.id }}_with`
def {{singular.id}}_with(criteria)
f = {{plural.id}}_with(criteria)
# TODO: Write correct error message.