Merge pull request #1229 from altern8tif/goodie_name_days

Name Days: Set max-width on table
master
Zaahir Moolla 2015-09-14 22:12:36 -04:00
commit 7a62a91ec4
3 changed files with 55 additions and 47 deletions

View File

@ -37,18 +37,18 @@ my %dates = share('preprocessed_dates.txt')->slurp(iomode => '<:encoding(UTF-8)'
sub parse_other_date_formats {
# Quick fix for the date formats not supported by parse_datestring_to_date.
# If parse_datestring_to_date will be improved, you can remove some of the following code.
# US date format ("month/day")
if (/^([0-1]?[0-9])\s?\/\s?([0-3]?[0-9])$/) {
# Suppress errors for invalid dates with eval
return eval { new DateTime(year => 2000, day => $2, month => $1) };
}
# Polish date format ("day.month")
if (/^([0-3]?[0-9])\s?\.\s?([0-1]?[0-9])$/) {
return eval { new DateTime(year => 2000, day => $1, month => $2) };
}
# Polish month names
s/\b(styczeń|stycznia)\b/Jan/i;
s/\b(luty|lutego)\b/Feb/i;
@ -62,7 +62,7 @@ sub parse_other_date_formats {
s/\b(październik|października)\b/Oct/i;
s/\b(listopad|listopada)\b/Nov/i;
s/\b(grudzień|grudnia)\b/Dec/i;
# Czech month names
s/\b(leden|ledna)\b/Jan/i;
s/\b(únor|února)\b/Feb/i;
@ -76,13 +76,13 @@ sub parse_other_date_formats {
s/\b(říjen|října)\b/Oct/i;
s/\b(listopad|listopadu)\b/Nov/i;
s/\b(prosinec|prosince)\b/Dec/i;
# Parse_datestring_to_date uses the current year if the year is not specified, so
# it will not parse "29 Feb" in a non-leap year. Fix this problem here.
if (/^29\s?(?:th)?\s*(Feb|February)/ || /(Feb|February)\s*29\s?(?:th)?$/) {
return new DateTime(year => 2000, day => 29, month => 2);
}
return parse_datestring_to_date($_);
}
@ -97,7 +97,7 @@ handle remainder => sub {
my $html;
my $query;
my $header;
if (exists $dates{lc($_)}) {
# Search by name first
$query = ucfirst($_);
@ -115,7 +115,7 @@ handle remainder => sub {
# Any leap year here, because the array includes February, 29
$day->set_year(2000);
my $suffix = 'th';
my $daynum = $day->day();
$suffix = 'st' if $daynum == 1 || $daynum == 21 || $daynum == 31;
@ -123,22 +123,23 @@ handle remainder => sub {
$suffix = 'rd' if $daynum == 3 || $daynum == 23;
$query = $day->month_name() . " $daynum$suffix";
$text = $names[$day->day_of_year() - 1];
# Convert to HTML
$html = $text;
$html =~ s/(\d{1,2}) (\w{1,3})/$1&nbsp;$2/g;
$html =~ s@(.*?): (.*?)(?:$|; )@'<tr><td class="name-days-country">' . get_flag($1) .
' <span class="name-days-country-name">' . $1 . '</span>' .
'</td><td class="name-days-dates">' . $2 . '</td></tr>'@ge;
$header = 'Name days on <b>' . html_enc($query) . '</b>';
}
# Add the header
$html = '<span>' . $header . '</span>' .
$html = '<div class="zci--name_days">' .
'<span>' . $header . '</span>' .
'<div class="zci__content"><table>' .
$html . '</table></div>';
$html . '</table></div></div>';
return $text, html => $html;
};

View File

@ -2,57 +2,64 @@
color: #333;
}
.name-days-country {
.zci--name_days .name-days-country {
padding-right: 2em;
white-space: nowrap;
vertical-align: top;
width: 25%;
}
.name-days-dates {
.zci--name_days .name-days-dates {
width: 75%;
}
.name-days-country-name, .name-days-tile {
.zci--name_days .name-days-country-name,
.zci--name_days .name-days-tile {
line-height: 1.6;
}
.name-days-country-name {
.zci--name_days .name-days-country-name {
vertical-align: middle;
padding-left: 0.4em;
}
.name-days-country .flag-sm {
.zci--name_days .name-days-country .flag-sm {
vertical-align: middle;
}
.name-days-country, .name-days-dates {
.zci--name_days .name-days-country,
.zci--name_days .name-days-dates {
border-bottom: solid 1px #DDD;
padding-top: 0.3em;
padding-bottom: 0.3em;
}
tr:last-of-type .name-days-country, tr:last-of-type .name-days-dates {
.zci--name_days tr:last-of-type .name-days-country,
.zci--name_days tr:last-of-type .name-days-dates {
border-bottom: none;
}
.name-days-tile span {
.zci--name_days .name-days-tile span {
padding: 0 0.5em 0 0;
}
.name-days-tile {
.zci--name_days .name-days-tile {
display: inline-block;
min-width: 33%;
}
@media (max-width: 600px) {
.name-days-tile {
.zci--name_days .name-days-tile {
min-width: 50%;
}
}
@media (max-width: 400px) {
.name-days-tile {
.zci--name_days .name-days-tile {
width: 100%;
}
}
.zci--name_days {
max-width: 44em;
}

View File

@ -19,12 +19,12 @@ sub get_flag {
sub header_name {
my $query = shift;
return '<span>Name days for <b>' . $query . '</b></span><div class="zci__content"><table>';
return '<div class="zci--name_days"><span>Name days for <b>' . $query . '</b></span><div class="zci__content"><table>';
}
sub header_date {
my $query = shift;
return '<span>Name days on <b>' . $query . '</b></span><div class="zci__content"><table>';
return '<div class="zci--name_days"><span>Name days on <b>' . $query . '</b></span><div class="zci__content"><table>';
}
sub line {
@ -39,7 +39,7 @@ sub tile {
return "<div class=\"name-days-tile\"><span>$month $days</span></div>";
}
my $footer = '</table></div>';
my $footer = '</table></div></div>';
@ -66,17 +66,17 @@ my $feb_29_html = header_date('February 29th') . line('Czech Republic', 'Horymí
my $dec_30_html = header_date('December 30th') . line('Croatia', 'Silvestar, Silvestrovo, Zahvalnica') . line('Czech Republic', 'David') .
line('Denmark', 'David') . line('France', 'Roger') . line('Hungary', 'Dávid'). line('Latvia', 'Dāvis, Dāvids').
line('Poland', 'Dawid, Eugeniusz, Katarzyna, Uniedrog') . line('Slovakia', 'Dávid, Lotar').
line('Poland', 'Dawid, Eugeniusz, Katarzyna, Uniedrog') . line('Slovakia', 'Dávid, Lotar').
line('Sweden', 'Abel, Set'). $footer;
my $dec_31_html = header_date('December 31st') . line('Czech Republic', 'Silvestr') . line('Denmark', 'Sylvester') .
line('France', 'Sylvestre') . line('Hungary', 'Szilveszter') . line('Latvia', 'Kalvis, Silvestris') .
line('Poland', 'Korneliusz, Melania, Sebastian, Sylwester, Tworzysław') .
line('Slovakia', 'Silvester, Horst') . line('Sweden', 'Sylvester') . $footer;
my $tamara_html = header_name('Tamara') . line('Czech Republic', tile('3', 'Jun')) . line('Hungary', tile('29', 'Dec')) .
line('Poland', tile('3', 'Jun')) . line('Slovakia', tile('26', 'Jan')) . $footer;
my $maria_poland = line('Poland', tile('23', 'Jan') . tile('2, 11', 'Feb') . tile('25', 'Mar') . tile('14, 26, 28', 'Apr') .
tile('3, 24, 25, 29', 'May') . tile('2, 13, 27', 'Jun') . tile('2, 16, 17, 22, 29', 'Jul') .
tile('2, 4, 5, 15, 22, 26', 'Aug') . tile('8, 12, 15, 24', 'Sep') .
@ -91,7 +91,7 @@ my $maria_html = header_name('Maria') . line('Bulgaria', tile('15', 'Aug')) .
ddg_goodie_test(
[qw( DDG::Goodie::NameDays )],
'name day mieszko' => test_zci('Poland: 1 Jan', html =>
header_name('Mieszko') . line('Poland', tile('1', 'Jan')) . $footer),
header_name('Mieszko') . line('Poland', tile('1', 'Jan')) . $footer),
'maria imieniny' => test_zci($maria, html => $maria_html),
'3 June name day' => test_zci('Croatia: Karlo Lwanga, dr.; Czech Republic: Tamara; Denmark: Erasmus; France: Kévin; ' .
'Greece: Marinos, Nikiforos; Hungary: Klotild, Cecília; Latvia: Inta, Dailis; ' .
@ -107,13 +107,13 @@ ddg_goodie_test(
'namedays dec 30' => test_zci($dec_30, html => $dec_30_html),
'name day 1 Jan' => test_zci('Bulgaria: Vassil; Croatia: Marija; Denmark: Nytårsdag; France: Jour de l\'An; ' .
'Greece: Basilius, Telemachus; Hungary: Fruzsina; Latvia: Solvija, Laimnesis; Poland: Mieczysław, Mieszko; Sweden: Nyårsdagen', html =>
header_date('January 1st') . line('Bulgaria', 'Vassil') . line('Croatia', 'Marija') . line('Denmark', 'Nytårsdag') .
header_date('January 1st') . line('Bulgaria', 'Vassil') . line('Croatia', 'Marija') . line('Denmark', 'Nytårsdag') .
line('France', 'Jour de l\'An') . line('Greece', 'Basilius, Telemachus') . line('Hungary', 'Fruzsina') .
line('Latvia', 'Solvija, Laimnesis') . line('Poland', 'Mieczysław, Mieszko') . line('Sweden', 'Nyårsdagen') . $footer),
'Radmila svátek' => test_zci('Croatia: 11 Apr; Czech Republic: 3 Jan; Slovakia: 3 Jan', html =>
header_name('Radmila') . line('Croatia', tile('11', 'Apr')) . line('Czech Republic', tile('3', 'Jan')) .
header_name('Radmila') . line('Croatia', tile('11', 'Apr')) . line('Czech Republic', tile('3', 'Jan')) .
line('Slovakia', tile('3', 'Jan')) . $footer),
# 1st, 2nd, 3rd, etc.
'imieniny Dec 22' => test_zci('Croatia: Ivan Kentijski, Viktorija; Czech Republic: Šimon; Denmark: Japetus; France: François Xavière; ' .
'Greece: Anastasias, Anastasia; Hungary: Zénó; Latvia: Donis, Donalds; ' .
@ -121,30 +121,30 @@ ddg_goodie_test(
'Sweden: Natanael, Jonatan', html =>
header_date('December 22nd') . line('Croatia', 'Ivan Kentijski, Viktorija') .
line('Czech Republic', 'Šimon') . line('Denmark', 'Japetus') . line('France', 'François Xavière') .
line('Greece', 'Anastasias, Anastasia') . line('Hungary', 'Zénó') . line('Latvia', 'Donis, Donalds') .
line('Poland', 'Beata, Drogomir, Franciszka, Zenon') .
line('Slovakia', 'Adela, Ada, Adelaida, Adelgunda, Adelína, Adina, Alida') .
line('Greece', 'Anastasias, Anastasia') . line('Hungary', 'Zénó') . line('Latvia', 'Donis, Donalds') .
line('Poland', 'Beata, Drogomir, Franciszka, Zenon') .
line('Slovakia', 'Adela, Ada, Adelaida, Adelgunda, Adelína, Adina, Alida') .
line('Sweden', 'Natanael, Jonatan') . $footer ),
'imieniny Aug 12' => test_zci('Croatia: Anicet, Hilarija; Czech Republic: Klára; Denmark: Clara; France: Clarisse; Hungary: Klára; ' .
'Latvia: Klāra, Vārpa; Poland: Klara, Lech, Piotr; Slovakia: Darina, Dárius, Dária; Sweden: Klara', html =>
header_date('August 12th') . line('Croatia', 'Anicet, Hilarija') .
line('Czech Republic', 'Klára') . line('Denmark', 'Clara') . line('France', 'Clarisse') .
line('Hungary', 'Klára') . line('Latvia', 'Klāra, Vārpa') . line('Poland', 'Klara, Lech, Piotr') .
header_date('August 12th') . line('Croatia', 'Anicet, Hilarija') .
line('Czech Republic', 'Klára') . line('Denmark', 'Clara') . line('France', 'Clarisse') .
line('Hungary', 'Klára') . line('Latvia', 'Klāra, Vārpa') . line('Poland', 'Klara, Lech, Piotr') .
line('Slovakia', 'Darina, Dárius, Dária') . line('Sweden', 'Klara') . $footer ),
# Genetive case
'imieniny marii' => test_zci($marii, html => $marii_html),
'imieniny Tamary' => test_zci("Poland: 3 Jun", html => header_name('Tamary') . line('Poland', tile('3', 'Jun')) . $footer),
'imieniny Tamara' => test_zci($tamara, html => $tamara_html),
'imieniny 29 Feb' => test_zci($feb_29, html => $feb_29_html),
'imieniny February 29th' => test_zci($feb_29, html => $feb_29_html),
# US date format
'name days 12/30' => test_zci($dec_30, html => $dec_30_html),
'name days 2/29' => test_zci($feb_29, html => $feb_29_html),
'name days 1 / 09' => test_zci($jan_9, html => $jan_9_html),
# Polish date formats
'imieniny 30.12' => test_zci($dec_30, html => $dec_30_html),
'imieniny 9.01' => test_zci($jan_9, html => $jan_9_html),
@ -155,13 +155,13 @@ ddg_goodie_test(
'imieniny 31 Grudnia' => test_zci($dec_31, html => $dec_31_html),
'Imieniny 31 GRUDNIA' => test_zci($dec_31, html => $dec_31_html),
'Imieniny 29 lutego' => test_zci($feb_29, html => $feb_29_html),
# Czech date formats
'svátek 9 ledna' => test_zci($jan_9, html => $jan_9_html),
'jmeniny 9 leden' => test_zci($jan_9, html => $jan_9_html),
'svátek 31 Prosince' => test_zci($dec_31, html => $dec_31_html),
'jmeniny 29 února' => test_zci($feb_29, html => $feb_29_html),
# Try to include some examples of queries on which it might
# appear that your answer will trigger, but does not.
'name day 12/32' => undef,