From 05d2c1501a0d1b76533541d579584e9d14e8b8a3 Mon Sep 17 00:00:00 2001 From: areeshatariq Date: Wed, 5 Aug 2020 19:15:49 +0500 Subject: [PATCH 1/4] html templatization WIP --- cgi/spellcheck_test.pl | 35 +++++++++++++++++++++++++---- templates/spellcheck_test.tt.html | 37 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100755 templates/spellcheck_test.tt.html diff --git a/cgi/spellcheck_test.pl b/cgi/spellcheck_test.pl index bcc5584e5e0a6..ade488e62194a 100644 --- a/cgi/spellcheck_test.pl +++ b/cgi/spellcheck_test.pl @@ -41,6 +41,19 @@ ProductOpener::Display::init(); +my $tt = Template->new({ + INCLUDE_PATH => $data_root . '/templates', + INTERPOLATE => 1, + EVAL_PERL => 1, + STAT_TTL => 60, # cache templates in memory for 1 min before checking if the source changed + COMPILE_EXT => '.ttc', # compile templates to Perl code for much faster reload + COMPILE_DIR => $data_root . '/tmp/templates', +}); + +# Passing values to the template +my $template_data_ref = { + lang => \&lang, +}; # MIDDLE DOT with common substitutes (BULLET variants, BULLET OPERATOR and DOT OPERATOR (multiplication)) my $middle_dot = qr/(?:\N{U+00B7}|\N{U+2022}|\N{U+2023}|\N{U+25E6}|\N{U+2043}|\N{U+204C}|\N{U+204D}|\N{U+2219}|\N{U+22C5})/i; @@ -68,14 +81,18 @@ my $text = remove_tags_and_quote(decode utf8=>param('text')); -my $html = '

The spellcheck results are based on matches in a given taxonomy.

+my $html; + +$html = '

The spellcheck results are based on matches in a given taxonomy.

For words with at least 5 characters, we consider an edit distance of 1 (insert, replace or delete).

'; +push @{$template_data_ref->{action_process}}, $action; +push @{$template_data_ref->{tagtype}}, $tagtype; +push @{$template_data_ref->{lc}}, $lc; if ($action eq 'process') { - $html .= "

Spellcheck result for taxonomy $tagtype and language $lc:

"; $html .= ""; foreach my $token2 (split(/$separators/, $text)) { @@ -98,6 +115,13 @@ $tag = ""; } + push @{$template_data_ref->{tokens}}, { + token => $token, + tag => $tag, + tagid => $tagid, + canon_tagid => $canon_tagid, + }; + $html .= "\n"; } @@ -107,13 +131,13 @@ $action = 'display'; } - +push @{$template_data_ref->{action_display}}, $action; if ($action eq 'display') { $html .= start_form(-method => "GET"); - + push @{$template_data_ref->{text}}, $text; $html .= <

Text (language code: $lc):
@@ -141,6 +165,9 @@ $full_width = 0; } +$tt->process('spellcheck_test.tt.html', $template_data_ref, \$html); +$html .= "

" . $tt->error() . "

"; + display_new( { title=>"Spellcheck Test", content_ref=>\$html, diff --git a/templates/spellcheck_test.tt.html b/templates/spellcheck_test.tt.html new file mode 100755 index 0000000000000..c66998f99a448 --- /dev/null +++ b/templates/spellcheck_test.tt.html @@ -0,0 +1,37 @@ +

The spellcheck results are based on matches in a given taxonomy.

+

For words with at least 5 characters, we consider an edit distance of 1 (insert, replace or delete).

+[% IF action_process == 'process' %] + +

Spellcheck result for taxonomy [% tagtype %] and language [% lc %]:

+
InputCorrection$lc tagCanonical tag
$token$tag$tagid$canon_tagid
+ + + + + + + [% FOREACH token IN tokens %] + + + + + + + [% END %] +
InputCorrection[% lc %] tagCanonical tag
[% token.token %][% token.tag %][% token.tagid %][% token.canon_tagid %]
+ +[% END %] + +[% IF action_display == 'display' %] + +
+ Taxonomy:

+ Text (language code: [% lc %]):
+ + + + + +
+ +[% END %] From 649d4ff4b0179806811fb56bf64be47d8f355fd3 Mon Sep 17 00:00:00 2001 From: areeshatariq Date: Thu, 6 Aug 2020 02:57:47 +0500 Subject: [PATCH 2/4] HTML Template --- cgi/spellcheck_test.pl | 50 +++++-------------------------- templates/spellcheck_test.tt.html | 18 +++++------ 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/cgi/spellcheck_test.pl b/cgi/spellcheck_test.pl index ade488e62194a..586cf7db5e462 100644 --- a/cgi/spellcheck_test.pl +++ b/cgi/spellcheck_test.pl @@ -83,18 +83,12 @@ my $html; -$html = '

The spellcheck results are based on matches in a given taxonomy.

-

For words with at least 5 characters, we consider an edit distance of 1 (insert, replace or delete).

-'; - -push @{$template_data_ref->{action_process}}, $action; -push @{$template_data_ref->{tagtype}}, $tagtype; -push @{$template_data_ref->{lc}}, $lc; +$template_data_ref->{action_process} = $action; +$template_data_ref->{tagtype} = $tagtype; +$template_data_ref->{lc} = $lc; if ($action eq 'process') { - $html .= "

Spellcheck result for taxonomy $tagtype and language $lc:

"; - $html .= ""; foreach my $token2 (split(/$separators/, $text)) { my $token = $token2; @@ -106,7 +100,7 @@ $token =~ s/\s+$//; $token =~ s/^\s+//; - + next if get_fileid($token) eq ''; my ($canon_tagid, $tagid, $tag) = spellcheck_taxonomy_tag($lc, $tagtype, $token); @@ -122,43 +116,13 @@ canon_tagid => $canon_tagid, }; - $html .= "\n"; - } - - $html .= "
InputCorrection$lc tagCanonical tag
$token$tag$tagid$canon_tagid
"; - - $action = 'display'; -} - -push @{$template_data_ref->{action_display}}, $action; -if ($action eq 'display') { - - $html .= start_form(-method => "GET"); - - - push @{$template_data_ref->{text}}, $text; - $html .= <

-Text (language code: $lc):
- - -HTML -; - - $html .= '' - . hidden(-name=>'type', -value=>$type, -override=>1) - . hidden(-name=>'action', -value=>'process', -override=>1); - - $html .= submit() - . end_form(); - -} -elsif ($action eq 'process') { - + $action = 'display'; } +$template_data_ref->{action_display} = $action; +$template_data_ref->{text} = $text; my $full_width = 1; if ($action ne 'display') { diff --git a/templates/spellcheck_test.tt.html b/templates/spellcheck_test.tt.html index c66998f99a448..82b4e25947dd4 100755 --- a/templates/spellcheck_test.tt.html +++ b/templates/spellcheck_test.tt.html @@ -1,14 +1,17 @@

The spellcheck results are based on matches in a given taxonomy.

For words with at least 5 characters, we consider an edit distance of 1 (insert, replace or delete).

-[% IF action_process == 'process' %] -

Spellcheck result for taxonomy [% tagtype %] and language [% lc %]:

+[% IF action_process == 'process' %] +

+ Spellcheck result for taxonomy [% tagtype %] and language [% lc %]: +

+ - - - - + + + + [% FOREACH token IN tokens %] @@ -19,11 +22,9 @@ [% END %]
Spellcheck Results
InputCorrection[% lc %] tagCanonical tagInputCorrection[% lc %] tagCanonical tag
- [% END %] [% IF action_display == 'display' %] -
Taxonomy:

Text (language code: [% lc %]):
@@ -33,5 +34,4 @@
- [% END %] From 3d35d512e503cca0dcf24a3e88e59b5ed6b7007e Mon Sep 17 00:00:00 2001 From: areeshatariq Date: Thu, 6 Aug 2020 03:12:42 +0500 Subject: [PATCH 3/4] Removed template initialization --- cgi/spellcheck_test.pl | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/cgi/spellcheck_test.pl b/cgi/spellcheck_test.pl index 586cf7db5e462..78a05cfc67a81 100644 --- a/cgi/spellcheck_test.pl +++ b/cgi/spellcheck_test.pl @@ -41,15 +41,6 @@ ProductOpener::Display::init(); -my $tt = Template->new({ - INCLUDE_PATH => $data_root . '/templates', - INTERPOLATE => 1, - EVAL_PERL => 1, - STAT_TTL => 60, # cache templates in memory for 1 min before checking if the source changed - COMPILE_EXT => '.ttc', # compile templates to Perl code for much faster reload - COMPILE_DIR => $data_root . '/tmp/templates', -}); - # Passing values to the template my $template_data_ref = { lang => \&lang, @@ -100,7 +91,7 @@ $token =~ s/\s+$//; $token =~ s/^\s+//; - + next if get_fileid($token) eq ''; my ($canon_tagid, $tagid, $tag) = spellcheck_taxonomy_tag($lc, $tagtype, $token); From 6fae3249f763ec7ab1f58b9c219e523b16aedbb5 Mon Sep 17 00:00:00 2001 From: areeshatariq Date: Tue, 18 Aug 2020 01:04:42 +0500 Subject: [PATCH 4/4] Minor Fixes --- templates/spellcheck_test.tt.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/templates/spellcheck_test.tt.html b/templates/spellcheck_test.tt.html index 82b4e25947dd4..731da585474d9 100755 --- a/templates/spellcheck_test.tt.html +++ b/templates/spellcheck_test.tt.html @@ -26,12 +26,16 @@ [% IF action_display == 'display' %]
- Taxonomy:

- Text (language code: [% lc %]):
- - + +
+
+ - +
[% END %]