summaryrefslogtreecommitdiff
path: root/scripts/update-autocomplete
blob: 1ba837baebe57b237d252f7c0feafb955a43cf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env perl
# Copyright (C) 2020 Daniel Friesel
#
# SPDX-License-Identifier: CC0-1.0

use strict;
use warnings;
use 5.020;

use JSON;
use File::Slurp qw(write_file);
use Travel::Status::DE::IRIS::Stations;

my @station_names = map { $_->[1] } Travel::Status::DE::IRIS::Stations::get_stations();

my $station_json = JSON->new->utf8->encode([@station_names]);

my $autocomplete = <<"EOF";
\$(function() {
	var stations = $station_json;
	\$('input.station').autocomplete({
		delay: 0,
		minLength: 3,
		source: stations
	});
});
EOF

write_file("public/static/js/autocomplete.js", $autocomplete);