add comment page and element_matcher

This commit is contained in:
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 "./utils/element_matcher"
require "./page/link" require "./page/link"
# This class represents the page of response. # This class represents the result of http response.
# If you send request, it returns the instance of Page. # 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. # You can get status code, title, and page body, and search html node using css selector from page instance.
class MechanizeCr::Page < MechanizeCr::File class MechanizeCr::Page < MechanizeCr::File
include MechanizeCr::ElementMatcher include MechanizeCr::ElementMatcher

View File

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