sqweeze 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,29 +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
- * 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,
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,
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 by running a single command line
18
+ On an Ubuntu box, you can install these all in once by running a single command line
19
19
 
20
20
  sudo apt-get install pngcrush gifsicle libjpeg-progs
21
21
 
22
22
  Mac OSX users can install the first two as Macports packages. The third (part of libjpeg) instead, has to be
23
23
  {compiled manually}[http://www.phpied.com/installing-jpegtran-mac-unix-linux].
24
24
 
25
- Once installed these, you can install _Sqweeze_ using rubygems
25
+ Once installed these third party tools, you can install _Sqweeze_ using the rubygems package manager
26
26
 
27
27
  gem install sqweeze
28
28
 
29
+ (this assumes that you have both ruby and rugygems installed).
30
+
29
31
  === Configuration
30
32
 
31
- 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.
33
+ 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.
32
34
 
33
35
  # file $HOME/.sqweeze.yml
34
36
 
@@ -37,4 +39,45 @@ When run for the first time, the script creates a config file in the user's $HOM
37
39
  - jpegtran: /usr/bin/jpegtran
38
40
  - gifsicle: /usr/bin/gifsicle
39
41
 
40
- If you have installed these anywhere else than in /usr/bin+, you will have to edit this file so that sqweeze can find them.
42
+ 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.
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
+ [....]
@@ -1,5 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
- # rubygems
2
+
3
+
4
+ # third party libs
3
5
  %w[rubygems yui/compressor closure-compiler hpricot].each{|lib| require lib}
4
6
  # ruby standard library
5
7
  %w[logger singleton yaml base64 open-uri pathname optparse fileutils].each{|lib| require lib}
@@ -24,7 +26,7 @@ op=OptionParser.new do |opts|
24
26
 
25
27
  opts.banner = "Usage: sqweeze [options] SOURCE_DIR [TARGET_DIR]"
26
28
  opts.program_name= 'sqweeze'
27
- opts.on("-s", "--optimisation-strategy=ALL_IN_ONE",
29
+ opts.on("-S", "--optimisation-strategy=ALL_IN_ONE",
28
30
  "JavaScript/CSS optimisation strategy to be adopted ") do |s|
29
31
  raise OptionParser::InvalidArgument unless ['all_inline','all_in_one'].include?(s)
30
32
  options[:optimisation_strategy] = s.downcase.to_sym
@@ -38,7 +40,7 @@ op=OptionParser.new do |opts|
38
40
  opts.on('-e','--exclude-files=PATTERN', "Exclude a file/directory pattern (e.g. doc/**/*.* )") do |exc|
39
41
  options[:exclude_files] = exc
40
42
  end
41
- opts.on('-d','--dom-documents=PATTERN', "Dom document/s to which CSS/JS should be linked (e.g. **/index.html )") do |dom|
43
+ opts.on('-D','--dom-documents=PATTERN', "Dom document/s to which CSS/JS should be linked (e.g. **/index.html )") do |dom|
42
44
  options[:dom_documents] = dom
43
45
  end
44
46
 
@@ -93,12 +95,13 @@ begin
93
95
  op.parse!
94
96
  Proc.new { puts "Missing SOURCE_DIR argument"; exit(1) }.call unless ARGV[0]
95
97
  Proc.new { puts "source directory #{ARGV[0]} does not exist, please provide a valid path"
96
- exit(1) }.call unless File.exists?(ARGV[0])
98
+ exit(1) }.call unless ARGV[0] and File.exists?(ARGV[0])
97
99
 
98
100
 
99
101
  cm=ConfManager.instance
100
102
  cm.prepare(ARGV[0], ARGV[1], options)
101
-
103
+
104
+
102
105
  # Compress images
103
106
  { :compress_png => PngCompressor.new,
104
107
  :compress_gif => GifCompressor.new,
@@ -109,16 +112,17 @@ begin
109
112
 
110
113
  case cm.get_conf(:optimisation_strategy)
111
114
  when :all_inline
112
- puts "not implemented yet.."
113
- exit
114
-
115
+ raise "You must specify a valid DOM document to use the inline strategy" unless File.exists?(cm.get_conf(:dom_documents).first)
116
+ JsDomCompiler.new.compile
117
+ CssDomCompiler.new.compile
115
118
 
116
119
  when :all_in_one
120
+
117
121
  { :compress_js => JsCompressor.new,
118
122
  :compress_css => CssCompressor.new
119
123
  }.each do |opt, cmp|
120
124
  cmp.compress unless cm.get_conf(opt) == false
121
- end
125
+ end
122
126
  # link assets to main HTML file
123
127
  AssetLinker.new.compile unless cm.get_conf(:dom_documents).empty?
124
128
  end
@@ -7,27 +7,32 @@ class AssetLinker < DOMCompiler
7
7
  # Otherwise delete.
8
8
  elm.parent.children.delete(elm)
9
9
  end
10
+
10
11
  dom_documents.each do |path|
12
+ target_path=remap_filepath(path)
13
+
11
14
  # Append concatenated JavaScript file.
15
+
12
16
  doc = Hpricot(open(path))
13
17
  doc.search(@cm.get_conf(:append_scripts_to).to_s.downcase).append( "<script type='text/javascript' src='javascripts.min.js'></script>")
14
-
18
+
19
+ notify("#{ansi_bold(target_path)}:".ljust(60) + ansi_green("Appending Sylesheets"),:info)
20
+
15
21
  stylesheets_html=<<EOF
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]-->
22
+
23
+ <!--[if (!IE)|(gte IE 8)]><!-->
24
+ <link href="stylesheets.min.datauri.css" media="screen" rel="stylesheet" type="text/css" />
25
+ <!--<![endif]-->
26
+ <!--[if lte IE 7]>
27
+ <link href="stylesheets.min.mhtml.css" media="screen" rel="stylesheet" type="text/css" />
28
+ <![endif]-->
25
29
  EOF
26
-
27
- # Append ie conditional tags
28
- doc.search('head').append(stylesheets_html)
29
- write_file(doc.innerHTML,path)
30
- end
30
+
31
+ # Append concatenated CSS files, wrapping them within IE conditional tags
32
+ doc.search('head').append(stylesheets_html)
33
+ notify("#{ansi_bold(target_path)}:".ljust(60)+ansi_green("Appending Sylesheets"),:info)
34
+ write_file(doc.innerHTML, target_path)
35
+ end
31
36
  end
32
37
 
33
38
  end
@@ -12,7 +12,7 @@ class JsDomCompiler < DOMCompiler
12
12
 
13
13
 
14
14
  def compress(fbody)
15
- unless @cm.default_js_compressor == :closure
15
+ unless @cm.get_conf(: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,9 +19,8 @@ class CssCompressor < Compressor
19
19
  EMBED_DETECTOR = /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/
20
20
 
21
21
  # MHTML file constants.
22
- MHTML_START = "/*\nContent-Type: multipart/related; boundary=\"SQWEEZED_ASSET\"\n"
23
- MHTML_SEPARATOR= "--SQWEEZED_ASSET"
24
- MHTML_END = "*/\n"
22
+ MHTML_START = "/*\r\nContent-Type: multipart/related; boundary=\"SQWEEZED_ASSET\"\r\n\r\n"
23
+ MHTML_SEPARATOR= "--SQWEEZED_ASSET\r\n"
25
24
 
26
25
  def initialize
27
26
  super('css')
@@ -59,12 +58,16 @@ class CssCompressor < Compressor
59
58
  end
60
59
 
61
60
  def embed_datauris(compressed_css)
61
+
62
62
  out=compressed_css.gsub(EMBED_DETECTOR) do |url|
63
- compressed_asset_path=remap_filepath($1)
63
+
64
+ compressed_asset_path=remap_filepath($1)
64
65
  mime_t=mime_type(compressed_asset_path)
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
+
66
68
  base64_asset=encoded_contents( compressed_asset_path )
67
- $log.debug("file:#{compressed_asset_path}; mime-type: #{mime_type($1)}#")
69
+
70
+ notify("file:#{compressed_asset_path}; mime-type: #{mime_type($1)}#",:debug)
68
71
  # label the image
69
72
  @assets[ compressed_asset_path ] = base64_asset
70
73
  "url(\"data:#{mime_t};charset=utf-8;base64,#{base64_asset}\")"
@@ -73,7 +76,9 @@ class CssCompressor < Compressor
73
76
  end
74
77
  end
75
78
 
76
-
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)
77
82
  write_file(out,"#{@cm.target_dir}/stylesheets.min.datauri.css")
78
83
  end
79
84
 
@@ -82,18 +87,18 @@ class CssCompressor < Compressor
82
87
  mhtml= MHTML_START
83
88
 
84
89
  @assets.each do |mhtml_loc,base64|
85
- mhtml <<"
86
- #{MHTML_SEPARATOR}
87
- Content-location: #{ mhtml_loc }
88
- Content-Transfer-Encoding:base64
89
-
90
- #{base64}\n"
90
+ mhtml << [MHTML_SEPARATOR,
91
+ "Content-location: #{mhtml_loc}\r\n",
92
+ "Content-Transfer-Encoding: base64\r\n",
93
+ "Content-type: #{mime_type(mhtml_loc)} \r\n\r\n",
94
+ "#{base64}\r\n"
95
+ ].join('')
91
96
  end
92
- mhtml << "*/\n"
97
+ mhtml << "*/\r\n"
93
98
  mhtml << compressed_css.gsub(EMBED_DETECTOR) do |css|
94
99
  compressed_asset_path=remap_filepath($1)
95
100
  if compressed_asset_path
96
- "url(mhtml:#{@cm.get_conf(:mhtml_root).gsub(/\/$/,'')}/stylesheets.min.mhtml.css!#{mhtml_location( compressed_asset_path)})"
101
+ "url(mhtml:#{@cm.get_conf(:mhtml_root).gsub(/\/$/,'')}/stylesheets.min.mhtml.css!#{compressed_asset_path})"
97
102
  else
98
103
  "url(#{$1})"
99
104
  end
@@ -37,7 +37,7 @@ class ConfManager
37
37
  }
38
38
  end
39
39
  attr_reader :target_dir,:source_dir,
40
- :files,:conf_filename,:conf
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
- # Remaps a filepath from the source to the target directory.
96
+ # Re-maps a file path 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,7 +103,6 @@ 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
-
107
106
  def mkpath(pattern,dir=@source_dir)
108
107
  dir.to_a.push(pattern).join('/')
109
108
  end
@@ -127,7 +126,6 @@ class ConfManager
127
126
  end
128
127
 
129
128
  # Parses configuration files and sets user-defined file inclusion/exlusion patterns.
130
-
131
129
  def parse_conf(configfile="#{ENV['HOME']}/#{@conf_filename}")
132
130
  notify("Parsing configuration file: #{configfile}",:debug)
133
131
  conf=YAML::load_file( configfile )
@@ -7,29 +7,32 @@ 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).to_a
10
+ @dom_documents=@cm.get_conf(:dom_documents).collect{|path| remap_filepath(path) }
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
- f=open(remap_filepath(path_or_url))
14
+ puts "opening ..#{path_or_url}"
15
+ target_path=remap_filepath(path_or_url)
16
+ puts "tp: #{target_path}"
17
+ f=open(target_path)
15
18
  (f.is_a? File)? f.read : f
16
19
  end
17
- # Iterates over a DOM element and allows to apply a custom block over it.
18
-
20
+
21
+ # Iterates over a DOM element and allows to apply a custom block over it.
19
22
  def iterate_over(selector)
20
23
  @dom_documents.each do |path|
21
- doc=Hpricot(open(path))
22
- if doc
24
+ raise "File #{path} does not seem to exist" unless File.exists?(path)
25
+ doc=Hpricot(open(path))
26
+
27
+ if doc
23
28
  doc.search(selector).each do |element|
24
-
25
- #$log.debug..
26
- yield(element, doc)
27
- # save document
28
- #write_file(doc.innerHTML, [@cm.target_dir, File.basename(path) ].join('/') )
29
+ yield(element, doc)
29
30
  write_file(doc.innerHTML, path )
30
31
  end
31
32
  else
32
- notify("DOMCompiler cannot parse #{path}",:error)
33
+ notify("DOMCompiler cannot parse #{path}",
34
+ :error
35
+ )
33
36
  end
34
37
  end
35
38
  end
@@ -10,9 +10,8 @@ module SqweezeUtils
10
10
  '.tiff' => 'image/tiff',
11
11
  '.ttf' => 'font/truetype',
12
12
  '.otf' => 'font/opentype'
13
- }
13
+ }
14
14
 
15
-
16
15
  def write_file(fbody,fpath)
17
16
  File.open(fpath,'w') do |f|
18
17
  f.write(fbody)
@@ -32,26 +31,46 @@ module SqweezeUtils
32
31
  # Otherwise, if the resource is a relative url in the source dir, try
33
32
  # to map it to its compressed version in the target directory
34
33
 
35
- def remap_filepath(path)
36
- path=Pathname.new(path)
37
- parent_dir, path_basename = path.parent, path.basename
34
+ def remap_filepath(path)
35
+ parent_dir, path_basename = path.split('/')[-2..-1]
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
+
38
44
  is_absolute = URI.parse(path).absolute?
39
45
  unless is_absolute
40
- find_file_in_targetdir( [parent_dir, path_basename].join('/'))
46
+
47
+ find_file_in_targetdir([parent_dir, path_basename].join('/'))
41
48
  else
42
- path.to_s
49
+ path
43
50
  end
44
51
  end
45
52
 
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
+
46
67
  # Return the Base64-encoded contents of an asset on a single line.
47
68
  def encoded_contents(asset_path)
48
69
  data = open(asset_path, 'rb'){|f| f.read }
49
70
  Base64.encode64(data).gsub(/\n/, '')
50
71
  end
51
72
 
52
-
53
- # Gets the byte weight of input strames, wether these are file paths or just strings
54
-
73
+ # Gets the byte weight of input strames, wether these are file paths or just strings
55
74
  def byteweight(path_or_string)
56
75
  path_or_string="" if path_or_string.nil?
57
76
 
@@ -68,18 +87,6 @@ module SqweezeUtils
68
87
  sprintf('%.2f',after_bweight/before_bweight.to_f * 100)
69
88
  end
70
89
 
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
83
90
 
84
91
 
85
92
  # Prints to STDERR and adds a log entry.
@@ -1,6 +1,5 @@
1
1
  require 'sqw_spec_helper'
2
2
 
3
-
4
3
  describe ConfManager do
5
4
  context "Starting up" do
6
5
 
@@ -10,7 +9,7 @@ describe ConfManager do
10
9
 
11
10
  after(:each) do
12
11
  @cm=nil
13
- # clean up config files
12
+ # clean up local configuration file
14
13
  %w( ENV['home'] test_dir ).each do |f|
15
14
  f << "/.sqweeze.yml"
16
15
  FileUtils.rm(f) if File.exists?(f)
@@ -18,44 +17,37 @@ describe ConfManager do
18
17
  end
19
18
 
20
19
  it "Should create a .sqweeze.yml file in the home directory" do
21
- @cm.prepare('test_dir')
20
+ @cm.prepare('test_dir', 'test_dir_sqweeze', {:suppress_info => true} )
22
21
  File.exists?("#{ENV['HOME']}/.sqweeze.yml").should be_true
23
22
  end
24
23
 
25
24
  it "Should select the list of files provided by the user if the *include:* section of the .sqweeze.yml is not empty" do
26
25
  extra_lines= ["include:","- js/**/*.js",'- color/**/*.png']
27
26
  write_configfile(extra_lines[0..1].join("\n"))
28
- @cm.prepare('test_dir')
27
+ @cm.prepare('test_dir', 'test_dir_sqweeze', {:suppress_info => true} )
29
28
  @cm.should have(3).files
30
29
 
31
30
  write_configfile(extra_lines.join("\n"))
32
- @cm.prepare('test_dir')
31
+
32
+ @cm.prepare('test_dir', 'test_dir_sqweeze', {:suppress_info => true} )
33
33
  @cm.should have(5).files
34
34
  end
35
-
36
35
  it "Should select all files in the project if the include: section of .sqweeze.yml is left empty" do
37
36
  project_file_count= Dir['test_dir/**/*'].reject{|f| File.directory?(f)}.size
38
- @cm.prepare('test_dir')
37
+ @cm.prepare('test_dir', 'test_dir_sqweeze',:suppress_info => true)
39
38
  @cm.should have(project_file_count).files
40
39
  end
41
-
42
40
  it "Should always exclude the files specified by the user in the .sqweeze.yml exclude section " do
43
41
  write_configfile(["exclude:","- js/**/*.js"].join("\n"))
44
42
  project_file_count= Dir['test_dir/**/*'].reject{|f| File.directory?(f)}.size
45
- @cm.prepare('test_dir')
43
+ @cm.prepare('test_dir', 'test_dir_sqweeze',:suppress_info => true)
46
44
  @cm.should have(46).files
47
45
  end
48
-
49
- it "Should search *dom_documents* in the the target directory " do
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
46
 
47
+ it "Should search *dom_documents* in the the target directory " do
48
+ write_configfile("dom_documents: test_dir/**/*.php")
49
+ @cm.prepare('test_dir', 'test_dir_sqweeze',:suppress_info => true)
50
+ @cm.get_conf(:dom_documents).should include('test_dir_sqweeze/tpl/page.tpl.php')
51
+ end
60
52
  end
61
53
  end
@@ -1,38 +1,37 @@
1
- require '../lib/confManager'
2
- require '../lib/DomCompiler'
3
- require '../lib/jsDomCompiler'
4
- require '../lib/cssDomCompiler'
5
1
  require 'sqw_spec_helper'
6
2
 
7
3
  describe DOMCompiler do
8
4
  before(:each) do
9
- wget_webpage('http://www.dreamhost.com/domains.html','dom-testdir')
5
+ wget_webpage('http://www.dreamhost.com/domains.html','dom-testdir')
10
6
  cm = ConfManager.instance
11
- cm.prepare('dom-testdir','dom-testdir-build')
12
- @js_c=JSDOMCompiler.new
13
- end
7
+ cm.prepare('dom-testdir','dom-testdir-build',{
8
+ :suppress_info => true,
9
+ :dom_documents => '*.html'
10
+ })
11
+ @js_c=JsDomCompiler.new
12
+ end
14
13
 
15
14
  after(:each) do
16
- FileUtils.rm_r('dom-testdir')
17
- FileUtils.rm_r('dom-testdir-build')
15
+ #FileUtils.rm_r('dom-testdir')
16
+ #FileUtils.rm_r('dom-testdir-build')
18
17
  end
19
18
 
20
19
  it "(all subclasses) should look for *dom_documents* in target directory" do
21
20
  @js_c.should have(1).dom_documents
22
- @js_c.dom_documents.should include('dom-testdir-build/index.html')
21
+ @js_c.dom_documents.should include('dom-testdir-build/domains.html')
23
22
  end
24
23
 
25
24
  it "Should fill each script element having a src attribute with the compressed content of the javascript file therin referenciated" do
26
25
  @js_c.compile
27
26
 
28
- Hpricot( open('dom-testdir-build/index.html')).search('script').each do |element|
27
+ Hpricot( open('dom-testdir-build/domains.html')).search('script').each do |element|
29
28
  element.innerHTML.should_not be_empty
30
29
  element.get_attribute('src').should be_nil
31
30
  end
32
31
  end
33
32
 
34
33
  it "Should fill each link tag having a href attribute with the compressed content of the css file therein referenced" do
35
- @css_c=CSSDOMCompiler.new
34
+ @css_c=CssDomCompiler.new
36
35
  @css_c.compile()
37
36
  end
38
37
 
@@ -1,5 +1,21 @@
1
- SQW_CONF_FILE='test_dir/.sqweeze.yml'
2
- SQW_FBODY=<<EOF
1
+ require 'singleton'
2
+ require 'hpricot'
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
3
19
  bin_paths:
4
20
  - pngcrush: /usr/bin/pngcrush
5
21
  - jpegtran: /usr/bin/jpegtran
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{sqweeze}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.6"
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"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
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
15
  s.files = ["Manifest", "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", "sqweeze.gemspec"]
16
- s.homepage = %q{http://github.com/premasagar/sqwidget-builder}
16
+ s.homepage = %q{http://github.com/premasagar/sqweeze}
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
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrea Fiore
@@ -112,7 +112,7 @@ files:
112
112
  - spec/sqw_spec_helper.rb
113
113
  - sqweeze.gemspec
114
114
  has_rdoc: true
115
- homepage: http://github.com/premasagar/sqwidget-builder
115
+ homepage: http://github.com/premasagar/sqweeze
116
116
  licenses: []
117
117
 
118
118
  post_install_message: