Module: Cuba::Sprockets

Defined in:
lib/cuba/sprockets.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup(app) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/cuba/sprockets.rb', line 4

def self.setup(app)
  app.settings[:sprockets] ||= {}
  app.settings[:sprockets][:path] ||= '/assets'
  app.settings[:sprockets][:assets_path] ||= File.join Dir.pwd, 'assets'
  app.settings[:sprockets][:manifest_path] ||= File.join Dir.pwd, 'public', 'assets'
  app.settings[:sprockets][:fonts_path] ||= File.join app.settings[:sprockets][:assets_path], 'fonts'
  app.settings[:sprockets][:images_path] ||= File.join app.settings[:sprockets][:assets_path], 'images'
  app.settings[:sprockets][:javascripts_path] ||= File.join app.settings[:sprockets][:assets_path], 'javascripts'
  app.settings[:sprockets][:stylesheets_path] ||= File.join app.settings[:sprockets][:assets_path], 'stylesheets'
end

Instance Method Details

#asset_path(file) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/cuba/sprockets.rb', line 15

def asset_path(file)
  if ENV['RACK_ENV'] == 'production'
    manifest = ::Sprockets::Manifest.new settings[:sprockets][:manifest_path]
    "#{settings[:sprockets][:path]}/#{manifest.assets[file]}"
  else
    "#{settings[:sprockets][:path]}/#{file}"
  end
end

#sprocketsObject



24
25
26
27
28
29
30
31
# File 'lib/cuba/sprockets.rb', line 24

def sprockets
  @sprockets ||= ::Sprockets::Environment.new do |env|
    env.append_path settings[:sprockets][:fonts_path]
    env.append_path settings[:sprockets][:images_path]
    env.append_path settings[:sprockets][:javascripts_path]
    env.append_path settings[:sprockets][:stylesheets_path]
  end
end