]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/test_data/idl2js.pl
LP#1775466 Angular(6) base application
[Evergreen.git] / Open-ILS / src / eg2 / src / test_data / idl2js.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3 use XML::LibXML;
4 use XML::LibXSLT;
5 my $out_file = 'IDL2js.js';
6 my $idl_file = '../../../../examples/fm_IDL.xml';
7 my $xsl_file = '../../../../xsl/fm_IDL2js.xsl'; 
8
9 my $xslt = XML::LibXSLT->new();
10 my $style_doc = XML::LibXML->load_xml(location => $xsl_file, no_cdata=>1);
11 my $stylesheet = $xslt->parse_stylesheet($style_doc);
12 my $idl_string = preprocess_idl_file($idl_file);
13 my $idl_doc = XML::LibXML->load_xml(string => $idl_string);
14 my $results = $stylesheet->transform($idl_doc);
15 my $output = $stylesheet->output_as_bytes($results);
16
17 open(IDL, ">$out_file") or die "Cannot open IDL2js file $out_file : $!\n";
18
19 print IDL $output;
20
21 close(IDL);
22
23
24 sub preprocess_idl_file {
25        my $file = shift;
26        open my $idl_fh, '<', $file or die "Unable to open IDL file $file : $!\n";
27        local $/ = undef;
28        my $xml = <$idl_fh>;
29        close($idl_fh);
30        # These substitutions are taken from OpenILS::WWW::IDL2js
31        $xml =~ s/<!--.*?-->//sg;     # filter out XML comments ...
32        $xml =~ s/(?:^|\s+)--.*$//mg; # and SQL comments ...
33        $xml =~ s/^\s+/ /mg;          # and extra leading spaces ...
34        $xml =~ s/\R*//g;             # and newlines
35        return $xml;
36 }