]>
git.refcnt.org Git - lugs.git/blob - make-html/make-html.pl
3 # Konvertiert die LUGS-Terminliste (im ASCII Format) in ein HTML-File
5 # (c) 1996-1998 Roland Alder
6 # (c) 2007-2008, 2011-2014 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 stgallen
=> 'e2b1a5', # wie heisst diese Farbe? :)
38 gnupingu
=> 'ffd133', # von http://www.gnupingu.ch/
39 debian
=> 'ffa500', # orange
40 hackerfunk
=> '99b2cd', # blau/grau
45 #---------------------
46 # End of configuration
47 #---------------------
54 my $termine = LUGS
::Termine
::Liste
->new;
58 my ($html_before, $html_after) = $termine->extract_html;
59 $termine->parse_template;
61 my $fh = $termine->{fh
}{out
};
63 print {$fh} $html_before;
64 $termine->process_events;
65 print {$fh} $html_after;
72 package LUGS
::Termine
::Liste
;
74 use constant true
=> 1;
76 use File
::Copy
qw(copy);
77 use File
::Temp
qw(tempfile);
78 use LUGS
::Events
::Parser
();
80 # Return a new instance of our class.
88 # Open files and retrieve the modification time.
93 $self->{mtime
} = scalar localtime +(stat($Config->{data_source
}))[9];
95 open($self->{fh
}{in}, '<', $Config->{html_file
}) or die "Cannot open $Config->{html_file}: $!\n";
96 ($self->{fh
}{out
}, $self->{tmp_file
}) = tempfile
(UNLINK
=> true
);
104 foreach my $handle (qw(in out)) {
105 close($self->{fh
}{$handle});
109 # Copy the temporary file to the HTML file's location.
114 copy
($self->{tmp_file
}, $Config->{html_file
})
115 or die "Cannot copy $self->{tmp_file} to $Config->{html_file}: $!\n";
118 # Extract chunks before and after where the events get populated in.
123 my $fh = $self->{fh
}{in};
124 my $html = do { local $/; <$fh> };
127 qr/^ (.+? \n<!-- \s*? TERMINE_BEGIN \s*? --> \s*? \n)/sx,
128 qr/ \n(<!-- \s*? TERMINE_ENDE \s*? --> .*) $/sx,
132 foreach my $regex (@regexes) {
133 push @chunks, $1 if $html =~ $regex;
139 # Dump regular events formatted to the output handle.
144 my $parser = LUGS
::Events
::Parser
->new($Config->{data_source
});
147 my %month_names = map { sprintf("%02d", ++$i) => $_ }
148 qw(Januar Februar März April Mai Juni Juli
149 August September Oktober November Dezember);
152 my $print_month = sub
156 my $year = $event->get_event_year;
157 my $month = $event->get_event_month;
158 my $day = $event->get_event_day;
160 if ($month ne $seen) {
162 $self->print_template('jahreszeit',
164 MONAT
=> $month_names{$month},
170 $self->print_template('tabellenstart');
171 $self->print_template('kopfdaten');
173 while (my $event = $parser->next_event) {
174 $print_month->($event);
176 my $anchor = $event->get_event_anchor;
178 $self->print_template('farbe',
180 FARBE
=> $Config->{colors
}->{$event->get_event_color}
183 $self->print_template('anker/wann',
186 WOCHENTAG
=> $event->get_event_weekday,
187 TAG
=> $event->get_event_day,
190 $event->get_event_time
191 ?
$self->print_template('zeit',
193 UHRZEIT
=> $event->get_event_time,
195 : $self->print_template('blank');
197 $event->get_event_responsible
198 ?
$self->print_template('verantwortlich',
200 WER
=> $event->get_event_responsible,
202 : $self->print_template('blank');
204 $self->print_template('titel',
206 BEZEICHNUNG
=> $event->get_event_title,
209 $event->get_event_location
210 ?
$self->print_template('standort',
212 STANDORT
=> $event->get_event_location,
216 $event->get_event_more
217 ?
$self->print_template('infos',
219 INFORMATIONEN
=> $event->get_event_more,
223 my $ics_file = "$anchor.ics";
224 my $ics_link = join '/', ($Config->{ical_dir
}, $ics_file);
226 $self->print_template('ical',
231 $self->print_raw_html('</td></tr>');
234 $self->print_template('tabellenende');
235 $self->print_template('fussnoten',
237 AENDERUNG
=> $self->{mtime
},
241 # Parse the template as outlined below __DATA__ and create
247 my $template = do { local $/; <DATA
> };
249 $self->{template
} = [ map { s/\n{2,}$/\n/; $_ } # # description
251 split /\# \s+? .+? \s+? -\n/x,
254 push @descriptions, $1 while $template =~ /\# \s+? (.+?) \s+? -\n/gx;
257 $self->{lookup
} = { map { $_ => $i++ } @descriptions };
260 # Look up the template item, substitute it with the data
261 # given and print it to the output handle.
265 my ($keyword, $data) = @_;
267 return unless exists $self->{lookup
}->{$keyword};
269 my $item = $self->{template
}->[$self->{lookup
}->{$keyword}];
275 foreach my $marker ($markers{begin
}, $markers{end
}) {
276 $marker = qr/\Q$marker\E/;
279 foreach my $name (keys %$data) {
280 $item =~ s
/$markers{begin
}
288 my $fh = $self->{fh
}{out
};
292 # Print raw HTML to the output handle.
298 my $fh = $self->{fh
}{out
};
299 print {$fh} $html, "\n";
307 # Do not change the data descriptions within '# <name>' without
308 # adjusting the code accordingly; furthermore, the hyphen '-'
309 # is required and two trailing newlines at the end of the
310 # template item, too.
317 <table border
=0 cellpadding
=1 cellspacing
=2>
321 <tr
><td
> 
;</td></tr
>
322 <tr
><td colspan
=4 align
=left
><h2
>Definitive Daten
</h2></td
></tr
>
323 <tr
><th align
=left
>Tag
</th><th align=left>Zeit</th
><th align
=left
>Verantwortlich
</th><th align=left>Anlass, Thema</th
></tr
>
327 <tr
><th align
=left colspan
=3><br
><font size
="+1">[% MONAT
%] [% JAHR
%]</font></th
></tr
>
331 <a name
="[% WERT %]"></a
>
335 <tr bgcolor
="#[% FARBE %]">
339 <td valign
=top
><a name
="[% ANKER %]"></a>[% WOCHENTAG %], [% TAG %].</td
>
343 <td valign
=top
>[% UHRZEIT
%]</td
>
347 <td valign
=top
>[% WER
%]</td
>
351 <td valign
=top
><b
>[% BEZEICHNUNG
%]</b
>
355 <br
><font size
=-1>[% STANDORT
%]</font
>
359 <br
>[% INFORMATIONEN
%]
363 <td valign
=top
><a href
="[% LINK %]">iCal
</a></td
>
372 <font size
="-1">Alle Angaben ohne Gew
ä
;hr
, letzte
Ä
;nderung der Terminliste
: [% AENDERUNG
%]</font
>