Permalink
Browse files

impove {import}

  • Loading branch information...
1 parent c59cfbd commit 7baa2bffabd4ad7c301d27d8356724c59c182500 @zag committed Oct 20, 2011
Showing with 35 additions and 11 deletions.
  1. +4 −0 Changes
  2. +3 −2 README
  3. +17 −3 bin/plosurin
  4. +11 −6 lib/Plosurin.pm
View
@@ -1,5 +1,9 @@
Revision history for Plosurin.
+0.02 20 Oct 2011
+ * impove {import} with 'rule' opt
+ * some perl6 syntactic sugar
+
0.01 17 Oct 2011
* Template Grammar (without expressions)
* {import } - import directive (not exists in original google closures)
View
5 README
@@ -5,13 +5,14 @@ Plosurin - Perl 6 implementation of Closure Templates
USAGE
- plosurin test.soy > Tmpl.pm
+ plosurin -type perl5 -package MyApp::Tmpl test.soy > Tmpl.pm
DEPENDENCIES
This module requires these other modules and libraries:
- http://search.cpan.org/perldoc?Perl6::Pod
+ http://search.cpan.org/perldoc?Perl6::Pod (0.34)
+ http://search.cpan.org/perldoc?Perl6::Pod::Lib
COPYRIGHT AND LICENCE
View
@@ -2,18 +2,32 @@
use v6;
use Plosurin;
+my %opt = ();
+while ( @*ARGS > 1 ) {
+ my ($name, $val ) = @*ARGS.splice(0,2);
+ unless $name ~~ rx/^\-+/ {
+ die "Bad option name: $name. Maybe you mean -$name or --$name?";
+ }
+ %opt{$name.subst( rx/^\-+/,'')} = $val;
+}
+
if @*ARGS == 1 {
my $data = slurp(@*ARGS[0]);
-my $plo = Plosurin.new( :type('perl5'), :package('Test::Tmpl'));
+my $plo = Plosurin.new( :type('perl5'), :package('MyApp::Template'), |%opt);
say $plo.parse($data).out_perl();
} else {
die
"Error: Need template file
Usage:
- $*PROGRAM_NAME <file>
+ plosurin <file>
+Options:
+ -type <perl5> - the argument following the -type is used to indicate the output format. Default: 'perl5'.
+ for type perl5:
+ -package - namespace for rendered perl5 code. Default: 'MyApp::Template'.
Expample:
- $*PROGRAM_NAME test.soy > Tmpl.pm";
+ perl5 output:
+ plosurin -type perl5 -package Test::Tmpl test.soy > Tmpl.pm";
}
View
@@ -1,5 +1,5 @@
use v6;
-my $VERSION = '0.01';
+my $VERSION = '0.02';
class Template {
has $.namespace ;
has @.params;
@@ -85,7 +85,7 @@ class Plo::Node {
class Plo::raw_text is Plo::Node {
has $.raw_text;
method export_perl {
- return '\'' ~ $.raw_text ~ '\'';
+ return $.raw_text;
}
}
class Plo::command_print is Plo::Node {
@@ -98,8 +98,13 @@ class Plo::command_import is Plo::Node {
return { self.WHAT.perl =>{ file=> $!file, rule=>$!rule}};
}
method export_perl {
- my $body = qqx% pod6xhtml $!file%;
- return $body
+ my $command = "pod6xhtml -nb -t div -M Perl6::Pod::Lib -c \'=Include $!file";
+ if ( $!rule) {
+ $command ~= "\($!rule\)";
+ }
+ $command ~= "\'";
+ my $body = qqx% $command %;
+ return $body
}
}
@@ -126,7 +131,7 @@ class Plosurin::TActions {
unless ( %attr{'file'}) {
die "Bad attr at: " ~ $/.CURSOR.pos ;
}
- make Plo::command_import.new( :file( %attr{'file'}), :rule(%attr{'rule'}));
+ make Plo::command_import.new( |%attr );
}
method tag ($/) {
@@ -205,7 +210,7 @@ class Plosurin {
multi method out_perl { self.out_perl( $!parsed.ast.values)}
multi method out_perl ( @templates ) {
my $output = "
-# this is generated code
+# this is a generated code
# Plosurin ver. $VERSION
package $!package;
";

0 comments on commit 7baa2bf

Please sign in to comment.