Skip to content

Instantly share code, notes, and snippets.

@jcxplorer
Created June 7, 2011 14:22
Show Gist options
  • Save jcxplorer/1012348 to your computer and use it in GitHub Desktop.
Save jcxplorer/1012348 to your computer and use it in GitHub Desktop.
Carpentry
require "carpentry/no_robots_middleware"
module Carpentry
class Engine < ::Rails::Engine
config.app_middleware.use NoRobotsMiddleware
end
end
module Carpentry
class NoRobotsMiddleware
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
if env["carpentry.prototype"] && status == 200
no_robots_tag = %{<meta name="robots" content="noindex, nofollow"/>\n}
response.body = response.body.sub("</head>", "#{no_robots_tag}</head>")
end
[status, headers, response]
end
end
end
module Carpentry
class PrototypesController < ApplicationController
before_filter :before_carpentry,
:if => proc { respond_to?(:before_carpentry, true) }
def serve
env["carpentry.prototype"] = true
render "carpentry/prototypes/#{params[:file_path]}"
end
end
end
Rails.application.routes.draw do
namespace "p", :module => :carpentry do
root :to => "prototypes#serve", :file_path => "index"
match "/*file_path" => "prototypes#serve"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment