Class: FrontCompiler::HTMLCompactor

Inherits:
Object
  • Object
show all
Defined in:
lib/front_compiler/html_compactor.rb

Overview

The HTML sources compactor

Copyright © Nikolay V. Nemshilov aka St.

Instance Method Summary collapse

Instance Method Details

#minimize(source) ⇒ Object

applies all the compactings to the given source



8
9
10
11
# File 'lib/front_compiler/html_compactor.rb', line 8

def minimize(source)
  source = remove_comments(source)
  source = remove_trailing_spaces(source)
end

#remove_comments(source) ⇒ Object

removes all the comments out of the code



14
15
16
# File 'lib/front_compiler/html_compactor.rb', line 14

def remove_comments(source)
  source.gsub /<!--.*?-->/, ''
end

#remove_trailing_spaces(source) ⇒ Object

remove all the trailing spaces out of the code



19
20
21
22
23
# File 'lib/front_compiler/html_compactor.rb', line 19

def remove_trailing_spaces(source)
  source.gsub! /\s+/, ' '
  source.gsub! />\s+/, '>'
  source.gsub  /\s+</, '<'
end