Class: Locomotive::Middlewares::Permalink
- Inherits:
-
Object
- Object
- Locomotive::Middlewares::Permalink
- Defined in:
- lib/locomotive/middlewares/permalink.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Permalink
constructor
A new instance of Permalink.
Constructor Details
#initialize(app, opts = {}) ⇒ Permalink
Returns a new instance of Permalink.
5 6 7 |
# File 'lib/locomotive/middlewares/permalink.rb', line 5 def initialize(app, opts = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/locomotive/middlewares/permalink.rb', line 9 def call(env) if env['PATH_INFO'] =~ /^#{Locomotive.mounted_on}\/_permalink.json/ request = Rack::Request.new(env) underscore = request.params['underscore'] == '1' value = request.params['string'].try(:permalink, underscore) [200, {}, [{ value: value }.to_json]] else @app.call(env) end end |