Updated art6 ideas.
[artemus.git] / art5
blob44abb8307387057c3436e2d2d75ad831547517f9
1 #!/usr/bin/perl
3 use Art5;
5 my $dump = 0;
6 my $v;
7 my $s;
8 my @path = ();
9 my $cache = undef;
11 # raw argument parsing
12 while ($v = shift(@ARGV)) {
13 if ($v eq '-d') {
14 $dump = 1;
16 elsif ($v eq '-I') {
17 push(@path, shift(@ARGV));
19 elsif ($v eq '-c') {
20 $cache = shift(@ARGV);
22 elsif ($v eq '-l') {
23 update_lang();
25 elsif ($v eq '-h') {
26 usage();
28 else {
29 # script name
33 if (!defined($s)) {
34 $s = join('', <>);
37 my $a = Art5->new( path => \@path, cache => $cache);
39 my $c = $a->compile($s);
41 if ($dump) {
42 use Data::Dumper;
44 print Dumper($c), "\n";
46 else {
47 print $a->exec($c);
50 exit 0;
54 sub update_lang
55 # updates all language files
57 my @lang = glob("lang_*");
59 if (scalar(@lang) == 0) {
60 print "Error: no lang_* files.\n";
61 exit 1;
64 # read now all templates in the current directory
65 # searching for translateable strings
66 my %h = ();
68 foreach my $t (glob("*")) {
69 # skip language files themselves
70 if ($t =~ /lang_.*$/) {
71 next;
74 # read template
75 if (open F, $t) {
76 my $l;
78 while ($l = <F>) {
79 my @s = ($l =~ /@\"([^\"]+)"/g);
81 foreach my $s (@s) {
82 $h{$s}++;
86 close F;
90 my $a = Art5->new( path => ['.']);
92 # now all keys in the templates must be
93 # merged into each language file
94 # ...
96 foreach my $l (@lang) {
97 print "Rebulding $l...\n";
99 # load and execute this template file
100 my $c = $a->code($l);
101 $a->exec($c);
103 open F, ">$l";
105 print F "<{T\n";
106 foreach my $k (sort keys(%h)) {
107 print F "\"$k\" \n";
108 print F "\"", ($a->{t}->{$k} || ''), "\"\n\n";
110 print F "}>\n";
112 close F;
115 exit 0;
119 sub usage {
120 print <<EOF;
122 Artemus 5 Command Line Interpreter
123 Copyright (C) 2000/2011 Angel Ortega <angel\@triptico.com>
125 Usage:
127 art5 [options]
129 Options
130 -------
132 -d Do not execute the compiled code, but dump it (using
133 Data::Dumper).
134 -I {dir} Add {dir} to the template search path.
135 -c {dir} Use {dir} as a folder to store caching information.
136 -l Reads all templates in the current directory, extracts all
137 translateable strings and updates all templates matching
138 'lang_*' with them. To start with a new language, just
139 create an empty language file.
140 -h Show this help.
144 exit 0;