Class: HtmlPress::Entities
- Inherits:
-
Object
- Object
- HtmlPress::Entities
- Defined in:
- lib/html_press/html_entities.rb
Instance Method Summary collapse
-
#initialize ⇒ Entities
constructor
A new instance of Entities.
- #minify(text) ⇒ Object
- #reserve(content) ⇒ Object
Constructor Details
#initialize ⇒ Entities
Returns a new instance of Entities.
5 6 7 8 |
# File 'lib/html_press/html_entities.rb', line 5 def initialize @replacement_hash = 'MINIFYENTITY' + Time.now.to_i.to_s @placeholders = [] end |
Instance Method Details
#minify(text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/html_press/html_entities.rb', line 15 def minify text out = text.dup out.gsub! /<|<|>|>|&|&/ do |m| reserve m end out = HTMLEntities.new.decode(out) re = Regexp.new('%' + @replacement_hash + '%(\d+)%') out.gsub! re do |m| m.gsub!(re, "\\1") @placeholders[m.to_i] end out end |
#reserve(content) ⇒ Object
10 11 12 13 |
# File 'lib/html_press/html_entities.rb', line 10 def reserve(content) @placeholders.push content '%' + @replacement_hash + '%' + (@placeholders.size - 1).to_s + '%' end |