From 19200aff71c98d9a91d95d248b8cbc1d1ab02db3 Mon Sep 17 00:00:00 2001 From: Adrian Short Date: Tue, 3 Jul 2012 17:29:32 +0100 Subject: [PATCH] Tidied POI descriptions for Layar: truncate where necessary, strip HTML, decode HTML entities --- Gemfile | 1 + Gemfile.lock | 2 ++ app/helpers/posts_helper.rb | 11 ++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 77125fb..4c89951 100644 --- a/Gemfile +++ b/Gemfile @@ -41,3 +41,4 @@ gem 'bson_ext' gem 'haml-rails' gem 'mm-multi-parameter-attributes' gem 'feedzirra' +gem 'htmlentities' diff --git a/Gemfile.lock b/Gemfile.lock index 559c3b2..88f2f6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,7 @@ GEM haml (~> 3.0) railties (~> 3.0) hike (1.2.1) + htmlentities (4.3.1) i18n (0.6.0) journey (1.0.4) jquery-rails (2.0.2) @@ -142,6 +143,7 @@ DEPENDENCIES coffee-rails (~> 3.2.1) feedzirra haml-rails + htmlentities jquery-rails mm-multi-parameter-attributes mongo_mapper diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 205a612..ea113fa 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -13,7 +13,7 @@ module PostsHelper }, :text => { :title => post.title, - :description => post.summary, + :description => clean_description(post.summary), :footnote => "From #{post.feed.title}" }, :actions => [ @@ -27,4 +27,13 @@ module PostsHelper ] } end + + def clean_description(s) + if s.size > 137 + s = s[0..136] + '...' + end + + coder = HTMLEntities.new + coder.decode(s.gsub(/<.+?>/, '')) + end end