Skip to content

Commit adaa3de

Browse files
committed
Late instantiation of Jammit::Compressor
At least one method inside Jammit::Packager, individual_urls, does not need @compressor. Skipping Compressor.new is nice because it calls `java -version` inside initialize.
1 parent 829ad88 commit adaa3de

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

lib/jammit/packager.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Packager
1414
# Jammit.configuration. When assets.yml is being changed on the fly,
1515
# create a new Packager.
1616
def initialize
17-
@compressor = Compressor.new
1817
@force = false
1918
@package_names = nil
2019
@config = {
@@ -71,21 +70,25 @@ def individual_urls(package, extension)
7170
package_for(package, extension)[:urls]
7271
end
7372

73+
def compressor
74+
@compressor ||= Compressor.new
75+
end
76+
7477
# Return the compressed contents of a stylesheet package.
7578
def pack_stylesheets(package, variant=nil, asset_url=nil)
76-
@compressor.compress_css(package_for(package, :css)[:paths], variant, asset_url)
79+
compressor.compress_css(package_for(package, :css)[:paths], variant, asset_url)
7780
end
7881

7982
# Return the compressed contents of a javascript package.
8083
def pack_javascripts(package)
81-
@compressor.compress_js(package_for(package, :js)[:paths])
84+
compressor.compress_js(package_for(package, :js)[:paths])
8285
end
8386

8487
# Return the compiled contents of a JST package.
8588
def pack_templates(package)
86-
@compressor.compile_jst(package_for(package, :js)[:paths])
89+
compressor.compile_jst(package_for(package, :js)[:paths])
8790
end
88-
91+
8992

9093
private
9194

@@ -109,7 +112,7 @@ def glob_files(glob)
109112
def path_to_url
110113
@path_to_url ||= /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(Jammit.public_root.sub(ASSET_ROOT, ''))})?/
111114
end
112-
115+
113116
# Get the latest mtime of a list of files (plus the config path).
114117
def latest_mtime(paths)
115118
paths += [Jammit.config_path]

0 commit comments

Comments
 (0)