Class: Sprockets::Standalone::Manifest

Inherits:
Manifest
  • Object
show all
Defined in:
lib/sprockets/standalone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#compress_assets=(value) ⇒ Object (writeonly)

Sets the attribute compress_assets

Parameters:

  • value

    the value to set the attribute compress_assets to.



90
91
92
# File 'lib/sprockets/standalone.rb', line 90

def compress_assets=(value)
  @compress_assets = value
end

#digest_assets=(value) ⇒ Object (writeonly)

Sets the attribute digest_assets

Parameters:

  • value

    the value to set the attribute digest_assets to.



85
86
87
# File 'lib/sprockets/standalone.rb', line 85

def digest_assets=(value)
  @digest_assets = value
end

Instance Method Details

#compile(*args) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sprockets/standalone.rb', line 95

def compile(*args)
  unless environment
    raise Error, "manifest requires environment for compilation"
  end

  paths = environment.each_logical_path(*args).to_a +
    args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)}

  if (missing_paths = (args.reject{|p| p.include?('*')} - paths)).any?
    missing_paths.each do |path|
      logger.warn "Asset #{path} not found."
    end
  end

  paths.each do |path|
    if asset = find_asset(path)
      compile_asset asset
    end
  end
  save
  paths
end

#compile_asset(asset) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sprockets/standalone.rb', line 118

def compile_asset(asset)
  path   = digest_assets? ? asset.digest_path : asset.logical_path
  target = File.join(dir, path)

  if files[path] && (digest = files[path]['digest'])
    if digest == asset.digest && File.exists?(target)
      logger.debug "Skipping #{target}, up-to-date"
      return
    end
  end

  files[path] = {
    'logical_path' => asset.logical_path,
    'mtime'        => asset.mtime.iso8601,
    'size'         => asset.bytesize,
    'digest'       => asset.digest
  }
  assets[asset.logical_path] = path

  logger.info "Writing #{target}"
  asset.write_to target
  asset.write_to "#{target}.gz" if asset.is_a?(BundledAsset) && compress_assets?
end

#compress_assets?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/sprockets/standalone.rb', line 91

def compress_assets?
  !!@compress_assets
end

#digest_assets?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/sprockets/standalone.rb', line 86

def digest_assets?
  !!@digest_assets
end