From a5c7df4a3a4b0cca8b4d36cd8647442478527716 Mon Sep 17 00:00:00 2001 From: Byrne Reese Date: Thu, 25 Aug 2011 10:03:49 -0700 Subject: [PATCH] Fixed bug in n_words, or instead improved it to properly process elispses --- plugins/ExtraTags/config.yaml | 4 +++- plugins/ExtraTags/lib/ExtraTags/Plugin.pm | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/ExtraTags/config.yaml b/plugins/ExtraTags/config.yaml index f39a680..3f05228 100644 --- a/plugins/ExtraTags/config.yaml +++ b/plugins/ExtraTags/config.yaml @@ -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: @@ -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 diff --git a/plugins/ExtraTags/lib/ExtraTags/Plugin.pm b/plugins/ExtraTags/lib/ExtraTags/Plugin.pm index 5a9f195..7d814ef 100644 --- a/plugins/ExtraTags/lib/ExtraTags/Plugin.pm +++ b/plugins/ExtraTags/lib/ExtraTags/Plugin.pm @@ -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; @@ -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;