Class: TDiary::Rack::HtmlAnchor

Inherits:
Object
  • Object
show all
Defined in:
lib/tdiary/rack/html_anchor.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HtmlAnchor

Returns a new instance of HtmlAnchor.



7
8
9
# File 'lib/tdiary/rack/html_anchor.rb', line 7

def initialize( app )
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tdiary/rack/html_anchor.rb', line 11

def call( env )
  if env['PATH_INFO'].match(/(.*\/)([0-9\-]+)(p(\d\d))?\.html$/)
    env["PATH_INFO"] = $1
    date = $2
    anchor = $4
    env["QUERY_STRING"] += "&" unless env["QUERY_STRING"].empty?
    env["QUERY_STRING"] += "date=#{date}"
    env["QUERY_STRING"] += "&p=#{anchor}" if anchor
  end
  @app.call( env )
end