Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more consistent Mojo::DOM examples
  • Loading branch information
kraih committed Aug 15, 2014
1 parent e5a9187 commit 37c2bf7
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions lib/Mojo/DOM.pm
Expand Up @@ -513,9 +513,9 @@ All selectors from L<Mojo::DOM::CSS/"SELECTORS"> are supported.
Append HTML/XML fragment to this node.
# "<div><h1>One</h1><h2>Two</h2></div>"
$dom->parse('<div><h1>One</h1></div>')->at('h1')
->append('<h2>Two</h2>')->root;
# "<div><h1>Test</h1><h2>123</h2></div>"
$dom->parse('<div><h1>Test</h1></div>')->at('h1')
->append('<h2>123</h2>')->root;
# "<p>test 123</p>"
$dom->parse('<p>test</p>')->at('p')->contents->first->append(' 123')->root;
Expand All @@ -527,16 +527,16 @@ Append HTML/XML fragment to this node.
Append HTML/XML fragment or raw content (depending on node type) to this
node's content.
# "<div><h1>OneTwo</h1></div>"
$dom->parse('<div><h1>One</h1></div>')->at('h1')
->append_content('Two')->root;
# "<div><h1>Test123</h1></div>"
$dom->parse('<div><h1>Test</h1></div>')->at('h1')
->append_content('123')->root;
# "<!-- One Two --><br>"
$dom->parse('<!-- One --><br>')
->contents->first->append_content('Two ')->root;
# "<!-- Test 123 --><br>"
$dom->parse('<!-- Test --><br>')
->contents->first->append_content('123 ')->root;
# "<p>One<i>Two</i></p>"
$dom->parse('<p>One</p>')->at('p')->append_content('<i>Two</i>')->root;
# "<p>Test<i>123</i></p>"
$dom->parse('<p>Test</p>')->at('p')->append_content('<i>123</i>')->root;
=head2 at
Expand Down Expand Up @@ -584,20 +584,20 @@ Return this node's content or replace it with HTML/XML fragment or raw content
# "<b>test</b>"
$dom->parse('<div><b>test</b></div>')->div->content;
# "<div><h1>Two</h1></div>"
$dom->parse('<div><h1>One</h1></div>')->at('h1')->content('Two')->root;
# "<div><h1>123</h1></div>"
$dom->parse('<div><h1>Test</h1></div>')->at('h1')->content('123')->root;
# "<div><h1></h1></div>"
$dom->parse('<div><h1>Test</h1></div>')->at('h1')->content('')->root;
# " Test "
$dom->parse('<!-- Test --><br>')->contents->first->content;
# "<!-- Two --><br>"
$dom->parse('<!-- One --><br>')->contents->first->content(' Two ')->root;
# "<!-- 123 --><br>"
$dom->parse('<!-- Test --><br>')->contents->first->content(' 123 ')->root;
# "<p><i>Two</i></p>"
$dom->parse('<p>One</p>')->at('p')->content('<i>Two</i>')->root;
# "<p><i>123</i></p>"
$dom->parse('<p>Test</p>')->at('p')->content('<i>123</i>')->root;
=head2 contents
Expand Down Expand Up @@ -667,8 +667,8 @@ fragment if necessary.
Return L<Mojo::DOM> object for next sibling element or C<undef> if there are
no more siblings.
# "<h2>Two</h2>"
$dom->parse('<div><h1>One</h1><h2>Two</h2></div>')->at('h1')->next;
# "<h2>123</h2>"
$dom->parse('<div><h1>Test</h1><h2>123</h2></div>')->at('h1')->next;
=head2 next_sibling
Expand Down Expand Up @@ -710,9 +710,9 @@ Parse HTML/XML fragment with L<Mojo::DOM::HTML>.
Prepend HTML/XML fragment to this node.
# "<div><h1>One</h1><h2>Two</h2></div>"
$dom->parse('<div><h2>Two</h2></div>')->at('h2')
->prepend('<h1>One</h1>')->root;
# "<div><h1>Test</h1><h2>123</h2></div>"
$dom->parse('<div><h2>123</h2></div>')->at('h2')
->prepend('<h1>Test</h1>')->root;
# "<p>test 123</p>"
$dom->parse('<p>123</p>')->at('p')->contents->first->prepend('test ')->root;
Expand All @@ -724,16 +724,16 @@ Prepend HTML/XML fragment to this node.
Prepend HTML/XML fragment or raw content (depending on node type) to this
node's content.
# "<div><h2>OneTwo</h2></div>"
$dom->parse('<div><h2>Two</h2></div>')->at('h2')
->prepend_content('One')->root;
# "<div><h2>Test123</h2></div>"
$dom->parse('<div><h2>123</h2></div>')->at('h2')
->prepend_content('Test')->root;
# "<!-- One Two --><br>"
$dom->parse('<!-- Two --><br>')
->contents->first->prepend_content(' One')->root;
# "<!-- Test 123 --><br>"
$dom->parse('<!-- 123 --><br>')
->contents->first->prepend_content(' Test')->root;
# "<p><i>Two</i>One</p>"
$dom->parse('<p>One</p>')->at('p')->prepend_content('<i>Two</i>')->root;
# "<p><i>123</i>Test</p>"
$dom->parse('<p>Test</p>')->at('p')->prepend_content('<i>123</i>')->root;
=head2 previous
Expand Down Expand Up @@ -774,12 +774,12 @@ Remove this node and return L</"parent">.
Replace this node with HTML/XML fragment and return L</"parent">.
# "<div><h2>Two</h2></div>"
$dom->parse('<div><h1>One</h1></div>')->at('h1')->replace('<h2>Two</h2>');
# "<div><h2>123</h2></div>"
$dom->parse('<div><h1>Test</h1></div>')->at('h1')->replace('<h2>123</h2>');
# "<p><b>Two</b></p>"
$dom->parse('<p>One</p>')->at('p')
->contents->[0]->replace('<b>Two</b>')->root;
# "<p><b>123</b></p>"
$dom->parse('<p>Test</p>')->at('p')
->contents->[0]->replace('<b>123</b>')->root;
=head2 root
Expand Down Expand Up @@ -880,14 +880,14 @@ C<selected> attribute and extract their values.
Wrap HTML/XML fragment around this node, placing it as the last child of the
first innermost element.
# "<p>Two<b>One</b></p>"
$dom->parse('<b>One</b>')->at('b')->wrap('<p>Two</p>')->root;
# "<p>123<b>Test</b></p>"
$dom->parse('<b>Test</b>')->at('b')->wrap('<p>123</p>')->root;
# "<div><p><b>One</b></p>Two</div>"
$dom->parse('<b>One</b>')->at('b')->wrap('<div><p></p>Two</div>')->root;
# "<div><p><b>Test</b></p>123</div>"
$dom->parse('<b>Test</b>')->at('b')->wrap('<div><p></p>123</div>')->root;
# "<p><b>One</b></p><p>Two</p>"
$dom->parse('<b>One</b>')->at('b')->wrap('<p></p><p>Two</p>')->root;
# "<p><b>Test</b></p><p>123</p>"
$dom->parse('<b>Test</b>')->at('b')->wrap('<p></p><p>123</p>')->root;
# "<p><b>test</b></p>"
$dom->parse('<p>test</p>')->at('p')->contents->first->wrap('<b>')->root;
Expand All @@ -899,11 +899,11 @@ first innermost element.
Wrap HTML/XML fragment around this node's content, placing it as the last
children of the first innermost element.
# "<p><b>TwoOne</b></p>"
$dom->parse('<p>One<p>')->at('p')->wrap_content('<b>Two</b>')->root;
# "<p><b>123Test</b></p>"
$dom->parse('<p>Test<p>')->at('p')->wrap_content('<b>123</b>')->root;
# "<p><b>One</b></p><p>Two</p>"
$dom->parse('<b>One</b>')->wrap_content('<p></p><p>Two</p>');
# "<p><b>Test</b></p><p>123</p>"
$dom->parse('<b>Test</b>')->wrap_content('<p></p><p>123</p>');
=head2 xml
Expand All @@ -923,8 +923,8 @@ and consistent results you can also use L</"children">.
# "Test"
$dom->parse('<p>Test</p>')->p->text;
# "Two"
$dom->parse('<div>One</div><div>Two</div>')->div->[2]->text;
# "123"
$dom->parse('<div>Test</div><div>123</div>')->div->[2]->text;
# "test"
$dom->parse('<div>test</div>')->div->text;
Expand Down

0 comments on commit 37c2bf7

Please sign in to comment.