Class: Emcee::Compressors::HtmlCompressor
- Inherits:
-
Object
- Object
- Emcee::Compressors::HtmlCompressor
- Defined in:
- lib/emcee/compressors/html_compressor.rb
Overview
HtmlCompressor is our basic implementation of an html minifier. For sprockets to use it, it must have a compress method that only accepts a string and returns the compressed output.
Our implementation only strips out html and javascript comments, and removes blank lines.
Constant Summary collapse
- HTML_COMMENTS =
Match html comments.
<!-- Comments --> /\<!\s*--(?:.*?)(?:--\s*\>)/m- JS_MULTI_COMMENTS =
Match multi-line javascript/css comments.
/* Comments */ /\/\*(?:.*?)\*\//m- JS_COMMENTS =
Match single-line javascript comments.
// CommentsThis does not have the /m modifier, because we only want it to match a single line at a time.
/\/\/.*$/- BLANK_LINES =
Match blank lines.
/^[\s]*$\n/
Instance Method Summary collapse
-
#compress(string) ⇒ Object
Remove comments and blank lines from our html.
Instance Method Details
#compress(string) ⇒ Object
Remove comments and blank lines from our html.
40 41 42 43 44 45 46 |
# File 'lib/emcee/compressors/html_compressor.rb', line 40 def compress(string) ops = [HTML_COMMENTS, JS_MULTI_COMMENTS, JS_COMMENTS, BLANK_LINES] ops.reduce(string) do |output, op| output.gsub(op, "") end end |