Hi Clint,
here is my final patch which includes :
- a fix in regexp to extract all cases of HTML::Mason syntax
- the repexp to extract Mason (aka Mason 2) syntax
- some tests to check this modules with HTML::mason and Mason examples
Please let me know if it's ok for you ?
Best regards,
Alex.
diff -ru Locale-Maketext-Lexicon-0.86.orig//lib/Locale/Maketext/Extract/Plugin/Mason.pm Locale-Maketext-Lexicon-0.86//lib/Locale/Maketext/Extract/Plugin/Mason.pm
--- Locale-Maketext-Lexicon-0.86.orig//lib/Locale/Maketext/Extract/Plugin/Mason.pm 2010-08-10 14:46:06.000000000 +0200
+++ Locale-Maketext-Lexicon-0.86//lib/Locale/Maketext/Extract/Plugin/Mason.pm 2011-06-20 16:30:04.000000000 +0200
@@ -5,7 +5,7 @@
=head1 NAME
-Locale::Maketext::Extract::Plugin::Mason - Mason format parser
+Locale::Maketext::Extract::Plugin::Mason - HTML::Mason (aka Mason 1) and Mason (aka Mason 2) format parser
=head1 SYNOPSIS
@@ -26,7 +26,12 @@
=head1 VALID FORMATS
-Strings inside <&|/l>...</&> and <&|/loc>...</&> are extracted.
+HTML::Mason (aka Mason 1)
+ Strings inside <&|/l>...</&> and <&|/loc>...</&> are extracted.
+
+Mason (aka Mason 2)
+Strings inside <% $.floc { %>...</%> or <% $.fl { %>...</%> or
+<% $self->floc { %>...</%> or <% $self->fl { %>...</%> are extracted.
=head1 KNOWN FILE TYPES
@@ -49,12 +54,18 @@
my $line = 1;
- # HTML::Mason
-
- while (m!\G(.*?<&\|/l(?:oc)?(.*?)&>(.*?)</&>)!sg) {
+ # HTML::Mason (aka Mason 1)
+ while (m!\G(.*?<&\|[ ]*/l(?:oc)?(?:[ ]*,[ ]*(.*?))?[ ]*&>(.*?)</&>)!sg) {
my ($vars, $str) = ($2, $3);
$line += ( () = ($1 =~ /\n/g) ); # cryptocontext!
- $self->add_entry($str, $line, $vars );
+ $self->add_entry($str, $line, $vars );
+ }
+
+ # Mason (aka Mason 2)
+ while (m!\G(.*?<%[ ]*(?:\$(?:\.|self->))fl(?:oc)?(?:[ ]*\((.*?)\))?[ ]*{[ ]*%>(.*?)</%>)!sg) {
+ my ($vars, $str) = ($2, $3);
+ $line += ( () = ($1 =~ /\n/g) ); # cryptocontext!
+ $self->add_entry($str, $line, $vars );
}
}
@@ -119,4 +130,4 @@
=cut
-1;
\ No newline at end of file
+1;
diff -ru Locale-Maketext-Lexicon-0.86.orig//t/5-extract.t Locale-Maketext-Lexicon-0.86//t/5-extract.t
--- Locale-Maketext-Lexicon-0.86.orig//t/5-extract.t 2010-08-10 14:46:14.000000000 +0200
+++ Locale-Maketext-Lexicon-0.86//t/5-extract.t 2011-06-20 16:30:15.000000000 +0200
@@ -1,7 +1,7 @@
#! /usr/bin/perl -w
use lib '../lib';
use strict;
-use Test::More tests => 64;
+use Test::More tests => 76;
use_ok('Locale::Maketext::Extract');
my $Ext = Locale::Maketext::Extract->new();
@@ -33,6 +33,434 @@
#### END WRAPPING TESTS ############
$Ext->{wrap} = 0;
+
+#### BEGIN HTML::Mason (aka Mason 1) TESTS ############
+SKIP: {
+ skip( 'HTML::Mason unavailable', 5 ) unless eval { require HTML::Mason };
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason simple" );
+<&|/l&>string1</&>
+<&|/loc&>string2</&>
+__EXAMPLE__
+#: :1
+msgid "string1"
+msgstr ""
+
+#: :2
+msgid "string2"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason simple with spaces" );
+<&| /l&>string1</&>
+<&|/l &>string2</&>
+<&| /l &>string3</&>
+<&| /loc&>string4</&>
+<&|/loc &>string5</&>
+<&| /loc &>string6</&>
+__EXAMPLE__
+#: :1
+msgid "string1"
+msgstr ""
+
+#: :2
+msgid "string2"
+msgstr ""
+
+#: :3
+msgid "string3"
+msgstr ""
+
+#: :4
+msgid "string4"
+msgstr ""
+
+#: :5
+msgid "string5"
+msgstr ""
+
+#: :6
+msgid "string6"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason one argument" );
+<&|/l,arg1=>value1&>string1</&>
+<&|/loc,arg1=>value1&>string2</&>
+__EXAMPLE__
+#. (arg1=>value1)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1)
+#: :2
+msgid "string2"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason one argument with spaces" );
+<&|/l, arg1=>value1&>string1</&>
+<&|/loc, arg1=>value1&>string2</&>
+<&|/l ,arg1=>value1&>string3</&>
+<&|/loc ,arg1=>value1&>string4</&>
+<&|/l , arg1=>value1&>string5</&>
+<&|/loc , arg1=>value1&>string6</&>
+<&| /l , arg1=>value1 &>string7</&>
+<&| /loc , arg1=>value1 &>string8</&>
+__EXAMPLE__
+#. (arg1=>value1)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1)
+#: :4
+msgid "string4"
+msgstr ""
+
+#. (arg1=>value1)
+#: :5
+msgid "string5"
+msgstr ""
+
+#. (arg1=>value1)
+#: :6
+msgid "string6"
+msgstr ""
+
+#. (arg1=>value1)
+#: :7
+msgid "string7"
+msgstr ""
+
+#. (arg1=>value1)
+#: :8
+msgid "string8"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason two arguments" );
+<&|/l,arg1=>value1,arg2=>value2&>string1</&>
+<&|/loc,arg1=>value1,arg2=>value2&>string2</&>
+__EXAMPLE__
+#. (arg1=>value1,arg2=>value2)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :2
+msgid "string2"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "HTML::Mason two arguments with spaces" );
+<&|/l ,arg1=>value1,arg2=>value2&>string1</&>
+<&|/loc ,arg1=>value1,arg2=>value2&>string2</&>
+<&|/l , arg1=>value1,arg2=>value2&>string3</&>
+<&|/loc , arg1=>value1,arg2=>value2&>string4</&>
+<&|/l , arg1=>value1, arg2=>value2&>string5</&>
+<&|/loc , arg1=>value1, arg2=>value2&>string6</&>
+<&| /l , arg1=>value1, arg2=>value2 &>string7</&>
+<&| /loc , arg1=>value1, arg2=>value2 &>string8</&>
+__EXAMPLE__
+#. (arg1=>value1,arg2=>value2)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :4
+msgid "string4"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :5
+msgid "string5"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :6
+msgid "string6"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :7
+msgid "string7"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :8
+msgid "string8"
+msgstr ""
+__EXPECTED__
+
+}
+#### END HTML::Mason (aka Mason 1) TESTS ############
+
+
+#### BEGIN Mason (aka Mason 2) TESTS ############
+SKIP: {
+ skip( 'Mason unavailable', 5 ) unless eval { require Mason };
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason simple" );
+<%$.fl {%>string1</%>
+<%$.floc {%>string2</%>
+<%$self->fl {%>string3</%>
+<%$self->floc {%>string4</%>
+__EXAMPLE__
+#: :1
+msgid "string1"
+msgstr ""
+
+#: :2
+msgid "string2"
+msgstr ""
+
+#: :3
+msgid "string3"
+msgstr ""
+
+#: :4
+msgid "string4"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason simple with spaces" );
+<% $.fl {%>string1</%>
+<% $.floc {%>string2</%>
+<% $self->fl {%>string3</%>
+<% $self->floc {%>string4</%>
+<% $.fl { %>string5</%>
+<% $.floc { %>string6</%>
+<% $self->fl { %>string7</%>
+<% $self->floc { %>string8</%>
+__EXAMPLE__
+#: :1
+msgid "string1"
+msgstr ""
+
+#: :2
+msgid "string2"
+msgstr ""
+
+#: :3
+msgid "string3"
+msgstr ""
+
+#: :4
+msgid "string4"
+msgstr ""
+
+#: :5
+msgid "string5"
+msgstr ""
+
+#: :6
+msgid "string6"
+msgstr ""
+
+#: :7
+msgid "string7"
+msgstr ""
+
+#: :8
+msgid "string8"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason one argument" );
+<%$.fl(arg1=>value1){%>string1</%>
+<%$.floc(arg1=>value1){%>string2</%>
+<%$self->fl(arg1=>value1){%>string3</%>
+<%$self->floc(arg1=>value1){%>string4</%>
+__EXAMPLE__
+#. (arg1=>value1)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1)
+#: :4
+msgid "string4"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason one argument with spaces" );
+<% $.fl(arg1=>value1){%>string1</%>
+<% $.floc(arg1=>value1){%>string2</%>
+<% $.fl(arg1=>value1) {%>string3</%>
+<% $.floc(arg1=>value1) {%>string4</%>
+<% $.fl(arg1=>value1) { %>string5</%>
+<% $.floc(arg1=>value1) { %>string6</%>
+__EXAMPLE__
+#. (arg1=>value1)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1)
+#: :4
+msgid "string4"
+msgstr ""
+
+#. (arg1=>value1)
+#: :5
+msgid "string5"
+msgstr ""
+
+#. (arg1=>value1)
+#: :6
+msgid "string6"
+msgstr ""
+__EXPECTED__
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason two arguments" );
+<% $.fl(arg1=>value1,arg2=>value2){%>string1</%>
+<% $.floc(arg1=>value1,arg2=>value2){%>string2</%>
+<%$self->fl(arg1=>value1,arg2=>value2){%>string3</%>
+<%$self->floc(arg1=>value1,arg2=>value2){%>string4</%>
+__EXAMPLE__
+#. (arg1=>value1,arg2=>value2)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :4
+msgid "string4"
+msgstr ""
+__EXPECTED__
+
+
+
+ write_po_ok( <<'__EXAMPLE__' => <<'__EXPECTED__', "Mason two arguments with spaces" );
+<%$.fl(arg1=>value1,arg2=>value2){%>string1</%>
+<%$.floc(arg1=>value1,arg2=>value2){%>string2</%>
+<% $.fl (arg1=>value1,arg2=>value2){%>string3</%>
+<% $.floc (arg1=>value1,arg2=>value2){%>string4</%>
+<% $.fl (arg1=>value1, arg2=>value2){%>string5</%>
+<% $.floc (arg1=>value1, arg2=>value2){%>string6</%>
+<% $.fl (arg1=>value1, arg2=>value2) {%>string7</%>
+<% $.floc (arg1=>value1, arg2=>value2) {%>string8</%>
+<% $.fl (arg1=>value1, arg2=>value2) { %>string9</%>
+<% $.floc (arg1=>value1, arg2=>value2) { %>string10</%>
+__EXAMPLE__
+#. (arg1=>value1,arg2=>value2)
+#: :1
+msgid "string1"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :10
+msgid "string10"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :2
+msgid "string2"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :3
+msgid "string3"
+msgstr ""
+
+#. (arg1=>value1,arg2=>value2)
+#: :4
+msgid "string4"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :5
+msgid "string5"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :6
+msgid "string6"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :7
+msgid "string7"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :8
+msgid "string8"
+msgstr ""
+
+#. (arg1=>value1, arg2=>value2)
+#: :9
+msgid "string9"
+msgstr ""
+__EXPECTED__
+
+}
+#### END Mason (aka Mason 2) TESTS ############
+
+
#### BEGIN FORMFU TESTS ############
SKIP: {
skip( 'YAML.pm unavailable', 5 ) unless eval { require YAML };