squoosh 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 315473e08078ff495007f1bfddbdcff65fa705e9a0b1184b94d048278fbbc1f3
4
- data.tar.gz: 5459f4ed5ed7803fe14e4f597180bcfee3de40e234f2d3e5792c2a1f31a456a1
3
+ metadata.gz: 8db4818a215da1002e475a6ab271f274448d983ec4f9b90aff346bd08705c6c2
4
+ data.tar.gz: 3155d597ba38ce21b1fcb59c6550bff5c76fc50b9b8ab63d251588a83448b063
5
5
  SHA512:
6
- metadata.gz: f52727e43f40846d4f2c3e29b0ba8a1d7414908049f7d8e3b82d8f85e32e5842fe573290a5977362992d5e0608b3097844479ba6d72c924a84df4b897bfaa05e
7
- data.tar.gz: b468345836215f88ae14a6a6d769a9d57dc796cc3746725ae61f56ad3ad328e5da88713612e99fc29bc9f9aadd3119a47a24c75c1da6dc1a6e480ff65789734b
6
+ metadata.gz: 6f4147816e466cfa7b1da925fb064ea65c3fec6ee3e8678b3afd8a2cb41a2fc40bea9825320fe67d3692dccd2ba14ff913f308672a9575d25e07a84f51a33a13
7
+ data.tar.gz: 693b6d9d3d20fe099926c67b571b53b9955d2ab2d2700c2b8b912b848729d14a6fda0c04fbc29414a08e43aa7efa29b042f45229021ebcc9493710fd771c639d
data/README.md CHANGED
@@ -5,7 +5,7 @@ Minifies HTML, JavaScript, and CSS, including inline JavaScript and CSS.
5
5
  [![Travis-CI Build
6
6
  Status](https://travis-ci.org/stevecheckoway/squoosh.svg)](https://travis-ci.org/stevecheckoway/squoosh)
7
7
 
8
- CSS minification is handled by [Sass](http://www.rubydoc.info/gems/sass)
8
+ CSS minification is handled by [Sassc](http://www.rubydoc.info/gems/sassc)
9
9
  whereas JavaScript minification is handled by
10
10
  [Uglifier](http://www.rubydoc.info/gems/uglifier) which requires node.js.
11
11
 
@@ -17,7 +17,7 @@ nodes](https://html.spec.whatwg.org/multipage/dom.html#inter-element-whitespace)
17
17
  are removed from the DOM and semantically meaningfull runs of whitespace are
18
18
  compressed to single spaces, except in `pre`, `textarea`, and
19
19
  [foreign](https://html.spec.whatwg.org/multipage/syntax.html#elements-2) elements.
20
- Then, inline JavaScript and CSS are compressed using Sass and Uglifier.
20
+ Then, inline JavaScript and CSS are compressed using Sassc and Uglifier.
21
21
  Finally, the DOM is serialized, compressing
22
22
  [attributes](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2)
23
23
  where possible and omitting [optional start and end
@@ -32,8 +32,17 @@ Squoosh will not minify
32
32
 
33
33
  - HTML 4 and earlier;
34
34
  - XHTML, any version;
35
- - [MathML](https://www.w3.org/TR/MathML3/) elements; nor
36
- - [SVG](https://www.w3.org/TR/SVG11/) elements.
35
+ - spaces in [MathML](https://www.w3.org/TR/MathML3/) elements; nor
36
+ - spaces in [SVG](https://www.w3.org/TR/SVG11/) elements.
37
+
38
+ HTML 4 and XHTML documents (more precisely, any document that does not have an
39
+ HTML 5 DOCTYPE, typically `<!DOCTYPE html>`) is returned unchanged by
40
+ `Squoosh::minify_html`.
41
+
42
+ MathML and SVG elements have their tags minified (including compressing
43
+ attributes and serializing empty elements as self-closing start tags) and
44
+ comments inside them are removed. White space is preserved (except for the
45
+ newline normalization performed by the HTML 5 parser).
37
46
 
38
47
  ## Installation
39
48
 
@@ -54,7 +63,7 @@ Or install it yourself as:
54
63
  ## Usage
55
64
 
56
65
  You can read the documentation
57
- [here](https://www.rubydoc.info/github/stevecheckoway/squoosh/).
66
+ [here](https://www.rubydoc.info/gems/squoosh/).
58
67
 
59
68
  The three basic minification functions are
60
69
 
@@ -96,7 +96,7 @@ module Squoosh
96
96
  doc.children.map { |node| stringify_node(node) }.join
97
97
  end
98
98
 
99
- # Minify CSS using Sass.
99
+ # Minify CSS using Sassc.
100
100
  #
101
101
  # @param content [String] the CSS to minify
102
102
  # @return [String] the minified CSS
@@ -248,11 +248,6 @@ module Squoosh
248
248
  end
249
249
  end
250
250
 
251
- def compress_event_handler(content)
252
- @event_handler_cache[content] ||= \
253
- Uglifier.compile(content, @options[:uglifier_options])
254
- end
255
-
256
251
  def compress_javascript(doc)
257
252
  # Compress script elements.
258
253
  doc.xpath('//script[not(ancestor::math or ancestor::svg)]').each do |node|
@@ -340,7 +335,8 @@ module Squoosh
340
335
 
341
336
  # Add attributes. 8.1.2.3
342
337
  last_attr_unquoted = false
343
- node.attributes.each do |name, attr|
338
+ node.attribute_nodes.each do |attr|
339
+ name = qualified_attribute_name(attr)
344
340
  last_attr_unquoted = false
345
341
  # Make sure there are no character references.
346
342
  # XXX: We should be able to compress a bit more by leaving bare & in
@@ -389,6 +385,24 @@ module Squoosh
389
385
  output.string
390
386
  end
391
387
 
388
+ def qualified_attribute_name(attr)
389
+ ns = attr.namespace
390
+ return attr.name if ns.nil?
391
+
392
+ uri = ns.href
393
+ if uri == Nokogiri::HTML5::XML_NAMESPACE
394
+ 'xml:' + attr.name
395
+ elsif uri == Nokogiri::HTML5::XMLNS_NAMESPACE && attr.name == 'xmlns'
396
+ 'xmlns'
397
+ elsif uri == Nokogiri::HTML5::XMLNS_NAMESPACE
398
+ 'xmlns:' + attr.name
399
+ elsif uri == Nokogiri::HTML5::XLINK_NAMESPACE
400
+ 'xlink:' + attr.name
401
+ else
402
+ raise 'Unreachable!'
403
+ end
404
+ end
405
+
392
406
  def self_closing?(node)
393
407
  # If we're not omitting end tags, then don't mark foreign elements as
394
408
  # self closing.
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Squoosh
4
4
  # The version of squoosh.
5
- VERSION = '0.3.0'
5
+ VERSION = '0.3.1'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squoosh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Checkoway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubygems_version: 3.0.3
173
+ rubygems_version: 3.0.6
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Minify HTML/CSS/JavaScript files.