Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got something working with mounting evergreen in a Rails 2.3 app. #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,23 @@ There's a rake task provided for you that you can use to run your specs:

rake spec:javascripts

== Integrating with Rails 2
== Integrating with Rails 2.3

Add the following line to your Rakefile:

require 'evergreen/tasks'

This will give you the `spec:javascripts` rake task. Note that mounting is not
possible under Rails 2 and that `require 'evergreen/rails'` will fail.
This will give you the `spec:javascripts` rake task.

To mount the spec runner, add the following to your config/environments/development.rb file:

config.after_initialize do
require "evergreen/rails2"
config.middleware.insert_before "ActionController::Failsafe", "Evergreen::Rails2"
end

Start your rails application and navigate to /evergreen. You should now see a
list of all spec files, click on one to run it.

== Configuration

Expand Down
41 changes: 41 additions & 0 deletions lib/evergreen/rails2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "evergreen"

module Evergreen
class UrlPrepender
def initialize app
@app = app
end

def call headers
status, headers, body = @app.call headers
new_body = ""
body.each do |part|
new_body << part
end

new_body.gsub! /(src|href)="\//, '\1="/evergreen/'
[status, headers, [new_body]]
end
end

class Rails2
def initialize app
@app = app
end

def call headers
builder = ::Rack::Builder.new do
map "/evergreen" do
use UrlPrepender
run Evergreen::Application
end
end

if headers["PATH_INFO"].starts_with? "/evergreen"
builder.call headers
else
@app.call headers
end
end
end
end