module HtmlWhitespaceCleaner

This module contains the public interface clean and some private methods used within it.

Constants

VERSION
WHITE_SPACE_BETWEEN_TAGS

Defines what is considered whitespace, and determines whether or not it is contained inside an html tag.

Public Class Methods

clean(html_string) click to toggle source

Takes a string of html code and returns the same code but with extra whitespace removed.

It only removes whitespace between html tags. Formatting within tags is preserved.

# File lib/html_whitespace_cleaner.rb, line 15
def self.clean(html_string)
  remove_all_white_space_between_tags(condense_whitespace(html_string)).strip
end

Private Class Methods

condense_whitespace(html_string) click to toggle source
# File lib/html_whitespace_cleaner.rb, line 30
def self.condense_whitespace(html_string)
  html_string.gsub(/\s+/, ' ')
end
remove_all_white_space_between_tags(html_string) click to toggle source
# File lib/html_whitespace_cleaner.rb, line 26
def self.remove_all_white_space_between_tags(html_string)
  html_string.gsub(WHITE_SPACE_BETWEEN_TAGS, "")
end