summaryrefslogtreecommitdiff
path: root/scripts/update-autocomplete
blob: 4dc64ae28adee4caa43e83254f0bceef26fb8484 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env perl

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_list = q{};

for my $station (@station_names) {
	$station_list .= sprintf( "\t\t\t\"%s\": null,\n", $station );
}

my $autocomplete = <<"EOF";
/*
 * Copyright (C) 2020 DB Station&Service AG, Europaplatz 1, 10557 Berlin
 * Copyright (C) 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: CC-BY-4.0
 */
document.addEventListener('DOMContentLoaded', function() {
	var elems = document.querySelectorAll('.autocomplete');
	M.Autocomplete.init(elems, {
		minLength: 3,
		limit: 50,
		data: {
$station_list
		}
	});
});
EOF

write_file(
	"public/static/js/autocomplete.js",
	{ binmode => ':encoding(utf-8)' },
	$autocomplete
);