Skip to content

Commit

Permalink
Merge 502a8d6 into 791b0a7
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed Jun 24, 2014
2 parents 791b0a7 + 502a8d6 commit c932f4e
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ gemfile:
- gemfiles/rack.1.3.x.gemfile
- gemfiles/rack.1.2.x.gemfile
- gemfiles/rack.1.1.x.gemfile
- gemfiles/rails.3.2.x.gemfile
- gemfiles/rails.4.0.x.gemfile
- gemfiles/rails.4.1.x.gemfile

script: "bundle exec rake spec"

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ gem "rack-dev-mark"

And run `bundle install`.

### For your Rack app
### For Rack App

```ruby
require 'rack/dev-mark'
use Rack::DevMark::Middleware
run MyApp
```

### For your Rails app
### For Rails App

In `config/environments/development.rb`

Expand Down Expand Up @@ -79,7 +79,7 @@ end

## Custom Theme

Define a sub class of `Rack::DevMark::Theme::Base` somewhere in your app.
Create your own theme class inheriting `Rack::DevMark::Theme::Base`.

```ruby
require 'rack/dev-mark/theme/base'
Expand All @@ -101,25 +101,25 @@ end

Then, insert them in your app.

### For your Rack app
### For Rack App

```ruby
use Rack::DevMark::Middleware, [NewTheme.new, AnotherTheme.new]
```

### For your Rails app
### For Rails App

In `config/application.rb`

```ruby
module MyApp
class Application < Rails::Application
config.rack_dev_mark.custom_theme = [NewTheme.new, AnotherTheme.new]
config.rack_dev_mark.theme = [NewTheme.new, AnotherTheme.new]
end
end
```

You can add any combination of themes.
You can add any combination of themes. See more about [themes](lib/rack/dev-mark/theme/README.md).

## Contributing

Expand Down
4 changes: 4 additions & 0 deletions gemfiles/rails.3.2.x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

gem 'rails', '~> 3.2'
gemspec :path => '../'
4 changes: 4 additions & 0 deletions gemfiles/rails.4.0.x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

gem 'rails', '~> 4.0'
gemspec :path => '../'
4 changes: 4 additions & 0 deletions gemfiles/rails.4.1.x.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

gem 'rails', '~> 4.1'
gemspec :path => '../'
11 changes: 9 additions & 2 deletions lib/generators/rack/dev-mark/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rails/generators'
require 'rails/generators/base'

module Rack
Expand All @@ -7,15 +8,21 @@ class InstallGenerator < ::Rails::Generators::Base

desc "Install rack-dev-mark."
def insert_enable
insert_into_file 'config/application.rb', after: "< Rails::Application\n" do <<-EOS
insert_into_file target_path, after: "< Rails::Application\n" do <<-EOS
# Enable rack-dev-mark
config.rack_dev_mark.enable = !Rails.env.production?
# Customize themes if you want to do so
# config.rack_dev_mark.custom_theme = [:title, :github_fork_ribbon]
# config.rack_dev_mark.theme = [:title, :github_fork_ribbon]
EOS
end
end

private

def target_path
'config/application.rb'
end
end
end
end
4 changes: 3 additions & 1 deletion lib/rack/dev-mark/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class Railtie < Rails::Railtie
initializer "rack-dev-mark.configure_rails_initialization" do |app|
if app.config.rack_dev_mark.enable
racks = [ActionDispatch::ShowExceptions, Rack::DevMark::Middleware]
racks << app.config.rack_dev_mark.custom_theme if app.config.rack_dev_mark.custom_theme
if theme = app.config.rack_dev_mark.theme || app.config.rack_dev_mark.custom_theme
racks << theme
end
app.config.app_middleware.insert_before *racks
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/rack/dev-mark/theme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

You can set options when you add the themes into your app. Otherwise, just put the symbol of the theme filename.

### For your Rack app
### For Rack App

```ruby
use Rack::DevMark::Middleware, [:title, Rack::DevMark::Theme::GithubForkRibbon.new(position: 'right')]
```

### For your Rails app
### For Rails App

In config/application.rb

```ruby
module MyApp
class Application < Rails::Application
config.rack_dev_mark.custom_theme = [:title, Rack::DevMark::Theme::GithubForkRibbon.new(position: 'right')]
config.rack_dev_mark.theme = [:title, Rack::DevMark::Theme::GithubForkRibbon.new(position: 'right')]
end
end
```
Expand All @@ -34,11 +34,11 @@ e.g.

`upcase`: `true` or `false` (default)

## github-fork-ribbon
## github_fork_ribbon

["Fork Me on GitHub" like ribbon](https://github.com/simonwhitaker/github-fork-ribbon-css) originally created by [simonwhitaker](https://github.com/simonwhitaker)

![github-fork-ribbon](screenshots/github_fork_ribbon.png)
![github_fork_ribbon](screenshots/github_fork_ribbon.png)

### options

Expand Down
45 changes: 45 additions & 0 deletions spec/generators/rack/dev-mark/install_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

if defined?(::Rails)
require 'tempfile'
require 'generators/rack/dev-mark/install_generator'
describe Rack::DevMark::InstallGenerator do
include_context 'forked spec'

context "config/application.rb" do
let(:application_rb) { Tempfile.new('config_application.rb') }
before do
application_rb.write <<-EOS
module MyApp
class Application < Rails::Application
# ...
end
end
EOS
application_rb.rewind
allow_any_instance_of(Rack::DevMark::InstallGenerator).to receive(:target_path).and_return(application_rb.path)
end
after do
application_rb.close
application_rb.unlink
end

it 'inserts rack-dev-mark settings' do
Rails::Generators.invoke("rack:dev-mark:install")
application_rb.rewind
expect(application_rb.read).to eq <<-EOS
module MyApp
class Application < Rails::Application
# Enable rack-dev-mark
config.rack_dev_mark.enable = !Rails.env.production?
# Customize themes if you want to do so
# config.rack_dev_mark.theme = [:title, :github_fork_ribbon]
# ...
end
end
EOS
end
end
end
end
49 changes: 49 additions & 0 deletions spec/rack/dev-mark/railtie_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'spec_helper'

if defined?(::Rails)
describe Rack::DevMark::Railtie do
include_context 'forked spec'

before do
puts 'initialize rails'
@app = Class.new(::Rails::Application)
@app.config.active_support.deprecation = :stderr
end
context "rack_dev_mark enable" do
before do
@app.config.rack_dev_mark.enable = true
@app.initialize!
end
it 'inserts the middleware' do
expect(@app.middleware.middlewares).to include(Rack::DevMark::Middleware)
end
end
context "rack_dev_mark disable" do
before do
@app.config.rack_dev_mark.enable = false
@app.initialize!
end
it 'does not insert the middleware' do
expect(@app.middleware.middlewares).not_to include(Rack::DevMark::Middleware)
end
end
context "rack_dev_mark theme" do
let(:setting_key) { 'theme' }
let(:theme) { d = double setup: nil; allow(d).to receive(:insert_into){ |b| "#{b} dev-mark" }; d }
before do
@app.config.rack_dev_mark.enable = true
@app.config.rack_dev_mark.send "#{setting_key}=", [theme]
@app.initialize!
end
it 'inserts the middleware' do
expect(theme).to receive(:setup)
end
context "rack_dev_mark custom_theme alias" do
let(:setting_key) { 'custom_theme' }
it 'inserts the middleware' do
expect(theme).to receive(:setup)
end
end
end
end
end
24 changes: 23 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
require 'rubygems'
require 'simplecov'
require 'coveralls'
Coveralls.wear!

resultset_path = SimpleCov::ResultMerger.resultset_path
FileUtils.rm resultset_path if File.exists? resultset_path
SimpleCov.use_merging true
SimpleCov.at_exit do
SimpleCov.command_name "fork-#{$$}"
SimpleCov.result.format!
end
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
if ENV['COVERAGE']
SimpleCov.start
end

ENV['RACK_ENV'] = 'test'

require 'rack'
begin
require 'rails'
$stdout.write "* Rails has been loaded.\n"
rescue LoadError
end
require 'rack-dev-mark'

Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }

ENV['RACK_ENV'] = 'test'
RSpec.configure do |config|
end

17 changes: 17 additions & 0 deletions spec/support/fork_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
shared_context 'forked spec' do
around do |example|
read, write = IO.pipe
pid = fork do
$stdout.sync = true
$stderr.sync = true
res = example.run
Marshal.dump(res, write)
write.close
end
Process.waitpid2 pid
res = Marshal.load(read)
example.example.send :set_exception, res
read.close
#fail "Forked spec failed" if $? >> 8 != 0
end
end

0 comments on commit c932f4e

Please sign in to comment.