Class: Locomotive::Steam::Server::DynamicAssets
- Inherits:
-
Middleware
- Object
- Middleware
- Locomotive::Steam::Server::DynamicAssets
- Defined in:
- lib/locomotive/steam/server/dynamic_assets.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#sprockets ⇒ Object
readonly
Returns the value of attribute sprockets.
Attributes inherited from Middleware
#content_entry, #liquid_assigns, #mounting_point, #page, #path, #request
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, site_path) ⇒ DynamicAssets
constructor
A new instance of DynamicAssets.
Constructor Details
#initialize(app, site_path) ⇒ DynamicAssets
Returns a new instance of DynamicAssets.
8 9 10 11 12 13 14 |
# File 'lib/locomotive/steam/server/dynamic_assets.rb', line 8 def initialize(app, site_path) super(app) @regexp = /^\/(javascripts|stylesheets)\/(.*)$/ @sprockets = Locomotive::Mounter::Extensions::Sprockets.environment(site_path) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/locomotive/steam/server/dynamic_assets.rb', line 6 def app @app end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
6 7 8 |
# File 'lib/locomotive/steam/server/dynamic_assets.rb', line 6 def regexp @regexp end |
#sprockets ⇒ Object (readonly)
Returns the value of attribute sprockets.
6 7 8 |
# File 'lib/locomotive/steam/server/dynamic_assets.rb', line 6 def sprockets @sprockets end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/locomotive/steam/server/dynamic_assets.rb', line 16 def call(env) if env['PATH_INFO'] =~ self.regexp env['PATH_INFO'] = $2 begin self.sprockets.call(env) rescue Exception => e raise Locomotive::Steam::DefaultException.new "Unable to serve a dynamic asset. Please check the logs.", e end else app.call(env) end end |