Removing extra spaces

Hello there,

In my built directory I have a json file that is the result of MM processing an erb one.

Everything works fine, but the output contains lots of additional spaces and new lines, which I suspect it is due to the many tag opening and closing.

E.g. <% faqpage.each do |fpage| %>

			<% if article.data.SearchFromSummary == true %>
         	<% sum = Nokogiri::HTML(article.summary).text.squeeze("\n").delete("\n") %>
         	<% else %>
         	<% sum = article.data.description %>
         	<% end %>

I was wondering if there is any way to suppress unwanted spaces.

Thanks
Andrea

While it’s possible to use ERB for this, you might have a more enjoyable experience using a template engine that’s designed for JSON, e.g.:

# Gemfile

gem 'yajl-ruby', '~> 1.2'
# source/example.json.yajl

json = {
  FaqSummaries: faq_articles.map(&:text_summary)
}

In this example, text_summary is defined as:

# lib/article_extensions.rb

module Middleman
  module Blog
    # Extensions to blog articles
    module BlogArticle
      def text_summary
        data.description || Nokogiri::HTML(summary).text.gsub(/\s+/, ' ')
      end
    end
  end
end
# config.rb

require 'lib/article_extensions'

Thanks for the hint.