Tiles for months

master
W25 2014-12-08 08:33:49 +00:00
parent b659c5b5de
commit fa5984b5e7
6 changed files with 4314 additions and 4249 deletions

View File

@ -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&nbsp;$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>';

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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&nbsp;Jun') . line('Hungary', '29&nbsp;Dec') .
line('Poland', ' 3&nbsp;Jun') . $footer;
my $marii_html = line('Poland', '23&nbsp;Jan, 2&nbsp;Feb, 11&nbsp;Feb, 25&nbsp;Mar, 14&nbsp;Apr, ' .
'26&nbsp;Apr, 28&nbsp;Apr, 3&nbsp;May, 24&nbsp;May, 25&nbsp;May, 29&nbsp;May, 2&nbsp;Jun, 13&nbsp;Jun, ' .
'27&nbsp;Jun, 2&nbsp;Jul, 16&nbsp;Jul, 17&nbsp;Jul, 22&nbsp;Jul, 29&nbsp;Jul, 2&nbsp;Aug, 4&nbsp;Aug, ' .
'5&nbsp;Aug, 15&nbsp;Aug, 22&nbsp;Aug, 26&nbsp;Aug, 8&nbsp;Sep, 12&nbsp;Sep, 15&nbsp;Sep, 24&nbsp;Sep, ' .
'7&nbsp;Oct, 11&nbsp;Oct, 16&nbsp;Nov, 21&nbsp;Nov, 8&nbsp;Dec, 10&nbsp;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&nbsp;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&nbsp;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&nbsp;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),