r76045 - in /trunk/libhtml-tagcloud-perl: CHANGES META.yml Makefile.PL README debian/changelog debian/control debian/copyright lib/HTML/TagCloud.pm
fabreg-guest at users.alioth.debian.org
fabreg-guest at users.alioth.debian.org
Sat Jun 18 21:20:10 UTC 2011
Author: fabreg-guest
Date: Sat Jun 18 21:20:08 2011
New Revision: 76045
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=76045
Log:
* New upstream release.
* Bump to 3.9.2 Standard-Version.
* Add myself to Uploaders and Copyright.
Modified:
trunk/libhtml-tagcloud-perl/CHANGES
trunk/libhtml-tagcloud-perl/META.yml
trunk/libhtml-tagcloud-perl/Makefile.PL
trunk/libhtml-tagcloud-perl/README
trunk/libhtml-tagcloud-perl/debian/changelog
trunk/libhtml-tagcloud-perl/debian/control
trunk/libhtml-tagcloud-perl/debian/copyright
trunk/libhtml-tagcloud-perl/lib/HTML/TagCloud.pm
Modified: trunk/libhtml-tagcloud-perl/CHANGES
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/CHANGES?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/CHANGES (original)
+++ trunk/libhtml-tagcloud-perl/CHANGES Sat Jun 18 21:20:08 2011
@@ -1,4 +1,9 @@
CHANGES file for HTML::TagCloud:
+
+0.37 Fri Jun 17 17:30:47 MST 2011
+ - added a fix suggested by Juan Antonio Raygoza Garay
+ - added some missing documentation
+ - added a list of known contributors
0.36 Wed Feb 16 15:10:49 MST 2011
- use different styles to distinguish adjacent tags.
Modified: trunk/libhtml-tagcloud-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/META.yml?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/META.yml (original)
+++ trunk/libhtml-tagcloud-perl/META.yml Sat Jun 18 21:20:08 2011
@@ -1,19 +1,21 @@
---- #YAML:1.0
-name: HTML-TagCloud
-version: 0.36
-abstract: ~
-author: []
-license: unknown
-distribution_type: module
+---
+abstract: 'Generate An HTML Tag Cloud'
+author:
+ - 'Leon Brocard, C<< <acme at astray.com> >>.'
configure_requires:
- ExtUtils::MakeMaker: 0
+ Module::Build: 0.36
+generated_by: 'Module::Build version 0.3607'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: HTML-TagCloud
+provides:
+ HTML::TagCloud:
+ file: lib/HTML/TagCloud.pm
+ version: 0.37
requires:
- Test::More: 0
-no_index:
- directory:
- - t
- - inc
-generated_by: ExtUtils::MakeMaker version 6.48
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+ Test::More: 0
+resources:
+ license: http://dev.perl.org/licenses/
+version: 0.37
Modified: trunk/libhtml-tagcloud-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/Makefile.PL?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/Makefile.PL (original)
+++ trunk/libhtml-tagcloud-perl/Makefile.PL Sat Jun 18 21:20:08 2011
@@ -1,13 +1,14 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.03
+# Note: this file was auto-generated by Module::Build::Compat version 0.3607
use ExtUtils::MakeMaker;
WriteMakefile
(
- 'NAME' => 'HTML::TagCloud',
- 'VERSION_FROM' => 'lib/HTML/TagCloud.pm',
- 'PREREQ_PM' => {
- 'Test::More' => '0'
- },
- 'INSTALLDIRS' => 'site',
- 'PL_FILES' => {}
- )
+ 'NAME' => 'HTML::TagCloud',
+ 'VERSION_FROM' => 'lib/HTML/TagCloud.pm',
+ 'PREREQ_PM' => {
+ 'Test::More' => '0'
+ },
+ 'INSTALLDIRS' => 'site',
+ 'EXE_FILES' => [],
+ 'PL_FILES' => {}
+)
;
Modified: trunk/libhtml-tagcloud-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/README?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/README (original)
+++ trunk/libhtml-tagcloud-perl/README Sat Jun 18 21:20:08 2011
@@ -2,18 +2,11 @@
HTML::TagCloud - Generate An HTML Tag Cloud
SYNOPSIS
- # A cloud with tags that link to other web pages.
my $cloud = HTML::TagCloud->new;
$cloud->add($tag1, $url1, $count1);
$cloud->add($tag2, $url2, $count2);
$cloud->add($tag3, $url3, $count3);
my $html = $cloud->html_and_css(50);
-
- # A cloud with tags that do not link to other web pages.
- my $cloud = HTML::TagCloud->new;
- $cloud->add_static($tag1, $count1);
- $cloud->add_static($tag2, $count2);
- $cloud->add_static($tag3, $count3);
DESCRIPTION
The HTML::TagCloud module enables you to generate "tag clouds" in HTML.
@@ -32,18 +25,11 @@
CONSTRUCTOR
new
- The constructor takes two optional arguments:
+ The constructor takes one optional argument:
my $cloud = HTML::TagCloud->new(levels=>10);
- if not provided, levels defaults to 24
-
- my $cloud = HTML::TagCloud->new(distinguish_adjacent_tags=>1);
-
- If distinguish_adjacent_tags is true HTML::TagCloud will use different
- CSS classes for adjacent tags in order to be able to make it easier to
- distinguish adjacent multi-word tags. If not specified, this parameter
- defaults to a false value.
+ if not provided, leves defaults to 24
METHODS
add
@@ -54,16 +40,9 @@
$cloud->add($tag2, $url2, $count2);
$cloud->add($tag3, $url3, $count3);
- add_static
- This module adds a tag that does not link to another web page into the
- cloud. You pass in the tag name and its count:
-
- $cloud->add_static($tag1, $count1);
- $cloud->add_static($tag2, $count2);
-
tags($limit)
Returns a list of hashrefs representing each tag in the cloud, sorted by
- alphabet. Each tag has the following keys: name, count, url and level.
+ alphabet. each tag has the following keys; name, count, url and level.
css
This returns the CSS that will format the HTML returned by the html()
@@ -90,7 +69,7 @@
Leon Brocard, "<acme at astray.com>".
COPYRIGHT
- Copyright (C) 2005-6, Leon Brocard
+ Copyright (C) 2005, Leon Brocard
This module is free software; you can redistribute it or modify it under
the same terms as Perl itself.
Modified: trunk/libhtml-tagcloud-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/debian/changelog?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/debian/changelog (original)
+++ trunk/libhtml-tagcloud-perl/debian/changelog Sat Jun 18 21:20:08 2011
@@ -1,3 +1,12 @@
+libhtml-tagcloud-perl (0.37-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+ * Bump to 3.9.2 Standard-Version.
+ * Add myself to Uploaders and Copyright.
+
+
+ -- Fabrizio Regalli <fabreg at fabreg.it> Sat, 18 Jun 2011 23:12:48 +0200
+
libhtml-tagcloud-perl (0.36-2) UNRELEASED; urgency=low
* Changed Priority in debian/control to extra to fix override disparity
Modified: trunk/libhtml-tagcloud-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/debian/control?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/debian/control (original)
+++ trunk/libhtml-tagcloud-perl/debian/control Sat Jun 18 21:20:08 2011
@@ -9,7 +9,8 @@
Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
Uploaders: Damyan Ivanov <dmn at debian.org>,
Chris Butler <chrisb at debian.org>
-Standards-Version: 3.9.1
+ Fabrizio Regalli <fabreg at fabreg.it>
+Standards-Version: 3.9.2
Homepage: http://search.cpan.org/dist/HTML-TagCloud/
Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libhtml-tagcloud-perl/
Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libhtml-tagcloud-perl/
Modified: trunk/libhtml-tagcloud-perl/debian/copyright
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/debian/copyright?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/debian/copyright (original)
+++ trunk/libhtml-tagcloud-perl/debian/copyright Sat Jun 18 21:20:08 2011
@@ -11,6 +11,7 @@
Copyright: 2005, Ben Hutchings <ben at decadentplace.org.uk>
2008, Ernesto Hernández-Novich (USB) <emhn at usb.ve>
2011, Chris Butler <chrisb at debian.org>
+ 2011, Fabrizio Regalli <fabreg at fabreg.it>
License: Artistic or GPL-1+
License: Artistic
Modified: trunk/libhtml-tagcloud-perl/lib/HTML/TagCloud.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libhtml-tagcloud-perl/lib/HTML/TagCloud.pm?rev=76045&op=diff
==============================================================================
--- trunk/libhtml-tagcloud-perl/lib/HTML/TagCloud.pm (original)
+++ trunk/libhtml-tagcloud-perl/lib/HTML/TagCloud.pm Sat Jun 18 21:20:08 2011
@@ -1,53 +1,65 @@
package HTML::TagCloud;
use strict;
use warnings;
-our $VERSION = '0.36';
+our $VERSION = '0.37';
+
+use constant EMPTY_STRING => q{};
sub new {
- my $class = shift;
- my $self = {
- counts => {},
- urls => {},
- levels => 24,
- distinguish_adjacent_tags => 0,
- @_
- };
- bless $self, $class;
- return $self;
+ my $class = shift;
+ my $self = {
+ counts => {},
+ urls => {},
+ category_for => {},
+ categories => [],
+ levels => 24,
+ distinguish_adjacent_tags => 0,
+ @_
+ };
+ bless $self, $class;
+ return $self;
}
sub add {
- my($self, $tag, $url, $count) = @_;
- $self->{counts}->{$tag} = $count;
- $self->{urls}->{$tag} = $url;
+ my ( $self, $tag, $url, $count, $category ) = @_;
+ $self->{counts}->{$tag} = $count;
+ $self->{urls}->{$tag} = $url;
+ if ( scalar @{ $self->{categories} } > 0 && defined $category ) {
+ $self->{category_for}->{$tag} = $category;
+ }
}
sub add_static {
- my ($self, $tag, $count) = @_;
+ my ( $self, $tag, $count, $category ) = @_;
$self->{counts}->{$tag} = $count;
+
+ if ( scalar @{ $self->{categories} } > 0 && defined $category ) {
+ $self->{category_for}->{$tag} = $category;
+ }
}
sub css {
- my ($self) = @_;
- my $css = q(
+ my ($self) = @_;
+ my $css = q(
#htmltagcloud {
text-align: center;
line-height: 1;
}
);
- foreach my $level (0 .. $self->{levels}) {
- if ( $self->{distinguish_adjacent_tags} ) {
- $css .= $self->_css_for_tag($level, 'even');
- $css .= $self->_css_for_tag($level, 'odd');
- } else {
- $css .= $self->_css_for_tag($level, q{});
- }
- }
- return $css;
+ foreach my $level ( 0 .. $self->{levels} ) {
+ if ( $self->{distinguish_adjacent_tags} ) {
+ $css .= $self->_css_for_tag( $level, 'even' );
+ $css .= $self->_css_for_tag( $level, 'odd' );
+ }
+ else {
+ $css .= $self->_css_for_tag( $level, q{} );
+ }
+ }
+ return $css;
}
sub _css_for_tag {
- my ($self, $level, $subclass) = @_;
+ my ( $self, $level, $subclass ) = @_;
my $font = 12 + $level;
return <<"END_OF_TAG";
span.tagcloud${level}${subclass} {font-size: ${font}px;}
@@ -56,93 +68,173 @@
}
sub tags {
- my($self, $limit) = @_;
- my $counts = $self->{counts};
- my $urls = $self->{urls};
- my @tags = sort { $counts->{$b} <=> $counts->{$a} } keys %$counts;
- @tags = splice(@tags, 0, $limit) if defined $limit;
-
- return unless scalar @tags;
-
- my $min = log($counts->{$tags[-1]});
- my $max = log($counts->{$tags[0]});
- my $factor;
-
- # special case all tags having the same count
- if ($max - $min == 0) {
- $min = $min - $self->{levels};
- $factor = 1;
- } else {
- $factor = $self->{levels} / ($max - $min);
- }
-
- if (scalar @tags < $self->{levels} ) {
- $factor *= (scalar @tags/$self->{levels});
- }
- my @tag_items;
- foreach my $tag (sort @tags) {
- my $tag_item;
- $tag_item->{name} = $tag;
- $tag_item->{count} = $counts->{$tag};
- $tag_item->{url} = $urls->{$tag};
- $tag_item->{level} = int((log($tag_item->{count}) - $min) * $factor);
- push @tag_items,$tag_item;
- }
- return @tag_items;
+ my ( $self, $limit ) = @_;
+ my $counts = $self->{counts};
+ my $urls = $self->{urls};
+ my $category_for = $self->{category_for};
+ my @tags = sort { $counts->{$b} <=> $counts->{$a} } keys %$counts;
+ @tags = splice( @tags, 0, $limit ) if defined $limit;
+
+ return unless scalar @tags;
+
+ my $min = log( $counts->{ $tags[-1] } );
+ my $max = log( $counts->{ $tags[0] } );
+ my $factor;
+
+ # special case all tags having the same count
+ if ( $max - $min == 0 ) {
+ $min = $min - $self->{levels};
+ $factor = 1;
+ }
+ else {
+ $factor = $self->{levels} / ( $max - $min );
+ }
+
+ if ( scalar @tags < $self->{levels} ) {
+ $factor *= ( scalar @tags / $self->{levels} );
+ }
+ my @tag_items;
+ foreach my $tag ( sort @tags ) {
+ my $tag_item;
+ $tag_item->{name} = $tag;
+ $tag_item->{count} = $counts->{$tag};
+ $tag_item->{url} = $urls->{$tag};
+ $tag_item->{level}
+ = int( ( log( $tag_item->{count} ) - $min ) * $factor );
+ $tag_item->{category} = $category_for->{$tag};
+ push @tag_items, $tag_item;
+ }
+ return @tag_items;
}
sub html {
- my($self, $limit) = @_;
- my @tags=$self->tags($limit);
-
- my $ntags = scalar(@tags);
- if ($ntags == 0) {
- return "";
- } elsif ($ntags == 1) {
- my $tag = $tags[0];
- my $span = $self->_format_span(@{$tag}{qw(name url)}, 1, 1);
- return qq{<div id="htmltagcloud">$span</div>\n};
- }
-
-# warn "min $min - max $max ($factor)";
-# warn(($min - $min) * $factor);
-# warn(($max - $min) * $factor);
-
- my $html = "";
- my $is_even = 1;
- foreach my $tag (@tags) {
- my $span = $self->_format_span(@{$tag}{qw(name url level)}, $is_even);
- $html .= "$span\n";
- $is_even = !$is_even;
- }
- $html = qq{<div id="htmltagcloud">
+ my ( $self, $limit ) = @_;
+ my $html
+ = scalar @{ $self->{categories} } > 0
+ ? $self->html_with_categories($limit)
+ : $self->html_without_categories($limit);
+ return $html;
+}
+
+sub html_without_categories {
+ my ( $self, $limit ) = @_;
+ my $html = $self->_html_for( [ $self->tags($limit) ] );
+}
+
+sub _html_for {
+ my ( $self, $tags_ref ) = @_;
+ my $ntags = scalar( @{$tags_ref} );
+ return EMPTY_STRING if $ntags == 0;
+
+ # Format the HTML division.
+ my $html
+ = $ntags == 1
+ ? $self->_html_for_single_tag($tags_ref)
+ : $self->_html_for_multiple_tags($tags_ref);
+
+ return $html;
+}
+
+sub _html_for_single_tag {
+ my ( $self, $tags_ref ) = @_;
+
+ # Format the contents of the div.
+ my $tag_ref = $tags_ref->[0];
+ my $html = $self->_format_span( @{$tag_ref}{qw(name url)}, 1, 1 );
+
+ return qq{<div id="htmltagcloud">$html</div>\n};
+}
+
+sub _html_for_multiple_tags {
+ my ( $self, $tags_ref ) = @_;
+
+ # Format the contents of the div.
+ my $html = EMPTY_STRING;
+ my $is_even = 1;
+ foreach my $tag ( @{$tags_ref} ) {
+ my $span
+ = $self->_format_span( @{$tag}{qw(name url level)}, $is_even );
+ $html .= "$span\n";
+ $is_even = !$is_even;
+ }
+ $html = qq{<div id="htmltagcloud">
$html</div>};
- return $html;
+ return $html;
+}
+
+sub html_with_categories {
+ my ( $self, $limit ) = @_;
+
+ # Get the collection of tags, organized by category.
+ my $tags_by_category_ref = $self->_tags_by_category($limit);
+ return EMPTY_STRING if !defined $tags_by_category_ref;
+
+ # Format the HTML document.
+ my $html = EMPTY_STRING;
+ CATEGORY:
+ for my $category ( @{ $self->{categories} } ) {
+ my $tags_ref = $tags_by_category_ref->{$category};
+ $html .= $self->_html_for_category( $category, $tags_ref );
+ }
+
+ return $html;
+}
+
+sub _html_for_category {
+ my ( $self, $category, $tags_ref ) = @_;
+
+ # Format the HTML.
+ my $html
+ = qq{<div class='$category'>}
+ . $self->_html_for($tags_ref)
+ . qq{</div>};
+
+ return $html;
+}
+
+sub _tags_by_category {
+ my ( $self, $limit ) = @_;
+
+ # Get the tags.
+ my @tags = $self->tags($limit);
+ return if scalar @tags == 0;
+
+ # Build the categorized collection of tags.
+ my %tags_by_category;
+ for my $tag_ref (@tags) {
+ my $category
+ = defined $tag_ref->{category}
+ ? $tag_ref->{category}
+ : '__unknown__';
+ push @{ $tags_by_category{$category} }, $tag_ref;
+ }
+
+ return \%tags_by_category;
}
sub html_and_css {
- my($self, $limit) = @_;
- my $html = qq{<style type="text/css">\n} . $self->css . "</style>";
- $html .= $self->html($limit);
- return $html;
+ my ( $self, $limit ) = @_;
+ my $html = qq{<style type="text/css">\n} . $self->css . "</style>";
+ $html .= $self->html($limit);
+ return $html;
}
sub _format_span {
- my ($self, $name, $url, $level, $is_even) = @_;
- my $subclass = q{};
- if ( $self->{distinguish_adjacent_tags} ) {
- $subclass = $is_even ? 'even' : 'odd';
- }
- my $span_class = qq{tagcloud$level$subclass};
- my $span = qq{<span class="$span_class">};
- if (defined $url) {
- $span .= qq{<a href="$url">};
- }
- $span .= $name;
- if (defined $url) {
- $span .= qq{</a>};
- }
- $span .= qq{</span>};
+ my ( $self, $name, $url, $level, $is_even ) = @_;
+ my $subclass = q{};
+ if ( $self->{distinguish_adjacent_tags} ) {
+ $subclass = $is_even ? 'even' : 'odd';
+ }
+ my $span_class = qq{tagcloud$level$subclass};
+ my $span = qq{<span class="$span_class">};
+ if ( defined $url ) {
+ $span .= qq{<a href="$url">};
+ }
+ $span .= $name;
+ if ( defined $url ) {
+ $span .= qq{</a>};
+ }
+ $span .= qq{</span>};
}
1;
@@ -167,7 +259,28 @@
$cloud->add_static($tag1, $count1);
$cloud->add_static($tag2, $count2);
$cloud->add_static($tag3, $count3);
-
+ my $html = $cloud->html_and_css(50);
+
+ # A cloud that is comprised of tags in multiple categories.
+ my $cloud = HTML::TagCloud->new;
+ $cloud->add($tag1, $url1, $count1, $category1);
+ $cloud->add($tag2, $url2, $count2, $category2);
+ $cloud->add($tag3, $url3, $count3, $category3);
+ my $html = $cloud->html_and_css(50);
+
+ # The same cloud without tags that link to other web pages.
+ my $cloud = HTML::TagCloud->new;
+ $cloud->add_static($tag1, $count1, $category1);
+ $cloud->add_static($tag2, $count2, $category2);
+ $cloud->add_static($tag3, $count3, $category3);
+ my $html = $cloud->html_and_css(50);
+
+ # Obtaining uncategorized HTML for a categorized tag cloud.
+ my $html = $cloud->html_without_categories();
+
+ # Explicitly requesting categorized HTML.
+ my $html = $cloud->html_with_categories();
+
=head1 DESCRIPTION
The L<HTML::TagCloud> module enables you to generate "tag clouds" in
@@ -188,7 +301,7 @@
=head2 new
-The constructor takes two optional arguments:
+The constructor takes a few optional arguments:
my $cloud = HTML::TagCloud->new(levels=>10);
@@ -201,6 +314,11 @@
distinguish adjacent multi-word tags. If not specified, this parameter
defaults to a false value.
+ my $cloud = HTML::TagCloud->new(categories=>\@categories);
+
+If categories are provided then tags are grouped in separate divisions by
+category when the HTML fragment is generated.
+
=head1 METHODS
=head2 add
@@ -235,11 +353,24 @@
=head2 html($limit)
This returns the tag cloud as HTML without the embedded CSS (you should
-use both css() and html() or simply the html_and_css() method). If a
-limit is provided, only the top $limit tags are in the cloud, otherwise
-all the tags are in the cloud:
+use both css() and html() or simply the html_and_css() method). If any
+categories were specified when items were being placed in the cloud then
+the tags will be organized into divisions by category name. If a limit
+is provided, only the top $limit tags are in the cloud, otherwise all the
+tags are in the cloud:
my $html = $cloud->html(200);
+
+=head2 html_with_categories($limit)
+
+This returns the tag cloud as HTML without the embedded CSS. The tags will
+be arranged into divisions by category. If a limit is provided, only the top
+$limit tags are in the cloud. Otherwise, all tags are in the cloud.
+
+=head2 html_without_categories($limit)
+
+This returns the tag cloud as HTML without the embedded CSS. The tags will
+not be grouped by category if this method is used to generate the HTML.
=head2 html_and_css($limit)
More information about the Pkg-perl-cvs-commits
mailing list