Module: Sinatra::AssetPipeline

Defined in:
lib/sinatra/asset_pipeline.rb,
lib/sinatra/asset_pipeline/task.rb,
lib/sinatra/asset_pipeline/version.rb

Defined Under Namespace

Classes: Task

Constant Summary collapse

VERSION =
'2.2.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object


6
7
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sinatra/asset_pipeline.rb', line 6

def self.registered(app)
  app.set_default :sprockets, ::Sprockets::Environment.new
  app.set_default :assets_paths, %w(assets)
  app.set_default :assets_precompile, %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
  app.set_default :assets_public_path, -> { File.join(public_folder, "assets") }
  app.set_default :assets_protocol, :http
  app.set_default :assets_css_compressor, nil
  app.set_default :assets_js_compressor, nil
  app.set_default :assets_host, nil
  app.set_default :assets_prefix, '/assets'
  app.set_default :assets_digest, true
  app.set_default :assets_debug, false
  app.set_default :precompiled_environments, %i(staging production)

  app.set :static, :true
  app.set :static_cache_control, [:public, :max_age => 60 * 60 * 24 * 365]

  app.configure do
    app.assets_paths.each do |path|
      app.sprockets.append_path(Pathname.new(path).absolute? ? path : File.join(app.root, path))
    end

    ::Sprockets::Helpers.configure do |config|
      config.environment = app.sprockets
      config.digest = app.assets_digest
      config.prefix = app.assets_prefix unless app.assets_prefix.nil?
      config.debug = app.assets_debug
    end
  end

  app.configure(*app.precompiled_environments) do
    ::Sprockets::Helpers.configure do |config|
      config.manifest = ::Sprockets::Manifest.new(app.sprockets, app.assets_public_path)
      config.prefix = app.assets_prefix unless app.assets_prefix.nil?
    end
  end

  app.configure(*app.precompiled_environments) do
    app.sprockets.css_compressor = app.assets_css_compressor unless app.assets_css_compressor.nil?
    app.sprockets.js_compressor = app.assets_js_compressor unless app.assets_js_compressor.nil?

    ::Sprockets::Helpers.configure do |config|
      config.protocol = app.assets_protocol
      config.asset_host = app.assets_host unless app.assets_host.nil?
      config.prefix = app.assets_prefix unless app.assets_prefix.nil?
    end
  end

  app.helpers ::Sprockets::Helpers

  app.configure :test, :development do
    app.get "#{app.assets_prefix}/*" do |path|
      env_sprockets = request.env.dup
      env_sprockets['PATH_INFO'] = path
      settings.sprockets.call env_sprockets
    end
  end
end

Instance Method Details

#set_default(key, default) ⇒ Object


65
66
67
# File 'lib/sinatra/asset_pipeline.rb', line 65

def set_default(key, default)
  self.set(key, default) unless self.respond_to? key
end