Parent

Class Index [+]

Quicksearch

Sprockets::StaticCompiler

Attributes

env[RW]
target[RW]
paths[RW]

Public Class Methods

new(env, target, paths, options = {}) click to toggle source
    # File lib/sprockets/static_compiler.rb, line 7
 7:     def initialize(env, target, paths, options = {})
 8:       @env = env
 9:       @target = target
10:       @paths = paths
11:       @digest = options.key?(:digest) ? options.delete(:digest) : true
12:       @manifest = options.key?(:manifest) ? options.delete(:manifest) : true
13:       @manifest_path = options.delete(:manifest_path) || target
14:     end

Public Instance Methods

compile() click to toggle source
    # File lib/sprockets/static_compiler.rb, line 16
16:     def compile
17:       manifest = {}
18:       env.each_logical_path do |logical_path|
19:         if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
20:           logical_path.sub!(/\/index\./, '.')
21:         end
22:         next unless compile_path?(logical_path)
23:         if asset = env.find_asset(logical_path)
24:           manifest[logical_path] = write_asset(asset)
25:         end
26:       end
27:       write_manifest(manifest) if @manifest
28:     end
compile_path?(logical_path) click to toggle source
    # File lib/sprockets/static_compiler.rb, line 46
46:     def compile_path?(logical_path)
47:       paths.each do |path|
48:         case path
49:         when Regexp
50:           return true if path.match(logical_path)
51:         when Proc
52:           return true if path.call(logical_path)
53:         else
54:           return true if File.fnmatch(path.to_s, logical_path)
55:         end
56:       end
57:       false
58:     end
path_for(asset) click to toggle source
    # File lib/sprockets/static_compiler.rb, line 60
60:     def path_for(asset)
61:       @digest ? asset.digest_path : asset.logical_path
62:     end
write_asset(asset) click to toggle source
    # File lib/sprockets/static_compiler.rb, line 37
37:     def write_asset(asset)
38:       path_for(asset).tap do |path|
39:         filename = File.join(target, path)
40:         FileUtils.mkdir_p File.dirname(filename)
41:         asset.write_to(filename)
42:         asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
43:       end
44:     end
write_manifest(manifest) click to toggle source
    # File lib/sprockets/static_compiler.rb, line 30
30:     def write_manifest(manifest)
31:       FileUtils.mkdir_p(@manifest_path)
32:       File.open("#{@manifest_path}/manifest.yml", 'wb') do |f|
33:         YAML.dump(manifest, f)
34:       end
35:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.