class RenderStatic::Middleware
Attributes
base_path[RW]
Public Class Methods
new(app)
click to toggle source
# File lib/render_static/middleware.rb, line 13 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/render_static/middleware.rb, line 17 def call(env) if will_render?(env) RenderStatic::Renderer.render(env) else @app.call(env) end end
Private Instance Methods
is_bot?(env)
click to toggle source
# File lib/render_static/middleware.rb, line 31 def is_bot?(env) [ "Googlebot", "Googlebot-Mobile", "AdsBot-Google", "Mozilla/5.0 (compatible; Ask Jeeves/Teoma; +http://about.ask.com/en/docs/about/webmasters.shtml)", "Baiduspider", "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", ].include?(env["HTTP_USER_AGENT"]) end
is_renderable?(env)
click to toggle source
# File lib/render_static/middleware.rb, line 42 def is_renderable?(env) path = env["PATH_INFO"] content_type = path.index(".") && path.split(".").last path.start_with?(self.class.base_path) & [nil, "htm", "html"].include?(content_type) && env["REQUEST_METHOD"] == "GET" end
will_render?(env)
click to toggle source
# File lib/render_static/middleware.rb, line 27 def will_render?(env) is_bot?(env) && is_renderable?(env) end