]>
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-2015, 2017 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
41 wilhelmtux
=> 'ffffbf', # from https://wilhelmtux.ch/
46 #---------------------
47 # End of configuration
48 #---------------------
55 my $termine = LUGS
::Termine
::Liste
->new;
59 my ($html_before, $html_after) = $termine->extract_html;
60 $termine->parse_template;
62 my $fh = $termine->{fh
}{out
};
64 print {$fh} $html_before;
65 $termine->process_events;
66 print {$fh} $html_after;
73 package LUGS
::Termine
::Liste
;
75 use constant true
=> 1;
77 use File
::Copy
qw(copy);
78 use File
::Temp
qw(tempfile);
79 use LUGS
::Events
::Parser
();
81 # Return a new instance of our class.
89 # Open files and retrieve the modification time.
94 $self->{mtime
} = scalar localtime +(stat($Config->{data_source
}))[9];
96 open($self->{fh
}{in}, '<', $Config->{html_file
}) or die "Cannot open $Config->{html_file}: $!\n";
97 ($self->{fh
}{out
}, $self->{tmp_file
}) = tempfile
(UNLINK
=> true
);
100 # Close file handles.
105 foreach my $handle (qw(in out)) {
106 close($self->{fh
}{$handle});
110 # Copy the temporary file to the HTML file's location.
115 copy
($self->{tmp_file
}, $Config->{html_file
})
116 or die "Cannot copy $self->{tmp_file} to $Config->{html_file}: $!\n";
119 # Extract chunks before and after where the events get populated in.
124 my $fh = $self->{fh
}{in};
125 my $html = do { local $/; <$fh> };
128 qr/^ (.+? \n<!-- \s*? TERMINE_BEGIN \s*? --> \s*? \n)/sx,
129 qr/ \n(<!-- \s*? TERMINE_ENDE \s*? --> .*) $/sx,
133 foreach my $regex (@regexes) {
134 push @chunks, $1 if $html =~ $regex;
140 # Dump regular events formatted to the output handle.
145 my $parser = LUGS
::Events
::Parser
->new($Config->{data_source
});
148 my %month_names = map { sprintf("%02d", ++$i) => $_ }
149 qw(Januar Februar März April Mai Juni Juli
150 August September Oktober November Dezember);
153 my $print_month = sub
157 my $year = $event->get_event_year;
158 my $month = $event->get_event_month;
159 my $day = $event->get_event_day;
161 if ($month ne $seen) {
163 $self->print_template('jahreszeit',
165 MONAT
=> $month_names{$month},
171 $self->print_template('tabellenstart');
172 $self->print_template('kopfdaten');
174 while (my $event = $parser->next_event) {
175 $print_month->($event);
177 my $anchor = $event->get_event_anchor;
179 $self->print_template('farbe',
181 FARBE
=> $Config->{colors
}->{$event->get_event_color}
184 $self->print_template('anker/wann',
187 WOCHENTAG
=> $event->get_event_weekday,
188 TAG
=> $event->get_event_day,
191 $event->get_event_time
192 ?
$self->print_template('zeit',
194 UHRZEIT
=> $event->get_event_time,
196 : $self->print_template('blank');
198 $event->get_event_responsible
199 ?
$self->print_template('verantwortlich',
201 WER
=> $event->get_event_responsible,
203 : $self->print_template('blank');
205 $self->print_template('titel',
207 BEZEICHNUNG
=> $event->get_event_title,
210 $event->get_event_location
211 ?
$self->print_template('standort',
213 STANDORT
=> $event->get_event_location,
217 $event->get_event_more
218 ?
$self->print_template('infos',
220 INFORMATIONEN
=> $event->get_event_more,
224 my $ics_file = "$anchor.ics";
225 my $ics_link = join '/', ($Config->{ical_dir
}, $ics_file);
227 $self->print_template('ical/anker',
233 $self->print_raw_html('</tr>');
236 $self->print_template('tabellenende');
237 $self->print_template('fussnoten',
239 AENDERUNG
=> $self->{mtime
},
243 # Parse the template as outlined below __DATA__ and create
249 my $template = do { local $/; <DATA
> };
251 $self->{template
} = [ map { s/\n{2,}$/\n/; $_ } # # description
253 split /\# \s+? .+? \s+? -\n/x,
256 push @descriptions, $1 while $template =~ /\# \s+? (.+?) \s+? -\n/gx;
259 $self->{lookup
} = { map { $_ => $i++ } @descriptions };
262 # Look up the template item, substitute it with the data
263 # given and print it to the output handle.
267 my ($keyword, $data) = @_;
269 return unless exists $self->{lookup
}->{$keyword};
271 my $item = $self->{template
}->[$self->{lookup
}->{$keyword}];
277 foreach my $marker ($markers{begin
}, $markers{end
}) {
278 $marker = qr/\Q$marker\E/;
281 foreach my $name (keys %$data) {
282 $item =~ s
/$markers{begin
}
290 my $fh = $self->{fh
}{out
};
294 # Print raw HTML to the output handle.
300 my $fh = $self->{fh
}{out
};
301 print {$fh} $html, "\n";
309 # Do not change the data descriptions within '# <name>' without
310 # adjusting the code accordingly; furthermore, the hyphen '-'
311 # is required and two trailing newlines at the end of the
312 # template item, too.
319 <table border
=0 cellpadding
=1 cellspacing
=2>
323 <tr
><td
> 
;</td></tr
>
324 <tr
><td colspan
=4 align
=left
><h2
>Definitive Daten
</h2></td
></tr
>
325 <tr
><th align
=left
>Tag
</th><th align=left>Zeit</th
><th align
=left
>Verantwortlich
</th><th align=left>Anlass, Thema</th
></tr
>
329 <tr
><th align
=left colspan
=3><br
><font size
="+1">[% MONAT
%] [% JAHR
%]</font></th
></tr
>
333 <a name
="[% WERT %]"></a
>
337 <tr bgcolor
="#[% FARBE %]">
341 <td valign
=top
><a name
="[% ANKER %]"></a>[% WOCHENTAG %], [% TAG %].</td
>
345 <td valign
=top
>[% UHRZEIT
%]</td
>
349 <td valign
=top
>[% WER
%]</td
>
353 <td valign
=top
><b
>[% BEZEICHNUNG
%]</b
>
357 <br
><font size
=-1>[% STANDORT
%]</font
>
361 <br
>[% INFORMATIONEN
%]
365 <td valign
=top
><a href
="[% LINK %]">iCal
</a><br><a href="#[% ANKER %]">#</a></td
>
374 <font size
="-1">Alle Angaben ohne Gew
ä
;hr
, letzte
Ä
;nderung der Terminliste
: [% AENDERUNG
%]</font
>