]>
git.refcnt.org Git - lugs.git/blob - make-html.pl
74b3371b39c51b646c242e486c2d6d7eb840c8f8
3 # Konvertiert die LUGS-Terminliste (im ASCII Format) in ein HTML-File
5 # (c) 1996-1998 Roland Alder
6 # (c) 2007-2008, 2011-2013 Steven Schubiger
14 #-----------------------
15 # Start of configuration
16 #-----------------------
19 # If you're looking for the template,
20 # it is contained below __DATA__ at the end
25 data_source
=> './termine.txt',
26 html_file
=> './index.phtml',
28 fremd
=> 'a2eeff', # blau/gruen
29 treff
=> '99ccff', # ex http://www.zuerich.ch/
30 seeland
=> 'ffffbb', # gelb
31 aargau
=> 'ffbbff', # violett
32 bern
=> 'a5f6bb', # gruen
33 spec
=> 'ff8a80', # rot
34 winti
=> 'd6d6ce', # ex http://www.stadt-winterthur.ch/
35 innerschweiz
=> '8abed7', # ex http://www.luzern.ch/
36 kreuzlingen
=> 'f9f9f9', # ehemals aargau (ex http://www.ag.ch/)
37 uzwil
=> 'e2b1a5', # wie heisst diese Farbe? :)
38 stgallen
=> 'e2b1a5', # wie heisst diese Farbe? :)
39 gnupingu
=> 'ffd133', # von http://www.gnupingu.ch/
44 #---------------------
45 # End of configuration
46 #---------------------
53 my $termine = LUGS
::Termine
::Liste
->new;
57 my ($html_before, $html_after) = $termine->extract_html;
58 $termine->parse_template;
60 my $fh = $termine->{fh
}{out
};
62 print {$fh} $html_before;
63 $termine->process_events;
64 print {$fh} $html_after;
71 package LUGS
::Termine
::Liste
;
73 use constant true
=> 1;
75 use File
::Copy
qw(copy);
76 use File
::Temp
qw(tempfile);
77 use LUGS
::Events
::Parser
;
79 # Return a new instance of our class.
87 # Open files and retrieve the modification time.
92 $self->{mtime
} = scalar localtime +(stat($Config->{data_source
}))[9];
94 open($self->{fh
}{in}, '<', $Config->{html_file
}) or die "Cannot open $Config->{html_file}: $!\n";
95 ($self->{fh
}{out
}, $self->{tmp_file
}) = tempfile
(UNLINK
=> true
);
103 foreach my $handle (qw(in out)) {
104 close($self->{fh
}{$handle});
108 # Copy the temporary file to the HTML file's location.
113 copy
($self->{tmp_file
}, $Config->{html_file
})
114 or die "Cannot copy $self->{tmp_file} to $Config->{html_file}: $!\n";
117 # Extract chunks before and after where the events get populated in.
122 my $fh = $self->{fh
}{in};
123 my $html = do { local $/; <$fh> };
126 qr/^ (.+? \n<!-- \s*? TERMINE_BEGIN \s*? --> \s*? \n)/sx,
127 qr/ \n(<!-- \s*? TERMINE_ENDE \s*? --> .*) $/sx,
131 foreach my $regex (@regexes) {
132 push @chunks, $1 if $html =~ $regex;
138 # Dump regular events formatted to the output handle.
143 my $parser = LUGS
::Events
::Parser
->new($Config->{data_source
});
146 my %month_names = map { sprintf("%02d", ++$i) => $_ }
147 qw(Januar Februar März April Mai Juni Juli
148 August September Oktober November Dezember);
151 my $print_month = sub
155 my $year = $event->get_event_year;
156 my $month = $event->get_event_month;
157 my $day = $event->get_event_day;
159 if ($month ne $seen) {
161 $self->print_template('jahreszeit',
163 MONAT
=> $month_names{$month},
169 $self->print_template('tabellenstart');
170 $self->print_template('kopfdaten');
172 while (my $event = $parser->next_event) {
173 $print_month->($event);
175 my $anchor = $event->get_event_anchor;
177 $self->print_template('farbe',
179 FARBE
=> $Config->{colors
}->{$event->get_event_color}
182 $self->print_template('anker/wann',
185 WOCHENTAG
=> $event->get_event_weekday,
186 TAG
=> $event->get_event_day,
189 $event->get_event_time
190 ?
$self->print_template('zeit',
192 UHRZEIT
=> $event->get_event_time,
194 : $self->print_template('blank');
196 $event->get_event_responsible
197 ?
$self->print_template('verantwortlich',
199 WER
=> $event->get_event_responsible,
201 : $self->print_template('blank');
203 $self->print_template('titel',
205 BEZEICHNUNG
=> $event->get_event_title,
208 $event->get_event_location
209 ?
$self->print_template('standort',
211 STANDORT
=> $event->get_event_location,
215 $event->get_event_more
216 ?
$self->print_template('infos',
218 INFORMATIONEN
=> $event->get_event_more,
222 my $ics_file = "$anchor.ics";
223 my $ics_link = join '/', ($Config->{ical_dir
}, $ics_file);
225 $self->print_template('ical',
230 $self->print_raw_html('</td></tr>');
233 $self->print_template('tabellenende');
234 $self->print_template('fussnoten',
236 AENDERUNG
=> $self->{mtime
},
240 # Parse the template as outlined below __DATA__ and create
246 my $template = do { local $/; <DATA
> };
248 $self->{template
} = [ map { s/\n{2,}$/\n/; $_ } # # description
250 split /\# \s+? .+? \s+? -\n/x,
253 push @descriptions, $1 while $template =~ /\# \s+? (.+?) \s+? -\n/gx;
256 $self->{lookup
} = { map { $_ => $i++ } @descriptions };
259 # Look up the template item, substitute it with the data
260 # given and print it to the output handle.
264 my ($keyword, $data) = @_;
266 return unless exists $self->{lookup
}->{$keyword};
268 my $item = $self->{template
}->[$self->{lookup
}->{$keyword}];
274 foreach my $marker ($markers{begin
}, $markers{end
}) {
275 $marker = qr/\Q$marker\E/;
278 foreach my $name (keys %$data) {
279 $item =~ s
/$markers{begin
}
287 my $fh = $self->{fh
}{out
};
291 # Print raw HTML to the output handle.
297 my $fh = $self->{fh
}{out
};
298 print {$fh} $html, "\n";
306 # Do not change the data descriptions within '# <name>' without
307 # adjusting the code accordingly; furthermore, the hyphen '-'
308 # is required and two trailing newlines at the end of the
309 # template item, too.
316 <table border
=0 cellpadding
=1 cellspacing
=2>
320 <tr
><td
> 
;</td></tr
>
321 <tr
><td colspan
=4 align
=left
><h2
>Definitive Daten
</h2></td
></tr
>
322 <tr
><th align
=left
>Tag
</th><th align=left>Zeit</th
><th align
=left
>Verantwortlich
</th><th align=left>Anlass, Thema</th
></tr
>
326 <tr
><th align
=left colspan
=3><br
><font size
="+1">[% MONAT
%] [% JAHR
%]</font></th
></tr
>
330 <a name
="[% WERT %]"></a
>
334 <tr bgcolor
="#[% FARBE %]">
338 <td valign
=top
><a name
="[% ANKER %]"></a>[% WOCHENTAG %], [% TAG %].</td
>
342 <td valign
=top
>[% UHRZEIT
%]</td
>
346 <td valign
=top
>[% WER
%]</td
>
350 <td valign
=top
><b
>[% BEZEICHNUNG
%]</b
>
354 <br
><font size
=-1>[% STANDORT
%]</font
>
358 <br
>[% INFORMATIONEN
%]
362 <td valign
=top
><a href
="[% LINK %]">iCal
</a></td
>
371 <font size
="-1">Alle Angaben ohne Gew
ä
;hr
, letzte
Ä
;nderung der Terminliste
: [% AENDERUNG
%]</font
>