Module: Sinatra::Sprockets

Defined in:
lib/sinatra/sprockets.rb,
lib/sinatra/sprockets/helpers.rb,
lib/sinatra/sprockets/version.rb,
lib/sinatra/sprockets/asset_paths.rb,
lib/sinatra/sprockets/configuration.rb,
lib/sinatra/sprockets/static_compiler.rb

Defined Under Namespace

Modules: Helpers Classes: AssetPaths, Configuration, StaticCompiler

Constant Summary collapse

VERSION =
"0.0.2.1"

Class Method Summary collapse

Class Method Details

.configObject



43
44
45
# File 'lib/sinatra/sprockets.rb', line 43

def self.config
  @config ||= Configuration.new
end

.configure(&block) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sinatra/sprockets.rb', line 8

def self.configure(&block)
  block.call(config)
  raise ArgumentError, "Cannot initialize Sprockets Environment without an app reference" if config.app.nil?
  
  @environment = ::Sprockets::Environment.new(config.app.root)
  
  config.paths.each do |path|
    environment.append_path(File.join(config.app.root, path))
  end
  
  if config.compress_assets?
    environment.js_compressor = Closure::Compiler.new
    environment.css_compressor = YUI::CssCompressor.new
  else
    environment.js_compressor = false
    environment.css_compressor = false
  end
  
  if config.manifest_path
    path = File.join(config.app.root, config.manifest_path, "manifest.yml")
  else
    path = File.join(config.app.settings.public_path, 'assets', "manifest.yml")
  end

  if File.exist?(path)
    YAML.load_file(path).each do |path, value|
      config.digests[path] = value
    end
  end
  
  environment.context_class.instance_eval do
    include Helpers
  end
end

.environmentObject



47
48
49
# File 'lib/sinatra/sprockets.rb', line 47

def self.environment
  @environment
end