Skip to content

Commit

Permalink
Fixed bug in n_words, or instead improved it to properly process elis…
Browse files Browse the repository at this point in the history
…pses
  • Loading branch information
Byrne Reese committed Aug 25, 2011
1 parent c1fc129 commit a5c7df4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plugins/ExtraTags/config.yaml
Expand Up @@ -3,7 +3,7 @@ key: Extra Tags
description: A collection of extra template tags that might be helpful.
author_name: Byrne Reese, Endevver LLC
author_link: http://www.endevver.com/
version: 1.15
version: 1.17

tags:
block:
Expand Down Expand Up @@ -34,3 +34,5 @@ tags:
handler: $ExtraTags::ExtraTags::Plugin::mod_nice_size
n_words:
handler: $ExtraTags::ExtraTags::Plugin::mod_n_words
encode_json:
handler: $ExtraTags::ExtraTags::Plugin::mod_encode_json
16 changes: 15 additions & 1 deletion plugins/ExtraTags/lib/ExtraTags/Plugin.pm
Expand Up @@ -206,7 +206,7 @@ sub mod_n_words {
my ($str, $val, $ctx) = @_;
return '' unless defined $str;
my $elip;
($val,$elip) = ($val =~ /^(\d+)(\.\.\.)?$/);
($val,$elip) = ($val =~ /^(\d+)(\.\.\.?)?$/);
$str = remove_html($str) || '';
my @words = split(/\s+/, $str);
my $max = @words > $val ? $val : @words;
Expand Down Expand Up @@ -632,4 +632,18 @@ sub tag_search_to {
return $upper;
}

sub mod_encode_json {
my ($str, $val, $ctx) = @_;
return '' unless defined $str;
$str =~ s!\\!\\\\!g; # \
$str =~ s!\/!\\\/!g; # /
$str =~ s!"!\\"!g; # "
$str =~ s!\f!\\f!g; # \f
$str =~ s!\n!\\n!g; # \n
$str =~ s!\r!\\r!g; # \r
$str =~ s!\t!\\t!g; # \t
$str =~ s!\0!\\0!g;
$str;
}

1;

0 comments on commit a5c7df4

Please sign in to comment.