Created
June 7, 2011 14:22
-
-
Save jcxplorer/1012348 to your computer and use it in GitHub Desktop.
Carpentry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "carpentry/no_robots_middleware" | |
module Carpentry | |
class Engine < ::Rails::Engine | |
config.app_middleware.use NoRobotsMiddleware | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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