Class: Sprockets::StaticCompiler
- Inherits:
-
Object
- Object
- Sprockets::StaticCompiler
- Defined in:
- lib/sprockets/static_compiler.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#env ⇒ Object
Returns the value of attribute env.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #compile(asset) ⇒ Object
- #digest_asset(asset) ⇒ Object
-
#initialize(env, target, options = {}) ⇒ StaticCompiler
constructor
A new instance of StaticCompiler.
- #precompile(paths) ⇒ Object
- #precompile_path?(logical_path, paths) ⇒ Boolean
Constructor Details
#initialize(env, target, options = {}) ⇒ StaticCompiler
Returns a new instance of StaticCompiler.
8 9 10 11 12 |
# File 'lib/sprockets/static_compiler.rb', line 8 def initialize(env, target, = {}) @env = env @target = target @digest = .key?(:digest) ? .delete(:digest) : true end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
6 7 8 |
# File 'lib/sprockets/static_compiler.rb', line 6 def digest @digest end |
#env ⇒ Object
Returns the value of attribute env.
6 7 8 |
# File 'lib/sprockets/static_compiler.rb', line 6 def env @env end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/sprockets/static_compiler.rb', line 6 def target @target end |
Instance Method Details
#compile(asset) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/sprockets/static_compiler.rb', line 25 def compile(asset) asset_path = digest_asset(asset) filename = File.join(target, asset_path) FileUtils.mkdir_p File.dirname(filename) asset.write_to(filename) asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/ asset_path end |
#digest_asset(asset) ⇒ Object
47 48 49 |
# File 'lib/sprockets/static_compiler.rb', line 47 def digest_asset(asset) digest ? asset.digest_path : asset.logical_path end |
#precompile(paths) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sprockets/static_compiler.rb', line 14 def precompile(paths) manifest = {} env.each_logical_path do |logical_path| next unless precompile_path?(logical_path, paths) if asset = env.find_asset(logical_path) manifest[logical_path] = compile(asset) end end manifest end |
#precompile_path?(logical_path, paths) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sprockets/static_compiler.rb', line 34 def precompile_path?(logical_path, paths) paths.each do |path| if path.is_a?(Regexp) return true if path.match(logical_path) elsif path.is_a?(Proc) return true if path.call(logical_path) else return true if File.fnmatch(path.to_s, logical_path) end end false end |