The full extended hash can now be used as a value.
[artemus.git] / art5
blobbae4d8ba2340e86bb8add5fb006d275cbe76ffd1
1 #!/usr/bin/perl
3 use Art5;
5 my $dump = 0;
6 my $v, $s;
7 my @path = ();
8 my $cache = undef;
10 # raw argument parsing
11 while ($v = shift(@ARGV)) {
12 if ($v eq '-d') {
13 $dump = 1;
15 elsif ($v eq '-I') {
16 push(@path, shift(@ARGV));
18 elsif ($v eq '-c') {
19 $cache = shift(@ARGV);
21 elsif ($v eq '-l') {
22 update_lang();
24 elsif ($v eq '-h') {
25 usage();
27 else {
28 # script name
32 if (!defined($s)) {
33 $s = join('', <>);
36 my $a = Art5->new( path => \@path, cache => $cache);
38 my $c = $a->compile($s);
40 if ($dump) {
41 use Data::Dumper;
43 print Dumper($c), "\n";
45 else {
46 print $a->exec($c);
49 exit 0;
53 sub update_lang
54 # updates all language files
56 my @lang = glob("lang_*");
58 if (scalar(@lang) == 0) {
59 print "Error: no lang_* files.\n";
60 exit 1;
63 # read now all templates in the current directory
64 # searching for translateable strings
65 my %h = ();
67 foreach my $t (glob("*")) {
68 # skip language files themselves
69 if ($t =~ /lang_.*$/) {
70 next;
73 # read template
74 if (open F, $t) {
75 my $l;
77 while ($l = <F>) {
78 my @s = ($l =~ /@\"([^\"]+)"/g);
80 foreach my $s (@s) {
81 $h{$s}++;
85 close F;
89 my $a = Art5->new( path => ['.']);
91 # now all keys in the templates must be
92 # merged into each language file
93 # ...
95 foreach my $l (@lang) {
96 print "Rebulding $l...\n";
98 # load and execute this template file
99 my $c = $a->code($l);
100 $a->exec($c);
102 open F, ">$l";
104 print F "<{T\n";
105 foreach my $k (sort keys(%h)) {
106 print F "\"$k\" \n";
107 print F "\"", ($a->{t}->{$k} || ''), "\"\n\n";
109 print F "}>\n";
111 close F;
114 exit 0;
118 sub usage {
119 print <<EOF;
121 Artemus 5 Command Line Interpreter
122 Copyright (C) 2000/2010 Angel Ortega <angel\@triptico.com>
124 Usage:
126 art5 [options]
128 Options
129 -------
131 -d Do not execute the compiled code, but dump it (using
132 Data::Dumper).
133 -I {dir} Add {dir} to the template search path.
134 -c {dir} Use {dir} as a folder to store caching information.
135 -l Reads all templates in the current directory, extracts all
136 translateable strings and updates all templates matching
137 'lang_*' with them. To start with a new language, just
138 create an empty language file.
139 -h Show this help.
143 exit 0;