sqweeze 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,31 +6,30 @@ A command line web asset optimisation tool.
6
6
  _Sqweeze_ cuts the unnecessary bytes out of your web assets, helping you delivering your web project more fast and efficiently.
7
7
  With a little help from a number of well known open source third party tools, _Sqweeze_ does the following:
8
8
 
9
- * Lossless compresses .PNG, .JPEG and .GIF image assets.
10
- * Compresses and concatenates into single files multiple Stylesheets and Javascript files.
11
- * Embeds the compressed assets referenced into the stylesheet, using using {Data-uris}[https://developer.mozilla.org/En/The_data_URL_scheme] (for proper browsers and IE8) and {MHTML}[http://en.wikipedia.org/wiki/MHTML] (for IE6-7).
12
- * Finally, it provides some basic functionality for linking the compressed Javascript and CSS just created to the main HTML document,
13
- and removing automatically the links pointing to the old uncompressed ones.
9
+ 1. Lossless compresses .PNG, .JPEG and .GIF image assets.
10
+ 2. Compresses and concatenates into single files multiple Stylesheets and Javascript files.
11
+ 3. Embeds the compressed image assets into the stylesheet, using {Data-uris}[https://developer.mozilla.org/En/The_data_URL_scheme] (for proper browsers and IE8) and {MHTML}[http://en.wikipedia.org/wiki/MHTML] (for IE6 and IE7).
12
+ 4. Finally, it provides some basic functionality for linking the compressed Javascript and CSS just created, to the main HTML document, and removing automatically the links pointing to the old uncompressed ones.
14
13
 
15
14
  === Installing it
16
15
 
17
16
  Sqweeze relies on a few command-line image compression tools, namely Pngcrush, Jpegtrain, and Gifsicle, which have to be installed first.
18
- On an Ubuntu box, you can install these by running a single command line
17
+ On an Ubuntu box, you can install these all in once by running a single command line
19
18
 
20
- sudo apt-get install pngcrush gifsicle libjpeg-progs
21
-
22
- (This assumes you have ruby, ruby1.8-dev, and gem installed).
19
+ sudo apt-get install pngcrush gifsicle libjpeg-progs
23
20
 
24
21
  Mac OSX users can install the first two as Macports packages. The third (part of libjpeg) instead, has to be
25
22
  {compiled manually}[http://www.phpied.com/installing-jpegtran-mac-unix-linux].
26
23
 
27
- Once installed these, you can install _Sqweeze_ using rubygems
24
+ Once installed these third party tools, you can install _Sqweeze_ using the rubygems package manager
25
+
26
+ sudo gem install sqweeze
28
27
 
29
- gem install sqweeze
28
+ (this assumes that you have both ruby and rugygems installed).
30
29
 
31
30
  === Configuration
32
31
 
33
- When run for the first time, the script creates a config file in the user's $HOME directory and sets therein the default paths of command line tools such as pngcrush and friends.
32
+ When run for the first time, the script creates a configuration file in the user's $HOME directory, and sets therein the default file paths of Pngcrush and friends.
34
33
 
35
34
  # file $HOME/.sqweeze.yml
36
35
 
@@ -39,4 +38,46 @@ When run for the first time, the script creates a config file in the user's $HOM
39
38
  - jpegtran: /usr/bin/jpegtran
40
39
  - gifsicle: /usr/bin/gifsicle
41
40
 
42
- If you have installed these anywhere else than in /usr/bin+, you will have to edit this file so that sqweeze can find them.
41
+ If you have installed those anywhere else than in <code>/usr/bin</code>, you will have to edit this file with your own paths, so that sqweeze can find them.
42
+
43
+ === Usage
44
+
45
+
46
+ sqweeze input_dir [target_dir]
47
+
48
+ When invoked with no options, sqweeze will simply copy the content of a source directory, compress its image assets, and finally generate three new files in the target directory:
49
+
50
+ [javascripts.min.js]
51
+ A file concatenating and compressing together all the other javascript files in the source directory
52
+ [stylesheets.min.js]
53
+ A file concatenating and compressing together all the other Stylesheets in the source directory
54
+ [stylesheets.min.datauri.js]
55
+ Same as stylesheets.min.js, but embedding the image referenced in the stylesheets through the data URI scheme.
56
+
57
+ ==== MHTML Support
58
+
59
+ Whilst the generated <code>stylesheets.all.datauri.css</code> will work fine in most recent web-browsers (i.e Chrome, Safari, Firefox, IE 8), it will fail displaying images in Internet Explorer 6 and 7. A viable way around to this limitation, however, is that of using
60
+ Microsoft's MIME HTML. In order to have sqweeze generate also a MHTML stylesheet suitable to be read by IE6 and IE7, one has to specify the parameter <code>--MHTML-ROOT</code>; that is the URL of the directory where the stylesheet will be deployed.
61
+
62
+ sqweeze --mhtml-root=http://example.com/css example-sourcedir
63
+
64
+ At this point, both the Data URI and the MHTML stylesheet can be linked to the main index.html and loaded selectively through {Internet Explorer's Conditional Comments}[http://en.wikipedia.org/wiki/Conditional_comment]
65
+
66
+ <!--[if (!IE)|(gte IE 8)]><!-->
67
+ <link href="css/stylesheets.min.datauri.css" media="screen" rel="stylesheet" type="text/css" />
68
+ <!--<![endif]-->
69
+ <!--[if lte IE 7]>
70
+ <link href="css/stylesheets.min.mhtml.css" media="screen" rel="stylesheet" type="text/css" />
71
+ <![endif]-->
72
+
73
+ This latter step can be automated by supplying the <code>-D</code> (DOM-Documents) parameter to the script. In this case, Sqweeze will simply delete from the DOM all the pre-existing <code>SCRIPT</code> and <code>LINK</code> elements having a src (or a href) attribute, and append the generated ones to the document's <code>HEAD</code>. However, this functionality is rather crude at the moment, and most certainly will require some manual tweaking on the user side.
74
+
75
+
76
+ ==== Inline asset optimisation (experimental)
77
+
78
+ Although the optimisation strategy described above is probably effective in most of the cases, in some cases it can be useful to reduce the amount of HTTP requests by placing compressed assets inline, directly within the HTML file, rather than in external stylesheets. Sqweeze provides functionality for compiling assets inline into the DOM document This is still experimental at the moment, and does not yet support base64 image embedding.
79
+
80
+ sqweeze -S all_inline -D source_dir/index.html source_dir
81
+
82
+ [....]
83
+
@@ -38,7 +38,7 @@ op=OptionParser.new do |opts|
38
38
  opts.on('-e','--exclude-files=PATTERN', "Exclude a file/directory pattern (e.g. doc/**/*.* )") do |exc|
39
39
  options[:exclude_files] = exc
40
40
  end
41
- opts.on('-d','--dom-documents=PATTERN', "Dom document/s to which CSS/JS should be linked (e.g. **/index.html )") do |dom|
41
+ opts.on('-D','--dom-documents=PATTERN', "Dom document/s to which CSS/JS should be linked (e.g. **/index.html )") do |dom|
42
42
  options[:dom_documents] = dom
43
43
  end
44
44
 
@@ -119,6 +119,7 @@ begin
119
119
  }.each do |opt, cmp|
120
120
  cmp.compress unless cm.get_conf(opt) == false
121
121
  end
122
+
122
123
  # link assets to main HTML file
123
124
  AssetLinker.new.compile unless cm.get_conf(:dom_documents).empty?
124
125
  end
@@ -1,6 +1,8 @@
1
1
  class AssetLinker < DOMCompiler
2
2
 
3
3
  def compile
4
+
5
+
4
6
  iterate_over("link[@rel='stylesheet'], script[@src]") do |elm,doc|
5
7
  # Skip if the script has an absolute link
6
8
  next if elm.get_attribute('src') =~ /^http:\/\//
@@ -15,8 +15,7 @@ class ConfManager
15
15
  @conf_filename='.sqweeze.yml'
16
16
  @source_dir=nil
17
17
  @target_dir=nil
18
- @files=[]
19
-
18
+ @files=[]
20
19
  @conf={
21
20
  :suppress_info => false,
22
21
  :suppress_debug => true,
@@ -62,6 +61,8 @@ class ConfManager
62
61
  def prepare(source,target=nil,override_conf={})
63
62
 
64
63
  @source_dir=source
64
+ raise 'Cannot sqweeze current directory' if source == '.'
65
+
65
66
  @target_dir=unless target
66
67
  "#{File.basename(source)}_sqweezed"
67
68
  else
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sqweeze}
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andrea Fiore"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqweeze
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrea Fiore