From f1fbaf6668f6810c24f8db563b2d14381b8ffd03 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Tue, 16 Nov 2021 12:55:37 +0900 Subject: [PATCH] add comment page and element_matcher --- src/mechanize/page.cr | 7 +++---- src/mechanize/utils/element_matcher.cr | 15 ++++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mechanize/page.cr b/src/mechanize/page.cr index eb5a8ad..ed30d25 100644 --- a/src/mechanize/page.cr +++ b/src/mechanize/page.cr @@ -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 diff --git a/src/mechanize/utils/element_matcher.cr b/src/mechanize/utils/element_matcher.cr index 70c2056..b1a2e5f 100644 --- a/src/mechanize/utils/element_matcher.cr +++ b/src/mechanize/utils/element_matcher.cr @@ -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 {
} - # page.form_with("foo") + # # like <{{ singular.id }} name="foo"></form> + # page.{{ plural.id }}_with("foo") # - # # you can specify tag's attribute and its' value by NamedTuple or Hash(String, String). - # ex)
- # 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) <{{ singular.id }} class="foo"></form> + # 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.