Author: kake
Date: 2012-03-13 17:24:05 +0000 (Tue, 13 Mar 2012)
New Revision: 1311
Added:
trunk/t/90_css_category_locale_classes.t
Modified:
trunk/Build.PL
trunk/Changes
trunk/MANIFEST
trunk/templates/node.tt
Log:
Add CSS classes for each category and locale to the "content" div (and hence we
now require version 2.24 of Template).
Modified: trunk/Build.PL
===================================================================
--- trunk/Build.PL 2012-03-06 09:35:12 UTC (rev 1310)
+++ trunk/Build.PL 2012-03-13 17:24:05 UTC (rev 1311)
@@ -304,7 +304,7 @@
'Parse::RecDescent' => 0,
$search_module => 0,
'POSIX' => 0,
- 'Template' => '2.15', # for
hash.delete and string.remove vmethods
+ 'Template' => '2.24', # for .lower
vmethod
'Time::Piece' => 0,
'URI::Escape' => 0,
'XML::RSS' => 0,
Modified: trunk/Changes
===================================================================
--- trunk/Changes 2012-03-06 09:35:12 UTC (rev 1310)
+++ trunk/Changes 2012-03-13 17:24:05 UTC (rev 1311)
@@ -4,6 +4,8 @@
<http://dev.openguides.org/log/trunk>.
0.66 ?
+ Add CSS classes for each category and locale to the "content" div
+ (and hence we now require version 2.24 of Template).
Switch to using Geo::Coordinates::OSGB/ITM instead of
Geography::NationalGrid (which no longer exists on CPAN).
Make sure that whitespace is collapsed in autocreated categories
Modified: trunk/MANIFEST
===================================================================
--- trunk/MANIFEST 2012-03-06 09:35:12 UTC (rev 1310)
+++ trunk/MANIFEST 2012-03-13 17:24:05 UTC (rev 1311)
@@ -154,6 +154,7 @@
t/84_navbar_admin.t
t/85_universal_edit_link.t
t/86_recent_changes.t
+t/90_css_category_locale_classes.t
t/templates/15_test.tt
wiki.cgi
META.json
Added: trunk/t/90_css_category_locale_classes.t
===================================================================
--- trunk/t/90_css_category_locale_classes.t (rev 0)
+++ trunk/t/90_css_category_locale_classes.t 2012-03-13 17:24:05 UTC (rev 1311)
@@ -0,0 +1,63 @@
+use strict;
+use Cwd;
+use OpenGuides;
+use OpenGuides::Test;
+use Test::More;
+
+eval { require DBD::SQLite; };
+if ( $@ ) {
+ my ($error) = $@ =~ /^(.*?)\n/;
+ plan skip_all =>
+ "DBD::SQLite could not be used - no database to test with. ($error)";
+}
+
+eval { require Test::HTML::Content; };
+if ( $@ ) {
+ plan skip_all => "Test::HTML::Content not installed";
+}
+
+plan tests => 3;
+
+my $config = OpenGuides::Test->make_basic_config;
+$config->custom_template_path( cwd . "/t/templates/" );
+my $guide = OpenGuides->new( config => $config );
+
+# Clear out the database from any previous runs.
+OpenGuides::Test::refresh_db();
+
+# Check that a node in one locale and one category has CSS classes for both.
+OpenGuides::Test->write_data(
+ guide => $guide,
+ node => "Crown",
+ categories => "Pubs",
+ locales => "Cornmarket",
+ return_output => 1,
+ );
+
+my $output = $guide->display_node( id => "Crown", return_output => 1
);
+Test::HTML::Content::tag_ok( $output, "div",
+ { id => "content", class => "cat_pubs loc_cornmarket" },
+ "Node in one locale and one category has CSS classes for both." );
+
+# Check that spaces in locale/category names are replaced by underscores.
+OpenGuides::Test->write_data(
+ guide => $guide,
+ node => "Debenhams",
+ categories => "Baby Changing",
+ locales => "Magdalen Street",
+ return_output => 1,
+ );
+$output = $guide->display_node( id => "Debenhams", return_output => 1
);
+Test::HTML::Content::tag_ok( $output, "div",
+ { id => "content", class => "cat_baby_changing
loc_magdalen_street" },
+ "...and spaces in locale/category names are replaced by underscores." );
+
+# Check that nodes with no locales or categories don't have classes added.
+OpenGuides::Test->write_data(
+ guide => $guide,
+ node => "A Blank Node",
+ return_output => 1,
+ );
+$output = $guide->display_node( id => "A Blank Node", return_output =>
1 );
+like( $output, qr|<div id="content">|,
+ "Nodes with no locales or categories don't have classes added." );
Modified: trunk/templates/node.tt
===================================================================
--- trunk/templates/node.tt 2012-03-06 09:35:12 UTC (rev 1310)
+++ trunk/templates/node.tt 2012-03-13 17:24:05 UTC (rev 1311)
@@ -1,7 +1,13 @@
[% USE CGI %]
[% INCLUDE header.tt %]
[% INCLUDE banner.tt %]
-<div id="content">
+
+[% IF categories.size OR locales.size %]
+ <div id="content" class="[% FOREACH cat = categories %]cat_[%
cat.name.lower.replace( ' ', '_' ) %][%- " " UNLESS (loop.last
AND !locales.size) %][% END %][% FOREACH loc=locales %]loc_[% loc.name.lower.replace(
' ', '_' ) %][%- " " UNLESS loop.last %][% END %]">
+[% ELSE %]
+ <div id="content">
+[% END %]
+
[% IF !config.content_above_navbar_in_html %]
[% INCLUDE navbar.tt %]
[% END %]