Tiles for months
parent
b659c5b5de
commit
fa5984b5e7
|
@ -89,12 +89,13 @@ sub parse_other_date_formats {
|
|||
# Handle statement
|
||||
handle remainder => sub {
|
||||
my $text;
|
||||
my $html;
|
||||
my $query;
|
||||
|
||||
if (exists $dates{lc($_)}) {
|
||||
# Search by name first
|
||||
$query = ucfirst($_);
|
||||
$text = $dates{lc($_)};
|
||||
($text, $html) = split('\|', $dates{lc($_)});
|
||||
} else {
|
||||
# Then, search by date
|
||||
my $day = parse_datestring_to_date($_);
|
||||
|
@ -110,12 +111,14 @@ handle remainder => sub {
|
|||
|
||||
$query = time2str( '%B %o', $day->epoch() );
|
||||
$text = $names[$day->day_of_year() - 1];
|
||||
|
||||
# Convert to HTML
|
||||
$html = $text;
|
||||
$html =~ s/(\d{1,2}) (\w{1,3})/$1 $2/g;
|
||||
$html =~ s@(.*?): (.*?)(?:$|; )@<tr><td class="name-days-country">$1</td><td>$2</td></tr>@g;
|
||||
}
|
||||
|
||||
# Convert to HTML
|
||||
my $html = $text;
|
||||
$html =~ s/(\d{1,2}) (\w{1,3})/$1 $2/g;
|
||||
$html =~ s@(.*?): (.*?)(?:$|; )@<tr><td style="padding-right: 10px;font-weight:bold">$1</td><td>$2</td></tr>@g;
|
||||
# Add the header
|
||||
$html = '<div class="zci__body"><span class="zci__header">' . $query . '</span>' .
|
||||
'<span class="zci__subheader">Name days</span><div class="zci__content"><table>' .
|
||||
$html . '</table></div></div>';
|
||||
|
|
|
@ -55,7 +55,7 @@ Bądzimir Damian Piotr Roma Seweryn | Bądzimira Damiana Piotra Romy Seweryna
|
|||
Bogurad Bogusz Boguta Maciej Piotr | Bogurada Bogusza Boguty Macieja Piotra
|
||||
Bolebor Cezary Maciej Małgorzata | Bolebora Cezarego Macieja Małgorzaty
|
||||
Aleksander Bogumił Cezariusz Mirosław Ewelina | Aleksandra Bogumiła Cezariusza Mirosława Eweliny
|
||||
Aleksander Anastazja Gabriel Gabriela Sierosława | Aleksandra Anastazji Gabriela Gabrieli Sierosławy
|
||||
Aleksander Anastazja Gabriel Gabriela Sierosława | Aleksandra Anastazji Gabrieli Sierosławy
|
||||
Józef Roman Lech | Józefa Romana Lecha
|
||||
Dobronieg Roman | Dobroniega Romana
|
||||
Albin Antoni Antonina Amelia Feliks Herakles Joanna Józef Piotr | Albina Antoniego Antoniny Amelii Feliksa Heraklesa Joanny Józefa Piotra
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
.name-days-country {
|
||||
padding-right: 0.5em; font-weight:bold;
|
||||
}
|
||||
|
||||
.name-days-tile {
|
||||
background-color: #fff;
|
||||
border: 1px solid #e3e3e3;
|
||||
display: inline-block;
|
||||
|
||||
margin:0.25em 0.25em;
|
||||
-webkit-border-radius:2px;
|
||||
-moz-border-radius:2px;
|
||||
-ms-border-radius:2px;
|
||||
-o-border-radius:2px;
|
||||
border-radius:2px;
|
||||
}
|
||||
|
||||
.name-days-tile-body {
|
||||
padding: 0.3em;
|
||||
}
|
||||
|
||||
.name-days-tile h4, .name-days-tile p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.name-days-tile h4 {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 1.3;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.name-days-tile p {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
|
@ -51,10 +51,12 @@ sub load_days_file {
|
|||
}
|
||||
|
||||
sub finish_loading {
|
||||
my @month_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
# Convert the dates to string
|
||||
for (keys %dates) {
|
||||
# Group the dates by country
|
||||
my %dates_by_country = ();
|
||||
my %dates_by_country_and_month = ();
|
||||
foreach (@{$dates{$_}}) {
|
||||
die 'Internal error' unless /^(.*?)\|(\d+)$/;
|
||||
# Any leap year here, because the text file includes February, 29
|
||||
|
@ -63,15 +65,33 @@ sub finish_loading {
|
|||
$dates_by_country{$1} .= ', ';
|
||||
}
|
||||
$dates_by_country{$1} .= $d->strftime('%e %b');
|
||||
|
||||
if ($dates_by_country_and_month{$1}[$d->month - 1]) {
|
||||
$dates_by_country_and_month{$1}[$d->month - 1] .= ', ';
|
||||
}
|
||||
$dates_by_country_and_month{$1}[$d->month - 1] .= $d->day;
|
||||
}
|
||||
|
||||
# Convert to string
|
||||
# Prepare the plain-text answer
|
||||
my $res = '';
|
||||
foreach (sort keys %dates_by_country) {
|
||||
$res .= $_ . ': ' . $dates_by_country{$_} . "; ";
|
||||
}
|
||||
$res =~ s/; $/\|/;
|
||||
|
||||
# Prepare the HTML answer
|
||||
foreach (sort keys %dates_by_country_and_month) {
|
||||
$res .= '<tr><td class="name-days-country">' . $_ . '</td><td>';
|
||||
my $i = 0;
|
||||
for (@{$dates_by_country_and_month{$_}}) {
|
||||
$res .= '<div class="name-days-tile"><div class="name-days-tile-body">' .
|
||||
'<h4>' . $_ . '</h4><p>' . $month_names[$i] . '</p>' .
|
||||
'</div></div>' if $_;
|
||||
$i++;
|
||||
}
|
||||
$res .= '</td></tr>';
|
||||
}
|
||||
|
||||
$res =~ s/; $//;
|
||||
$dates{$_} = $res;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
27
t/NameDays.t
27
t/NameDays.t
|
@ -19,7 +19,13 @@ sub header {
|
|||
|
||||
sub line {
|
||||
my ($country, $result) = @_;
|
||||
return '<tr><td style="padding-right: 10px;font-weight:bold">' . $country . '</td><td>' . $result . '</td></tr>';
|
||||
return '<tr><td class="name-days-country">' . $country . '</td><td>' . $result . '</td></tr>';
|
||||
}
|
||||
|
||||
sub tile {
|
||||
my ($days, $month) = @_;
|
||||
return '<div class="name-days-tile"><div class="name-days-tile-body">' .
|
||||
'<h4>' . $days . '</h4><p>' . $month . '</p></div></div>';
|
||||
}
|
||||
|
||||
my $footer = '</table></div></div>';
|
||||
|
@ -47,19 +53,18 @@ my $dec_30_html = header('December 30th') . line('Czech Republic', 'David') .
|
|||
my $dec_31_html = header('December 31st') . line('Czech Republic', 'Silvestr') . line('Hungary', 'Szilveszter') .
|
||||
line('Poland', 'Korneliusz, Melania, Sebastian, Sylwester, Tworzysław') . $footer;
|
||||
|
||||
my $tamara_html = header('Tamara') . line('Czech Republic', ' 3 Jun') . line('Hungary', '29 Dec') .
|
||||
line('Poland', ' 3 Jun') . $footer;
|
||||
my $marii_html = line('Poland', '23 Jan, 2 Feb, 11 Feb, 25 Mar, 14 Apr, ' .
|
||||
'26 Apr, 28 Apr, 3 May, 24 May, 25 May, 29 May, 2 Jun, 13 Jun, ' .
|
||||
'27 Jun, 2 Jul, 16 Jul, 17 Jul, 22 Jul, 29 Jul, 2 Aug, 4 Aug, ' .
|
||||
'5 Aug, 15 Aug, 22 Aug, 26 Aug, 8 Sep, 12 Sep, 15 Sep, 24 Sep, ' .
|
||||
'7 Oct, 11 Oct, 16 Nov, 21 Nov, 8 Dec, 10 Dec') . $footer;
|
||||
my $tamara_html = header('Tamara') . line('Czech Republic', tile('3', 'Jun')) . line('Hungary', tile('29', 'Dec')) .
|
||||
line('Poland', tile('3', 'Jun')) . $footer;
|
||||
my $marii_html = 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') .
|
||||
tile('7, 11', 'Oct') . tile('16, 21', 'Nov') . tile('8, 10', 'Dec')) . $footer;
|
||||
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::NameDays )],
|
||||
'name day mieszko' => test_zci('Poland: 1 Jan', html =>
|
||||
header('Mieszko') . line('Poland', ' 1 Jan') . $footer),
|
||||
header('Mieszko') . line('Poland', tile('1', 'Jan')) . $footer),
|
||||
'maria imieniny' => test_zci($marii, html => header('Maria') . $marii_html),
|
||||
'3 June name day' => test_zci('Czech Republic: Tamara; Hungary: Klotild, Cecília; Poland: Konstantyn, Leszek, Paula, Tamara',
|
||||
html => header('June 3rd') . line('Czech Republic', 'Tamara') .
|
||||
|
@ -69,11 +74,11 @@ ddg_goodie_test(
|
|||
'name day 1 Jan' => test_zci('Hungary: Fruzsina; Poland: Mieczysław, Mieszko', html =>
|
||||
header('January 1st') . line('Hungary', 'Fruzsina') . line('Poland', 'Mieczysław, Mieszko') . $footer),
|
||||
'Radmila svátek' => test_zci('Czech Republic: 3 Jan', html =>
|
||||
header('Radmila') . line('Czech Republic', ' 3 Jan') . $footer),
|
||||
header('Radmila') . line('Czech Republic', tile('3', 'Jan')) . $footer),
|
||||
|
||||
# Genetive case
|
||||
'imieniny marii' => test_zci($marii, html => header('Marii') . $marii_html),
|
||||
'imieniny Tamary' => test_zci("Poland: 3 Jun", html => header('Tamary') . line('Poland', ' 3 Jun') . $footer),
|
||||
'imieniny Tamary' => test_zci("Poland: 3 Jun", html => header('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),
|
||||
|
|
Loading…
Reference in New Issue