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: Configuration, StaticCompiler

Constant Summary collapse

VERSION =
"0.0.5"
DEFAULT_OPTIONS =
{
  app: nil,
  debug: false,
  digest: false,
  compile: false,
  compress: false,
  host: nil,
  manifest_path: 'public/assets',
  paths: %w[images javascripts stylesheets],
  precompile: [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ],
  prefix: 'assets',
  relative_url_root: ENV['RACK_RELATIVE_URL_ROOT'],
  css_compressor: false,
  js_compressor: false
}

Class Method Summary collapse

Class Method Details

.configObject



13
14
15
# File 'lib/sinatra/sprockets.rb', line 13

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

.configure {|config| ... } ⇒ Object

Yields:



9
10
11
# File 'lib/sinatra/sprockets.rb', line 9

def self.configure
  yield config
end

.environmentObject



17
18
19
# File 'lib/sinatra/sprockets.rb', line 17

def self.environment
  @environment
end

.registered(app) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sinatra/sprockets.rb', line 21

def self.registered app
  config.app = app

  @environment = ::Sprockets::Environment.new app.root

  config.paths.each do |path|
    environment.append_path File.join(config.app.root, config.prefix, path)
    environment.append_path File.join(config.app.root, 'lib', config.prefix, path)
  end

  if config.compress
    environment.css_compressor = config.css_compressor
    environment.js_compressor = config.js_compressor
  end

  app.helpers Helpers
  environment.context_class.instance_eval do
    include Helpers
  end
end