Class: Merb::Test::ViewHelper::DocumentOutput
- Defined in:
- lib/merb-core/test/helpers/view_helper.rb
Overview
Small utility class for working with the Hpricot parser class
Instance Method Summary collapse
-
#[](css_query) ⇒ Object
Parameters css_query<String>:: A CSS query to find the elements for.
-
#content_for(css_query) ⇒ Object
Parameters css_query<String>:: A CSS query to find the element for, e.g.
-
#content_for_all(css_query) ⇒ Object
Parameters css_query<String>:: A CSS query to find the elements for.
-
#initialize(response_body) ⇒ DocumentOutput
constructor
Parameters response_body<String>:: The response body to parse with Hpricot.
Constructor Details
#initialize(response_body) ⇒ DocumentOutput
Parameters
- response_body<String>
-
The response body to parse with Hpricot.
10 11 12 |
# File 'lib/merb-core/test/helpers/view_helper.rb', line 10 def initialize(response_body) @parser = Hpricot.parse(response_body) end |
Instance Method Details
#[](css_query) ⇒ Object
Parameters
- css_query<String>
-
A CSS query to find the elements for.
Returns
- Hpricot::Elements
-
All tags matching the query.
39 40 41 |
# File 'lib/merb-core/test/helpers/view_helper.rb', line 39 def [](css_query) @parser.search(css_query) end |
#content_for(css_query) ⇒ Object
Parameters
- css_query<String>
-
A CSS query to find the element for, e.g. “ul.links”.
Returns
- String
-
The content of the first tag matching the query.
20 21 22 23 |
# File 'lib/merb-core/test/helpers/view_helper.rb', line 20 def content_for(css_query) match = @parser.search(css_query).first match.inner_text unless match.nil? end |
#content_for_all(css_query) ⇒ Object
Parameters
- css_query<String>
-
A CSS query to find the elements for.
Returns
- Array
-
Content of all tags matching the query.
30 31 32 |
# File 'lib/merb-core/test/helpers/view_helper.rb', line 30 def content_for_all(css_query) matches = @parser.search(css_query).collect{|ele| ele.inner_text} end |