Changes
CHANGES
lib/HTML/Element/Library.pm
+lib/HTML/Element/Library.pod
lib/HTML/Element/Library/Changes.pod
Makefile.PL
MANIFEST This list of files
t/Arsenal.pl
t/Arsenal.pm
t/content_handler.t
+t/crunch.t
t/data/3dig.dat
t/data/4dig.dat
t/data/table2.pm
+t/defmap.t
t/dual_iter.t
+t/fillinform.t
+t/hashmap.t
t/highlander.t
t/highlander2.t
t/HTML-Element-Library.t
+t/html/crunch/crunch.initial
+t/html/defmap/defmap.exp
+t/html/defmap/defmap.gen
+t/html/defmap/defmap.initial
t/html/dual_iter.exp
t/html/dual_iter.gen
t/html/dual_iter.html
+t/html/fillinform/fillinform.exp
+t/html/fillinform/fillinform.gen
+t/html/fillinform/fillinform.initial
t/html/highlander-15.exp
t/html/highlander-15.gen
t/html/highlander-5.exp
t/html/highlander2-27.gen
t/html/highlander2-5.exp
t/html/highlander2-5.gen
+t/html/highlander2-passover.exp
+t/html/highlander2-passover.gen
t/html/highlander2.html
t/html/iter.exp
t/html/iter.gen
t/html/iter2.exp
t/html/iter2.gen
t/html/iter2.html
+t/html/same_as.html
+t/html/same_as/same_as.exp
+t/html/same_as/same_as.gen
+t/html/same_as/same_as.initial
t/html/table-alt.exp
t/html/table-alt.gen
t/html/table-alt.html
t/m/TestUtils.pm
t/not-used/Arsenal.pl
t/not-used/Arsenal.pm
+t/passover.t
t/position.t
t/q
t/replace_content.t
}
+sub HTML::Element::crunch {
+ my $container = shift;
+
+ my %p = validate(@_, {
+ look_down => { type => ARRAYREF },
+ leave => { default => 1 },
+ });
+
+ my @look_down = @{$p{look_down}} ;
+ my @elem = $container->look_down( @look_down ) ;
+
+ my $left;
+
+ for my $elem (@elem) {
+ $elem->detach if $left++ >= $p{leave} ;
+ }
+
+}
sub HTML::Element::hash_map {
my $container = shift;
=head2 Tree Rewriting Methods
+=head3 "de-prepping" HTML
+
+Oftentimes, the HTML to be worked with will have multiple sample rows:
+
+ <OL>
+ <LI>bread
+ <LI>butter
+ <LI>beer
+ <LI>bacon
+ </OL>
+
+But, before you begin to rewrite the HTML with your model data, you typically only want 1 or 2 sample rows.
+
+Thus, you want to "crunch" the multiple sample rows to a specified amount. Hence the C<crunch> method:
+
+ $tree->crunch(look_down => [ '_tag' => 'li' ], leave => 2) ;
+
+The C<leave> argument defaults to 1 if not given. The call above would "crunch" the above 4 sample rows to:
+
+ <OL>
+ <LI>bread
+ <LI>butter
+ </OL>
+
+
=head3 Simplifying calls to HTML::FillInForm
Since HTML::FillInForm gets and returns strings, using HTML::Element instances
my $new_tree = $html_tree->fillinform($data_structure);
+
+
=head3 Mapping a hashref to HTML elements
It is very common to get a hashref of data from some external source - flat file, database, XML, etc.
--- /dev/null
+# This might look like shell script, but it's actually -*- perl -*-
+use strict;use warnings;
+use lib qw(t/ t/m/);
+
+use File::Slurp;
+use Test::More qw(no_plan);
+
+use TestUtils;
+use HTML::TreeBuilder;
+use HTML::Element::Library;
+
+sub tage {
+
+ my $root = "t/html/crunch/crunch";
+
+ my $tree = HTML::TreeBuilder->new_from_file("$root.initial")->guts;
+
+
+ $tree->crunch(look_down => [ class => 'imageElement' ], leave => 1);
+
+ my $generated_html = ptree($tree, "$root.gen");
+
+ is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for crunch");
+}
+
+
+tage();
+
--- /dev/null
+<html>
+ <head>
+<script src="smooth/scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
+<script src="smooth/scripts/mootools-1.2-more.js" type="text/javascript"></script>
+<script src="smooth/scripts/jd.gallery.js" type="text/javascript"></script>
+ <link rel="stylesheet" /="/" href="smooth/css/jd.gallery.css"
+ media="screen" type="text/css">
+ </head>
+ <body>
+<script type="text/javascript">
+function startGallery() {
+var myGallery = new gallery($('myGallery'), {
+timed: true
+});
+}
+window.addEvent('domready', startGallery);
+</script>
+ <div id="myGallery">
+ <div class="imageElement">
+ <h3>Item 1 Title</h3>
+ <p>Item 1 Description</p>
+ <a href="gallery-images/item-1/" title="open image" class="open"></a>
+ <img /="/" alt="Item 1 Title"
+ src="http://smoothgallery.jondesign.net/assets/images/samples/77196_6784-gallery.jpg"
+ class="full"> <img /="/" alt="thumbnail of Item 1 Title"
+ src="http://smoothgallery.jondesign.net/assets/images/samples/77196_6784-mini.jpg"
+ class="thumbnail"></div>
+ </div>
+ </body>
+</html>
--- /dev/null
+<html>
+ <head>
+
+ <script src="smooth/scripts/mootools-1.2.1-core-yc.js" type="text/javascript"></script>
+ <script src="smooth/scripts/mootools-1.2-more.js" type="text/javascript"></script>
+ <script src="smooth/scripts/jd.gallery.js" type="text/javascript"></script>
+
+ <link rel="stylesheet" href="smooth/css/jd.gallery.css" type="text/css" media="screen" />
+
+ </head>
+ <body>
+
+<script type="text/javascript">
+function startGallery() {
+var myGallery = new gallery($('myGallery'), {
+timed: true
+});
+}
+window.addEvent('domready', startGallery);
+</script>
+
+ <div id="myGallery">
+
+ <div class="imageElement">
+ <h3>Item 1 Title</h3>
+ <p>Item 1 Description</p>
+<a href="gallery-images/item-1/" title="open image" class="open"></a>
+
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/77196_6784-gallery.jpg" class="full" alt="Item 1 Title" />
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/77196_6784-mini.jpg" class="thumbnail" alt="thumbnail of Item 1 Title" />
+ </div>
+
+ <div class="imageElement">
+ <h3>Item 2 Title</h3>
+ <p>Item 2 Description</p>
+<a href="gallery-images/item-1/" title="open image" class="open"></a>
+
+ <img src="http://lh3.ggpht.com/_Pu5idg9RIVo/S1G0Krsr6iI/AAAAAAAAAB8/Hzl-tKkclmo/s640/IMG_0488.jpg" class="full" alt="Item 2 Title" />
+ <img src="http://lh3.ggpht.com/_Pu5idg9RIVo/S1G0Krsr6iI/AAAAAAAAAB8/Hzl-tKkclmo/s128/IMG_0488.jpg" class="thumbnail" alt="thumbnail of Item 2 Title" />
+ </div>
+
+ <div class="imageElement">
+ <h3>Item 2 Title</h3>
+ <p>Item 2 Description</p>
+<a href="gallery-images/item-1/" title="open image" class="open"></a>
+
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/165392_5486-gallery.jpg" class="full" alt="Item 2 Title" />
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/165392_5486-mini.jpg" class="thumbnail" alt="thumbnail of Item 2 Title" />
+ </div>
+
+ <div class="imageElement">
+
+ <h3>Item 3 Title</h3>
+ <p>Item 3 Description</p>
+<a href="gallery-images/item-1/" title="open image" class="open"></a>
+
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/83808_7948-gallery.jpg" class="full" alt="Item 3 Title" />
+ <img src="http://smoothgallery.jondesign.net/assets/images/samples/83808_7948-mini.jpg" class="thumbnail" alt="thumbnail of Item 3 Title" />
+ </div>
+ </div>
+
+
+ </body>
+
+</html>