Class: Rack::Spriter
- Inherits:
-
Object
- Object
- Rack::Spriter
- Defined in:
- lib/rack/spriter.rb
Constant Summary collapse
- File =
::File
Instance Method Summary collapse
- #call(env) ⇒ Object
- #default_options ⇒ Object
-
#initialize(app, options = {}) ⇒ Spriter
constructor
A new instance of Spriter.
Constructor Details
#initialize(app, options = {}) ⇒ Spriter
Returns a new instance of Spriter.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rack/spriter.rb', line 8 def initialize(app, = {}) = .merge() @app = app @stylesheets_path = [:stylesheets_path] @stylesheets_url_pattern = [:stylesheets_url_pattern] @images = [] ::Spriter.assets_path = [:assets_path] ::Spriter.sprite_image_path = [:sprite_image_path] ::Spriter.sprite_image_url = [:sprite_image_url] end |
Instance Method Details
#call(env) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rack/spriter.rb', line 36 def call(env) if css = generate_css(env) return [200, {"Content-Type" => "text/css", "Cache-Control" => "private"}, [css]] else @app.call(env) end end |
#default_options ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rack/spriter.rb', line 19 def defaults = { :sprite_image_url => '/images/sprites.png', :stylesheets_url_pattern => %r{stylesheets\/(.+)\.css$} } if defined? Rails defaults.merge( :stylesheets_path => File.join(Rails.root, *%w[ public stylesheets ]), :assets_path => File.join(Rails.root, *%w[ public images sprite_assets ]), :sprite_image_path => File.join(Rails.root, *%w[ public images sprites.png ]) ) else defaults end end |