Class: Locomotive::Middlewares::Permalink

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/middlewares/permalink.rb

Instance Method Summary collapse

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