Class: Sinatra::SimpleAssets::Assets

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/simple_assets.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ Assets

Returns a new instance of Assets.



80
81
82
83
84
85
# File 'lib/sinatra/simple_assets.rb', line 80

def initialize(app, &block)
  @app = app
  @bundles = {}
  @hashes = {}
  instance_eval(&block)
end

Instance Method Details

#bundle_exists?(bundle) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/sinatra/simple_assets.rb', line 123

def bundle_exists?(bundle)
  @hashes[bundle]
end

#content_for(bundle) ⇒ Object



112
113
114
115
# File 'lib/sinatra/simple_assets.rb', line 112

def content_for(bundle)
  bundle = @bundles[@hashes[bundle]]
  bundle.content if bundle
end

#create_bundle(name, type, files) ⇒ Object



95
96
97
98
# File 'lib/sinatra/simple_assets.rb', line 95

def create_bundle(name, type, files)
  bundle = Bundle.new(name, type, @app.public_folder, files)
  @bundles[bundle.name] = bundle
end

#css(bundle, files) ⇒ Object



87
88
89
# File 'lib/sinatra/simple_assets.rb', line 87

def css(bundle, files)
  create_bundle(bundle, :css, files)
end

#js(bundle, files) ⇒ Object



91
92
93
# File 'lib/sinatra/simple_assets.rb', line 91

def js(bundle, files)
  create_bundle(bundle, :js, files)
end

#paths_for(bundle) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sinatra/simple_assets.rb', line 100

def paths_for(bundle)
  bundle = @bundles[bundle]
  return [] unless bundle

  if @app.environment == :production
    @hashes[bundle.hash_name] = bundle.name
    [bundle.hashed_path]
  else
    bundle.files
  end
end

#precompileObject



117
118
119
120
121
# File 'lib/sinatra/simple_assets.rb', line 117

def precompile
  @bundles.values.each do |bundle|
    bundle.compile
  end
end