sqweeze 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -2
- data/README.rdoc +10 -51
- data/bin/sqweeze +10 -14
- data/lib/compilers/assetLinker.rb +15 -20
- data/lib/compilers/jsDomCompiler.rb +1 -1
- data/lib/compressors/cssCompressor.rb +20 -24
- data/lib/compressors/pngCompressor.rb +1 -1
- data/lib/confManager.rb +4 -2
- data/lib/domCompiler.rb +12 -15
- data/lib/sqweezeUtils.rb +22 -29
- data/spec/confManager_spec.rb +20 -12
- data/spec/domCompiler_spec.rb +13 -12
- data/spec/sqw_spec_helper.rb +2 -18
- data/sqweeze.gemspec +4 -4
- metadata +19 -43
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -6,31 +6,31 @@ 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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
13
|
and removing automatically the links pointing to the old uncompressed ones.
|
14
14
|
|
15
15
|
=== Installing it
|
16
16
|
|
17
17
|
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
|
18
|
+
On an Ubuntu box, you can install these by running a single command line
|
19
19
|
|
20
20
|
sudo apt-get install pngcrush gifsicle libjpeg-progs
|
21
21
|
|
22
|
+
(This assumes you have ruby, ruby1.8-dev, and gem installed).
|
23
|
+
|
22
24
|
Mac OSX users can install the first two as Macports packages. The third (part of libjpeg) instead, has to be
|
23
25
|
{compiled manually}[http://www.phpied.com/installing-jpegtran-mac-unix-linux].
|
24
26
|
|
25
|
-
Once installed these
|
27
|
+
Once installed these, you can install _Sqweeze_ using rubygems
|
26
28
|
|
27
29
|
gem install sqweeze
|
28
30
|
|
29
|
-
(this assumes that you have both ruby and rugygems installed).
|
30
|
-
|
31
31
|
=== Configuration
|
32
32
|
|
33
|
-
When run for the first time, the script creates a
|
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.
|
34
34
|
|
35
35
|
# file $HOME/.sqweeze.yml
|
36
36
|
|
@@ -39,45 +39,4 @@ When run for the first time, the script creates a configuration file in the user
|
|
39
39
|
- jpegtran: /usr/bin/jpegtran
|
40
40
|
- gifsicle: /usr/bin/gifsicle
|
41
41
|
|
42
|
-
If you have installed
|
43
|
-
|
44
|
-
=== Usage
|
45
|
-
|
46
|
-
|
47
|
-
sqweeze input_dir [target_dir]
|
48
|
-
|
49
|
-
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:
|
50
|
-
|
51
|
-
[javascripts.min.js]
|
52
|
-
A file concatenating and compressing together all the other javascript files in the source directory
|
53
|
-
[styleshees.min.js]
|
54
|
-
A file concatenating and compressing together all the other Stylesheets in the source directory
|
55
|
-
[styleshees.min.datauri.js]
|
56
|
-
Same as stylesheets.min.js, but embedding the image referenced in the stylesheets through the data URI scheme.
|
57
|
-
|
58
|
-
==== MHTML Support
|
59
|
-
|
60
|
-
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
|
61
|
-
fail displaying images in Internet Explorer 6 and 7. A viable way around to this limitation, however, is that of using
|
62
|
-
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.
|
63
|
-
|
64
|
-
sqweeze --mhtml-root=http://example.com/css example-sourcedir
|
65
|
-
|
66
|
-
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]
|
67
|
-
|
68
|
-
<!--[if (!IE)|(gte IE 8)]><!-->
|
69
|
-
<link href="css/stylesheets.min.datauri.css" media="screen" rel="stylesheet" type="text/css" />
|
70
|
-
<!--<![endif]-->
|
71
|
-
<!--[if lte IE 7]>
|
72
|
-
<link href="css/stylesheets.min.mhtml.css" media="screen" rel="stylesheet" type="text/css" />
|
73
|
-
<![endif]-->
|
74
|
-
|
75
|
-
==== Inline asset optimisation
|
76
|
-
|
77
|
-
Although the process described above is the most broadly adopted by already established Web optimisation tools (e.g. Jammit),
|
78
|
-
sometimes it can be useful - in order to reduce the amount of HTTP requests - to render compressed assets in-line, directly in the HTML file
|
79
|
-
(as opposed to linking them to an external stylesheet or javascript ). Although this is still very experimental and does not support base64 image embedding yet, sqweeze provides a functionality for compiling assets inline into an HTML file.
|
80
|
-
|
81
|
-
sqweeze -S all_inline -D source_dir/index.html source_dir
|
82
|
-
|
83
|
-
[....]
|
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.
|
data/bin/sqweeze
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
# third party libs
|
2
|
+
# rubygems
|
5
3
|
%w[rubygems yui/compressor closure-compiler hpricot].each{|lib| require lib}
|
6
4
|
# ruby standard library
|
7
5
|
%w[logger singleton yaml base64 open-uri pathname optparse fileutils].each{|lib| require lib}
|
@@ -26,7 +24,7 @@ op=OptionParser.new do |opts|
|
|
26
24
|
|
27
25
|
opts.banner = "Usage: sqweeze [options] SOURCE_DIR [TARGET_DIR]"
|
28
26
|
opts.program_name= 'sqweeze'
|
29
|
-
opts.on("-
|
27
|
+
opts.on("-s", "--optimisation-strategy=ALL_IN_ONE",
|
30
28
|
"JavaScript/CSS optimisation strategy to be adopted ") do |s|
|
31
29
|
raise OptionParser::InvalidArgument unless ['all_inline','all_in_one'].include?(s)
|
32
30
|
options[:optimisation_strategy] = s.downcase.to_sym
|
@@ -40,7 +38,7 @@ op=OptionParser.new do |opts|
|
|
40
38
|
opts.on('-e','--exclude-files=PATTERN', "Exclude a file/directory pattern (e.g. doc/**/*.* )") do |exc|
|
41
39
|
options[:exclude_files] = exc
|
42
40
|
end
|
43
|
-
opts.on('-
|
41
|
+
opts.on('-d','--dom-documents=PATTERN', "Dom document/s to which CSS/JS should be linked (e.g. **/index.html )") do |dom|
|
44
42
|
options[:dom_documents] = dom
|
45
43
|
end
|
46
44
|
|
@@ -82,7 +80,7 @@ op=OptionParser.new do |opts|
|
|
82
80
|
opts.separator ""
|
83
81
|
opts.separator "Console output:"
|
84
82
|
|
85
|
-
opts.on('-q',"--
|
83
|
+
opts.on('-q',"--quiet", "suppress console output ") do |q|
|
86
84
|
options[:suppress_warn] = true
|
87
85
|
options[:suppress_info] = true
|
88
86
|
end
|
@@ -95,13 +93,12 @@ begin
|
|
95
93
|
op.parse!
|
96
94
|
Proc.new { puts "Missing SOURCE_DIR argument"; exit(1) }.call unless ARGV[0]
|
97
95
|
Proc.new { puts "source directory #{ARGV[0]} does not exist, please provide a valid path"
|
98
|
-
exit(1) }.call unless
|
96
|
+
exit(1) }.call unless File.exists?(ARGV[0])
|
99
97
|
|
100
98
|
|
101
99
|
cm=ConfManager.instance
|
102
100
|
cm.prepare(ARGV[0], ARGV[1], options)
|
103
|
-
|
104
|
-
|
101
|
+
|
105
102
|
# Compress images
|
106
103
|
{ :compress_png => PngCompressor.new,
|
107
104
|
:compress_gif => GifCompressor.new,
|
@@ -112,17 +109,16 @@ begin
|
|
112
109
|
|
113
110
|
case cm.get_conf(:optimisation_strategy)
|
114
111
|
when :all_inline
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
puts "not implemented yet.."
|
113
|
+
exit
|
114
|
+
|
118
115
|
|
119
116
|
when :all_in_one
|
120
|
-
|
121
117
|
{ :compress_js => JsCompressor.new,
|
122
118
|
:compress_css => CssCompressor.new
|
123
119
|
}.each do |opt, cmp|
|
124
120
|
cmp.compress unless cm.get_conf(opt) == false
|
125
|
-
|
121
|
+
end
|
126
122
|
# link assets to main HTML file
|
127
123
|
AssetLinker.new.compile unless cm.get_conf(:dom_documents).empty?
|
128
124
|
end
|
@@ -7,32 +7,27 @@ class AssetLinker < DOMCompiler
|
|
7
7
|
# Otherwise delete.
|
8
8
|
elm.parent.children.delete(elm)
|
9
9
|
end
|
10
|
-
|
11
10
|
dom_documents.each do |path|
|
12
|
-
target_path=remap_filepath(path)
|
13
|
-
|
14
11
|
# Append concatenated JavaScript file.
|
15
|
-
|
16
12
|
doc = Hpricot(open(path))
|
17
13
|
doc.search(@cm.get_conf(:append_scripts_to).to_s.downcase).append( "<script type='text/javascript' src='javascripts.min.js'></script>")
|
18
|
-
|
19
|
-
notify("#{ansi_bold(target_path)}:".ljust(60) + ansi_green("Appending Sylesheets"),:info)
|
20
|
-
|
14
|
+
|
21
15
|
stylesheets_html=<<EOF
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
<!--[if lte IE 8]>
|
17
|
+
<link href="stylesheets.min.mhtml.css" rel="stylesheet" />
|
18
|
+
<![endif]-->
|
19
|
+
<!--[if IE 8]>
|
20
|
+
<link href="stylesheets.min.datauri.css" rel="stylesheet" />
|
21
|
+
<![endif]-->
|
22
|
+
<!--[if !IE]>
|
23
|
+
<link href="stylesheets.min.datauri.css" rel="stylesheet" />
|
24
|
+
<![endif]-->
|
29
25
|
EOF
|
30
|
-
|
31
|
-
# Append
|
32
|
-
doc.search('head').append(stylesheets_html)
|
33
|
-
|
34
|
-
|
35
|
-
end
|
26
|
+
|
27
|
+
# Append ie conditional tags
|
28
|
+
doc.search('head').append(stylesheets_html)
|
29
|
+
write_file(doc.innerHTML,path)
|
30
|
+
end
|
36
31
|
end
|
37
32
|
|
38
33
|
end
|
@@ -12,7 +12,7 @@ class JsDomCompiler < DOMCompiler
|
|
12
12
|
|
13
13
|
|
14
14
|
def compress(fbody)
|
15
|
-
unless @cm.
|
15
|
+
unless @cm.default_js_compressor == :closure
|
16
16
|
compressor, method = YUI::JavaScriptCompressor.new( :munge => true), :compress
|
17
17
|
else
|
18
18
|
compressor, method = Closure::Compiler.new, :compiler
|
@@ -19,8 +19,9 @@ class CssCompressor < Compressor
|
|
19
19
|
EMBED_DETECTOR = /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/
|
20
20
|
|
21
21
|
# MHTML file constants.
|
22
|
-
MHTML_START = "/*\
|
23
|
-
MHTML_SEPARATOR= "--SQWEEZED_ASSET
|
22
|
+
MHTML_START = "/*\nContent-Type: multipart/related; boundary=\"SQWEEZED_ASSET\"\n"
|
23
|
+
MHTML_SEPARATOR= "--SQWEEZED_ASSET"
|
24
|
+
MHTML_END = "*/\n"
|
24
25
|
|
25
26
|
def initialize
|
26
27
|
super('css')
|
@@ -58,27 +59,22 @@ class CssCompressor < Compressor
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def embed_datauris(compressed_css)
|
61
|
-
|
62
62
|
out=compressed_css.gsub(EMBED_DETECTOR) do |url|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
if compressed_asset_path and File.exists?(compressed_asset_path) and File.size(compressed_asset_path) < MAX_IMAGE_SIZE and mime_t
|
67
|
-
|
68
|
-
base64_asset=encoded_contents( compressed_asset_path )
|
63
|
+
|
64
|
+
compressed_asset_path=remap_filepath($1)
|
65
|
+
mime_t=mime_type(compressed_asset_path)
|
69
66
|
|
70
|
-
|
67
|
+
if compressed_asset_path and File.exists?(compressed_asset_path) and File.size(compressed_asset_path) < MAX_IMAGE_SIZE and mime_t
|
68
|
+
base64_asset=encoded_contents( compressed_asset_path )
|
69
|
+
$log.debug("file:#{compressed_asset_path}; mime-type: #{mime_type($1)}#")
|
71
70
|
# label the image
|
72
71
|
@assets[ compressed_asset_path ] = base64_asset
|
73
72
|
"url(\"data:#{mime_t};charset=utf-8;base64,#{base64_asset}\")"
|
74
73
|
else
|
75
74
|
"url(#{$1})"
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
total_file_weight=@assets.keys.inject(0){|sum,path| sum+File.size(path)}
|
80
|
-
|
81
|
-
notify("Converting #{ansi_bold(@assets.size)} images (#{ansi_bold(total_file_weight)} bytes) into base64".ljust(60),:info)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
82
78
|
write_file(out,"#{@cm.target_dir}/stylesheets.min.datauri.css")
|
83
79
|
end
|
84
80
|
|
@@ -87,18 +83,18 @@ class CssCompressor < Compressor
|
|
87
83
|
mhtml= MHTML_START
|
88
84
|
|
89
85
|
@assets.each do |mhtml_loc,base64|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
86
|
+
mhtml <<"
|
87
|
+
#{MHTML_SEPARATOR}
|
88
|
+
Content-location: #{ mhtml_loc }
|
89
|
+
Content-Transfer-Encoding:base64
|
90
|
+
|
91
|
+
#{base64}\n"
|
96
92
|
end
|
97
|
-
mhtml << "*/\
|
93
|
+
mhtml << "*/\n"
|
98
94
|
mhtml << compressed_css.gsub(EMBED_DETECTOR) do |css|
|
99
95
|
compressed_asset_path=remap_filepath($1)
|
100
96
|
if compressed_asset_path
|
101
|
-
"url(mhtml:#{@cm.get_conf(:mhtml_root).gsub(/\/$/,'')}/stylesheets.min.mhtml.css!#{compressed_asset_path})"
|
97
|
+
"url(mhtml:#{@cm.get_conf(:mhtml_root).gsub(/\/$/,'')}/stylesheets.min.mhtml.css!#{mhtml_location( compressed_asset_path)})"
|
102
98
|
else
|
103
99
|
"url(#{$1})"
|
104
100
|
end
|
data/lib/confManager.rb
CHANGED
@@ -37,7 +37,7 @@ class ConfManager
|
|
37
37
|
}
|
38
38
|
end
|
39
39
|
attr_reader :target_dir,:source_dir,
|
40
|
-
|
40
|
+
:files,:conf_filename,:conf
|
41
41
|
|
42
42
|
|
43
43
|
# Setter method used to populate the <code>@conf</code> attribute with key value pairs.
|
@@ -93,7 +93,7 @@ class ConfManager
|
|
93
93
|
FileUtils.rm_r(nested_dir) if File.directory?(nested_dir)
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
96
|
+
# Remaps a filepath from the source to the target directory.
|
97
97
|
#
|
98
98
|
# TODO:check if this works with relative paths (i.e. <code>../imgs/bar.png</code>)
|
99
99
|
|
@@ -103,6 +103,7 @@ class ConfManager
|
|
103
103
|
|
104
104
|
|
105
105
|
# Generates a file pattern suitable to be expanded by ruby's {Dir[]}[http://ruby-doc.org/core/classes/Dir.html] method.
|
106
|
+
|
106
107
|
def mkpath(pattern,dir=@source_dir)
|
107
108
|
dir.to_a.push(pattern).join('/')
|
108
109
|
end
|
@@ -126,6 +127,7 @@ class ConfManager
|
|
126
127
|
end
|
127
128
|
|
128
129
|
# Parses configuration files and sets user-defined file inclusion/exlusion patterns.
|
130
|
+
|
129
131
|
def parse_conf(configfile="#{ENV['HOME']}/#{@conf_filename}")
|
130
132
|
notify("Parsing configuration file: #{configfile}",:debug)
|
131
133
|
conf=YAML::load_file( configfile )
|
data/lib/domCompiler.rb
CHANGED
@@ -7,32 +7,29 @@ class DOMCompiler
|
|
7
7
|
# @dom_extnames=['.html','.svg']
|
8
8
|
@cm=ConfManager.instance
|
9
9
|
#if @cm.link_assets_to and not @cm.link_assets_to.empty?
|
10
|
-
@dom_documents=@cm.get_conf(:dom_documents).
|
10
|
+
@dom_documents=@cm.get_conf(:dom_documents).to_a
|
11
11
|
end
|
12
12
|
# Retrieves a resource, being this either a URL or a file.
|
13
13
|
def get_resource(path_or_url)
|
14
|
-
|
15
|
-
target_path=remap_filepath(path_or_url)
|
16
|
-
puts "tp: #{target_path}"
|
17
|
-
f=open(target_path)
|
14
|
+
f=open(remap_filepath(path_or_url))
|
18
15
|
(f.is_a? File)? f.read : f
|
19
16
|
end
|
20
|
-
|
21
|
-
|
17
|
+
# Iterates over a DOM element and allows to apply a custom block over it.
|
18
|
+
|
22
19
|
def iterate_over(selector)
|
23
20
|
@dom_documents.each do |path|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if doc
|
21
|
+
doc=Hpricot(open(path))
|
22
|
+
if doc
|
28
23
|
doc.search(selector).each do |element|
|
29
|
-
|
24
|
+
|
25
|
+
#$log.debug..
|
26
|
+
yield(element, doc)
|
27
|
+
# save document
|
28
|
+
#write_file(doc.innerHTML, [@cm.target_dir, File.basename(path) ].join('/') )
|
30
29
|
write_file(doc.innerHTML, path )
|
31
30
|
end
|
32
31
|
else
|
33
|
-
notify("DOMCompiler cannot parse #{path}"
|
34
|
-
:error
|
35
|
-
)
|
32
|
+
notify("DOMCompiler cannot parse #{path}",:error)
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
data/lib/sqweezeUtils.rb
CHANGED
@@ -10,8 +10,9 @@ module SqweezeUtils
|
|
10
10
|
'.tiff' => 'image/tiff',
|
11
11
|
'.ttf' => 'font/truetype',
|
12
12
|
'.otf' => 'font/opentype'
|
13
|
-
}
|
13
|
+
}
|
14
14
|
|
15
|
+
|
15
16
|
def write_file(fbody,fpath)
|
16
17
|
File.open(fpath,'w') do |f|
|
17
18
|
f.write(fbody)
|
@@ -31,46 +32,26 @@ module SqweezeUtils
|
|
31
32
|
# Otherwise, if the resource is a relative url in the source dir, try
|
32
33
|
# to map it to its compressed version in the target directory
|
33
34
|
|
34
|
-
def remap_filepath(path)
|
35
|
-
|
36
|
-
|
37
|
-
# Handle file paths at 0 level of depth 'style.css'
|
38
|
-
path_basename = path if path_basename.nil?
|
39
|
-
|
40
|
-
parent_dir = get_confManager().target_dir if parent_dir.gsub(/\/$/,'') == get_confManager().source_dir.gsub(/\/$/,'')
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
def remap_filepath(path)
|
36
|
+
path=Pathname.new(path)
|
37
|
+
parent_dir, path_basename = path.parent, path.basename
|
44
38
|
is_absolute = URI.parse(path).absolute?
|
45
39
|
unless is_absolute
|
46
|
-
|
47
|
-
find_file_in_targetdir([parent_dir, path_basename].join('/'))
|
40
|
+
find_file_in_targetdir( [parent_dir, path_basename].join('/'))
|
48
41
|
else
|
49
|
-
path
|
42
|
+
path.to_s
|
50
43
|
end
|
51
44
|
end
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
# Find a file in the target directory
|
56
|
-
# endpath is a string containing parent directory and file name
|
57
|
-
# (e.g imgs/separator.png)
|
58
|
-
|
59
|
-
def find_file_in_targetdir(endpath)
|
60
|
-
pattern= [get_confManager.target_dir,"**/**"].join('/')
|
61
|
-
# puts "Searching for #{endpath} into #{pattern}"
|
62
|
-
Dir[pattern].find{|path| path =~ Regexp.new("#{endpath}$")}
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
46
|
# Return the Base64-encoded contents of an asset on a single line.
|
68
47
|
def encoded_contents(asset_path)
|
69
48
|
data = open(asset_path, 'rb'){|f| f.read }
|
70
49
|
Base64.encode64(data).gsub(/\n/, '')
|
71
50
|
end
|
72
51
|
|
73
|
-
|
52
|
+
|
53
|
+
# Gets the byte weight of input strames, wether these are file paths or just strings
|
54
|
+
|
74
55
|
def byteweight(path_or_string)
|
75
56
|
path_or_string="" if path_or_string.nil?
|
76
57
|
|
@@ -87,6 +68,18 @@ module SqweezeUtils
|
|
87
68
|
sprintf('%.2f',after_bweight/before_bweight.to_f * 100)
|
88
69
|
end
|
89
70
|
|
71
|
+
|
72
|
+
# Find a file in the target directory
|
73
|
+
# endpath is a string containing parent directory and file name
|
74
|
+
# (e.g imgs/separator.png)
|
75
|
+
|
76
|
+
# TODO: rewrite this! (it sucks..)
|
77
|
+
|
78
|
+
def find_file_in_targetdir(endpath)
|
79
|
+
pattern= [get_confManager.target_dir,"**/*#{File.extname(endpath)}"].join('/')
|
80
|
+
#puts "searcing for files in #{pattern} ending with #{endpath}"
|
81
|
+
Dir[pattern].find{|path| path =~ Regexp.new("#{endpath}$")}
|
82
|
+
end
|
90
83
|
|
91
84
|
|
92
85
|
# Prints to STDERR and adds a log entry.
|
data/spec/confManager_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'sqw_spec_helper'
|
2
2
|
|
3
|
+
|
3
4
|
describe ConfManager do
|
4
5
|
context "Starting up" do
|
5
6
|
|
@@ -9,7 +10,7 @@ describe ConfManager do
|
|
9
10
|
|
10
11
|
after(:each) do
|
11
12
|
@cm=nil
|
12
|
-
# clean up
|
13
|
+
# clean up config files
|
13
14
|
%w( ENV['home'] test_dir ).each do |f|
|
14
15
|
f << "/.sqweeze.yml"
|
15
16
|
FileUtils.rm(f) if File.exists?(f)
|
@@ -17,37 +18,44 @@ describe ConfManager do
|
|
17
18
|
end
|
18
19
|
|
19
20
|
it "Should create a .sqweeze.yml file in the home directory" do
|
20
|
-
@cm.prepare('test_dir'
|
21
|
+
@cm.prepare('test_dir')
|
21
22
|
File.exists?("#{ENV['HOME']}/.sqweeze.yml").should be_true
|
22
23
|
end
|
23
24
|
|
24
25
|
it "Should select the list of files provided by the user if the *include:* section of the .sqweeze.yml is not empty" do
|
25
26
|
extra_lines= ["include:","- js/**/*.js",'- color/**/*.png']
|
26
27
|
write_configfile(extra_lines[0..1].join("\n"))
|
27
|
-
@cm.prepare('test_dir'
|
28
|
+
@cm.prepare('test_dir')
|
28
29
|
@cm.should have(3).files
|
29
30
|
|
30
31
|
write_configfile(extra_lines.join("\n"))
|
31
|
-
|
32
|
-
@cm.prepare('test_dir', 'test_dir_sqweeze', {:suppress_info => true} )
|
32
|
+
@cm.prepare('test_dir')
|
33
33
|
@cm.should have(5).files
|
34
34
|
end
|
35
|
+
|
35
36
|
it "Should select all files in the project if the include: section of .sqweeze.yml is left empty" do
|
36
37
|
project_file_count= Dir['test_dir/**/*'].reject{|f| File.directory?(f)}.size
|
37
|
-
@cm.prepare('test_dir'
|
38
|
+
@cm.prepare('test_dir')
|
38
39
|
@cm.should have(project_file_count).files
|
39
40
|
end
|
41
|
+
|
40
42
|
it "Should always exclude the files specified by the user in the .sqweeze.yml exclude section " do
|
41
43
|
write_configfile(["exclude:","- js/**/*.js"].join("\n"))
|
42
44
|
project_file_count= Dir['test_dir/**/*'].reject{|f| File.directory?(f)}.size
|
43
|
-
@cm.prepare('test_dir'
|
45
|
+
@cm.prepare('test_dir')
|
44
46
|
@cm.should have(46).files
|
45
47
|
end
|
46
|
-
|
48
|
+
|
47
49
|
it "Should search *dom_documents* in the the target directory " do
|
48
|
-
write_configfile("dom_documents: test_dir
|
49
|
-
@cm.prepare('test_dir'
|
50
|
-
@cm.get_conf(:dom_documents).should include('
|
51
|
-
end
|
50
|
+
write_configfile("dom_documents: test_dir/*/page.tpl.php")
|
51
|
+
@cm.prepare('test_dir')
|
52
|
+
@cm.get_conf(:dom_documents).should include('test_dir_sqweezed/tpl/page.tpl.php')
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
52
60
|
end
|
53
61
|
end
|
data/spec/domCompiler_spec.rb
CHANGED
@@ -1,37 +1,38 @@
|
|
1
|
+
require '../lib/confManager'
|
2
|
+
require '../lib/DomCompiler'
|
3
|
+
require '../lib/jsDomCompiler'
|
4
|
+
require '../lib/cssDomCompiler'
|
1
5
|
require 'sqw_spec_helper'
|
2
6
|
|
3
7
|
describe DOMCompiler do
|
4
8
|
before(:each) do
|
5
|
-
|
9
|
+
wget_webpage('http://www.dreamhost.com/domains.html','dom-testdir')
|
6
10
|
cm = ConfManager.instance
|
7
|
-
cm.prepare('dom-testdir','dom-testdir-build'
|
8
|
-
|
9
|
-
|
10
|
-
})
|
11
|
-
@js_c=JsDomCompiler.new
|
12
|
-
end
|
11
|
+
cm.prepare('dom-testdir','dom-testdir-build')
|
12
|
+
@js_c=JSDOMCompiler.new
|
13
|
+
end
|
13
14
|
|
14
15
|
after(:each) do
|
15
|
-
|
16
|
-
|
16
|
+
FileUtils.rm_r('dom-testdir')
|
17
|
+
FileUtils.rm_r('dom-testdir-build')
|
17
18
|
end
|
18
19
|
|
19
20
|
it "(all subclasses) should look for *dom_documents* in target directory" do
|
20
21
|
@js_c.should have(1).dom_documents
|
21
|
-
@js_c.dom_documents.should include('dom-testdir-build/
|
22
|
+
@js_c.dom_documents.should include('dom-testdir-build/index.html')
|
22
23
|
end
|
23
24
|
|
24
25
|
it "Should fill each script element having a src attribute with the compressed content of the javascript file therin referenciated" do
|
25
26
|
@js_c.compile
|
26
27
|
|
27
|
-
Hpricot( open('dom-testdir-build/
|
28
|
+
Hpricot( open('dom-testdir-build/index.html')).search('script').each do |element|
|
28
29
|
element.innerHTML.should_not be_empty
|
29
30
|
element.get_attribute('src').should be_nil
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
it "Should fill each link tag having a href attribute with the compressed content of the css file therein referenced" do
|
34
|
-
@css_c=
|
35
|
+
@css_c=CSSDOMCompiler.new
|
35
36
|
@css_c.compile()
|
36
37
|
end
|
37
38
|
|
data/spec/sqw_spec_helper.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'fileutils'
|
4
|
-
require 'logger'
|
5
|
-
require 'open-uri'
|
6
|
-
require 'pp'
|
7
|
-
require 'yui/compressor'
|
8
|
-
require 'closure-compiler'
|
9
|
-
require 'hpricot'
|
10
|
-
require '../lib/sqweezeUtils'
|
11
|
-
require '../lib/confManager'
|
12
|
-
require '../lib/domCompiler'
|
13
|
-
require '../lib/compilers/jsDomCompiler'
|
14
|
-
require '../lib/compilers/cssDomCompiler'
|
15
|
-
|
16
|
-
|
17
|
-
SQW_CONF_FILE='test_dir/.sqweeze.yml'
|
18
|
-
SQW_FBODY=<<EOF
|
1
|
+
SQW_CONF_FILE='test_dir/.sqweeze.yml'
|
2
|
+
SQW_FBODY=<<EOF
|
19
3
|
bin_paths:
|
20
4
|
- pngcrush: /usr/bin/pngcrush
|
21
5
|
- jpegtran: /usr/bin/jpegtran
|
data/sqweeze.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sqweeze}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.7"
|
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"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-08-20}
|
10
10
|
s.default_executable = %q{sqweeze}
|
11
11
|
s.description = %q{A command line web-asset optimisation tool}
|
12
12
|
s.email = %q{and@inventati.org}
|
13
13
|
s.executables = ["sqweeze"]
|
14
14
|
s.extra_rdoc_files = ["README.rdoc", "bin/sqweeze", "lib/compilers/assetLinker.rb", "lib/compilers/cssDomCompiler.rb", "lib/compilers/jsDomCompiler.rb", "lib/compressor.rb", "lib/compressors/cssCompressor.rb", "lib/compressors/gifCompressor.rb", "lib/compressors/jpegCompressor.rb", "lib/compressors/jsCompressor.rb", "lib/compressors/pngCompressor.rb", "lib/confManager.rb", "lib/domCompiler.rb", "lib/sqweezeUtils.rb"]
|
15
|
-
s.files = ["
|
16
|
-
s.homepage = %q{http://github.com/
|
15
|
+
s.files = ["README.rdoc", "Rakefile", "bin/sqweeze", "lib/compilers/assetLinker.rb", "lib/compilers/cssDomCompiler.rb", "lib/compilers/jsDomCompiler.rb", "lib/compressor.rb", "lib/compressors/cssCompressor.rb", "lib/compressors/gifCompressor.rb", "lib/compressors/jpegCompressor.rb", "lib/compressors/jsCompressor.rb", "lib/compressors/pngCompressor.rb", "lib/confManager.rb", "lib/domCompiler.rb", "lib/sqweezeUtils.rb", "spec/confManager_spec.rb", "spec/domCompiler_spec.rb", "spec/sqw_spec_helper.rb", "Manifest", "sqweeze.gemspec"]
|
16
|
+
s.homepage = %q{http://github.com/afiore/sqwidget-builder}
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sqweeze", "--main", "README.rdoc"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubyforge_project = %q{sqweeze}
|
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqweeze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
version: 0.0.6
|
4
|
+
version: 0.0.7
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Andrea Fiore
|
@@ -14,61 +9,45 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-
|
12
|
+
date: 2010-08-20 00:00:00 +01:00
|
18
13
|
default_executable: sqweeze
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: hpricot
|
22
|
-
|
23
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
23
|
version: "0"
|
30
24
|
- - "="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
segments:
|
33
|
-
- 0
|
34
|
-
- 8
|
35
|
-
- 2
|
36
26
|
version: 0.8.2
|
37
|
-
|
38
|
-
version_requirements: *id001
|
27
|
+
version:
|
39
28
|
- !ruby/object:Gem::Dependency
|
40
29
|
name: closure-compiler
|
41
|
-
|
42
|
-
|
30
|
+
type: :runtime
|
31
|
+
version_requirement:
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
33
|
requirements:
|
44
34
|
- - ">="
|
45
35
|
- !ruby/object:Gem::Version
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 2
|
49
|
-
- 2
|
50
36
|
version: 0.2.2
|
51
|
-
|
52
|
-
version_requirements: *id002
|
37
|
+
version:
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
39
|
name: yui-compressor
|
55
|
-
|
56
|
-
|
40
|
+
type: :runtime
|
41
|
+
version_requirement:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
43
|
requirements:
|
58
44
|
- - ">="
|
59
45
|
- !ruby/object:Gem::Version
|
60
|
-
segments:
|
61
|
-
- 0
|
62
46
|
version: "0"
|
63
47
|
- - "="
|
64
48
|
- !ruby/object:Gem::Version
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
- 9
|
68
|
-
- 1
|
69
49
|
version: 0.9.1
|
70
|
-
|
71
|
-
version_requirements: *id003
|
50
|
+
version:
|
72
51
|
description: A command line web-asset optimisation tool
|
73
52
|
email: and@inventati.org
|
74
53
|
executables:
|
@@ -91,7 +70,6 @@ extra_rdoc_files:
|
|
91
70
|
- lib/domCompiler.rb
|
92
71
|
- lib/sqweezeUtils.rb
|
93
72
|
files:
|
94
|
-
- Manifest
|
95
73
|
- README.rdoc
|
96
74
|
- Rakefile
|
97
75
|
- bin/sqweeze
|
@@ -110,9 +88,10 @@ files:
|
|
110
88
|
- spec/confManager_spec.rb
|
111
89
|
- spec/domCompiler_spec.rb
|
112
90
|
- spec/sqw_spec_helper.rb
|
91
|
+
- Manifest
|
113
92
|
- sqweeze.gemspec
|
114
93
|
has_rdoc: true
|
115
|
-
homepage: http://github.com/
|
94
|
+
homepage: http://github.com/afiore/sqwidget-builder
|
116
95
|
licenses: []
|
117
96
|
|
118
97
|
post_install_message:
|
@@ -129,21 +108,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
108
|
requirements:
|
130
109
|
- - ">="
|
131
110
|
- !ruby/object:Gem::Version
|
132
|
-
segments:
|
133
|
-
- 0
|
134
111
|
version: "0"
|
112
|
+
version:
|
135
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
114
|
requirements:
|
137
115
|
- - ">="
|
138
116
|
- !ruby/object:Gem::Version
|
139
|
-
segments:
|
140
|
-
- 1
|
141
|
-
- 2
|
142
117
|
version: "1.2"
|
118
|
+
version:
|
143
119
|
requirements: []
|
144
120
|
|
145
121
|
rubyforge_project: sqweeze
|
146
|
-
rubygems_version: 1.3.
|
122
|
+
rubygems_version: 1.3.5
|
147
123
|
signing_key:
|
148
124
|
specification_version: 3
|
149
125
|
summary: A command line web-asset optimisation tool
|