rack-dev-mark 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29e79da8e2e497e598c546a19d5fdbd559d08122
4
- data.tar.gz: 9c48bd678f7a011150b951ad15846ba5a655d52b
3
+ metadata.gz: df36ab5b5e659caeee87e9392be1626d6bc60834
4
+ data.tar.gz: f152c7f27e311c166858de3403a0dd56e074910c
5
5
  SHA512:
6
- metadata.gz: a1b8813d5f99f420f4408878cfa5dbefc316b0fcd28e53fb0b44198f35c8a68f7fa3045573e963748ceb8e24a928598cd996500ca8c08f4b5177ae3f4cf0e9e8
7
- data.tar.gz: a5e49e6bccc0cf1e0530acfef251f4b1db3ebce2979ce0075a27e69be85a13d1b7a9fbdd2c777be9f1b63918cde3b47f4a0922f159ec12be643dbf00f3f252ed
6
+ metadata.gz: 3287bb471bdf78d02ed55bb92a365f90042041a773db600ce2a429a656fb5e6a8bb462ca53a0a356a8976bb6009d40251537134c0ecf1751d8cc3e752ced7276
7
+ data.tar.gz: 8618e72dfd9a95ed37ccae14038ab616e80673187c40cd8a6d24043492230163685638ee0e6844a22a6a417ba6503cedf868adb076a666a2425f67241ee4c431
data/README.md CHANGED
@@ -26,7 +26,7 @@ And run `bundle install`.
26
26
 
27
27
  ### For your Rack app
28
28
 
29
- ```ruby:config.ru
29
+ ```ruby
30
30
  require 'rack/dev-mark'
31
31
  use Rack::DevMark::Middleware
32
32
  run MyApp
@@ -34,7 +34,17 @@ run MyApp
34
34
 
35
35
  ### For your Rails app
36
36
 
37
- This gem inserts rack middleware for all the environment except production automatically.
37
+ In `config/application.rb`
38
+
39
+ ```ruby
40
+ module MyApp
41
+ class Application < Rails::Application
42
+ if !%w(production).include?(Rails.env)
43
+ config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware
44
+ end
45
+ end
46
+ end
47
+ ```
38
48
 
39
49
  ## Custom Theme
40
50
 
@@ -44,7 +54,7 @@ Define a sub class of `Rack::DevMark::Theme::Base` somewhere in your app.
44
54
  require 'rack/dev-mark/theme/base'
45
55
 
46
56
  class NewTheme < Rack::DevMark::Theme::Base
47
- def insert_into(html, env)
57
+ def insert_into(html, env, revision)
48
58
  # Do something for your theme
49
59
  html
50
60
  end
@@ -56,27 +66,23 @@ Then, insert it in your app.
56
66
  ### For your Rack app
57
67
 
58
68
  ```ruby
59
- use Rack::DevMark::Middleware, Rack::DevMark::Theme::NewTheme.new
69
+ use Rack::DevMark::Middleware, NewTheme.new
60
70
  ```
61
71
 
62
72
  ### For your Rails app
63
73
 
64
- ```ruby:application.rb
65
- Rack::DevMark.theme = NewTheme.new
66
- ```
67
-
68
- ## Production Environment
74
+ In `config/application.rb`
69
75
 
70
- You can change production environment name.
71
-
72
- ### For your Rails app
73
-
74
- ```ruby:application.rb
75
- Rack::DevMark.production_env = [:demo, :production]
76
+ ```ruby
77
+ module MyApp
78
+ class Application < Rails::Application
79
+ if !%w(production).include?(Rails.env)
80
+ config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware, NewTheme.new
81
+ end
82
+ end
83
+ end
76
84
  ```
77
85
 
78
- Then the mark won't show up on demo and production environments.
79
-
80
86
  ## Contributing
81
87
 
82
88
  1. Fork it
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'rack', '~> 1.1.0'
4
4
  gemspec :path => '../'
5
-
6
- dependencies.delete_if { |dep| dep.name == 'rails' }
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'rack', '~> 1.2.0'
4
4
  gemspec :path => '../'
5
-
6
- dependencies.delete_if { |dep| dep.name == 'rails' }
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  gem 'rack', '~> 1.3.0'
4
4
  gemspec :path => '../'
5
-
6
- dependencies.delete_if { |dep| dep.name == 'rails' }
data/lib/rack/dev-mark.rb CHANGED
@@ -4,29 +4,16 @@ require 'rack/dev-mark/utils'
4
4
  require 'rack/dev-mark/title'
5
5
  require 'rack/dev-mark/theme'
6
6
  require 'rack/dev-mark/middleware'
7
- require 'rack/dev-mark/railtie' if defined?(Rails)
8
7
  require 'rack/dev-mark/version'
9
8
 
10
9
  module Rack
11
10
  module DevMark
12
11
  def self.env
13
- ENV['RAILS_ENV'] || ENV['RACK_ENV']
12
+ @env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV']
14
13
  end
15
14
 
16
- def self.production_env
17
- @production_env ||= ['production']
18
- end
19
-
20
- def self.production_env=(*production_env)
21
- @production_env = production_env.flatten.map(&:to_s)
22
- end
23
-
24
- def self.theme
25
- @theme ||= :github_fork_ribbon
26
- end
27
-
28
- def self.theme=(theme)
29
- @theme = theme
15
+ def self.revision
16
+ @revision ||= (::File.open('REVISION') { |f| f.read.strip } rescue nil)
30
17
  end
31
18
  end
32
19
  end
@@ -33,8 +33,8 @@ module Rack
33
33
  response.each do |r|
34
34
  body.concat r.to_s
35
35
  end
36
- body = @title.insert_into(body, Rack::DevMark.env)
37
- body = @theme.insert_into(body, Rack::DevMark.env)
36
+ body = @title.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
37
+ body = @theme.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
38
38
  [body]
39
39
  end
40
40
  end
@@ -6,7 +6,7 @@ module Rack
6
6
  raise RuntimeError, 'Abstract class can not be instantiated' if self.class == Rack::DevMark::Theme::Base
7
7
  end
8
8
 
9
- def insert_into(html, env)
9
+ def insert_into(html, env, revision)
10
10
 
11
11
  end
12
12
 
@@ -5,13 +5,13 @@ module Rack
5
5
  module DevMark
6
6
  module Theme
7
7
  class GithubForkRibbon < Base
8
- def insert_into(html, env)
8
+ def insert_into(html, env, revision)
9
9
  s = <<-EOS
10
10
  #{stylesheet_link_tag "github-fork-ribbon-css/gh-fork-ribbon.css"}
11
11
  <!--[if lt IE 9]>
12
12
  #{stylesheet_link_tag "github-fork-ribbon-css/gh-fork-ribbon.ie.css"}
13
13
  <![endif]-->
14
- <div class="github-fork-ribbon-wrapper left" onClick="this.style.display='none'"><div class="github-fork-ribbon"><span class="github-fork-ribbon-text">#{env}</span></div></div>
14
+ <div class="github-fork-ribbon-wrapper left" onClick="this.style.display='none'" title="#{revision}"><div class="github-fork-ribbon"><span class="github-fork-ribbon-text">#{env}</span></div></div>
15
15
  EOS
16
16
  html.sub %r{(<body[^>]*>)}i, "\\1#{s.strip}"
17
17
  end
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  module DevMark
3
3
  class Title
4
- def insert_into(html, env)
4
+ def insert_into(html, env, revision)
5
5
  html.sub %r{(<title[^>]*>)}i, "\\1(#{env}) "
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module DevMark
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -18,7 +18,6 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_dependency "rack", ">= 1.1"
20
20
 
21
- gem.add_development_dependency "rails", ">= 3.1"
22
21
  gem.add_development_dependency "rake"
23
22
  gem.add_development_dependency "rspec"
24
23
  gem.add_development_dependency "coveralls"
@@ -5,11 +5,12 @@ describe Rack::DevMark::Middleware do
5
5
  subject { Rack::DevMark::Middleware.new(app) }
6
6
  before do
7
7
  allow(Rack::DevMark).to receive(:env).and_return('test')
8
+ allow(Rack::DevMark).to receive(:revision).and_return('rev')
8
9
  end
9
10
 
10
11
  it "inserts planbcd tag" do
11
- expect_any_instance_of(Rack::DevMark::Title).to receive(:insert_into).with('response', 'test').once.and_return('response')
12
- expect_any_instance_of(Rack::DevMark::Theme::GithubForkRibbon).to receive(:insert_into).with('response', 'test').once.and_return('response')
12
+ expect_any_instance_of(Rack::DevMark::Title).to receive(:insert_into).with('response', 'test', 'rev').once.and_return('response')
13
+ expect_any_instance_of(Rack::DevMark::Theme::GithubForkRibbon).to receive(:insert_into).with('response', 'test', 'rev').once.and_return('response')
13
14
  status, headers, body = subject.call({})
14
15
  expect(status).to eq(200)
15
16
  expect(headers).to eq({'Content-Type' => 'text/html; charset=utf-8'})
@@ -8,7 +8,7 @@ describe Rack::DevMark::Theme::GithubForkRibbon do
8
8
  <!--[if lt IE 9]>
9
9
  <style>#{read_stylesheet "github-fork-ribbon-css/gh-fork-ribbon.ie.css"}</style>
10
10
  <![endif]-->
11
- <div class="github-fork-ribbon-wrapper left" onClick="this.style.display='none'"><div class="github-fork-ribbon"><span class="github-fork-ribbon-text">env</span></div></div>body</body></html>
11
+ <div class="github-fork-ribbon-wrapper left" onClick="this.style.display='none'" title="rev"><div class="github-fork-ribbon"><span class="github-fork-ribbon-text">env</span></div></div>body</body></html>
12
12
  EOS
13
13
  s.strip
14
14
  end
@@ -9,7 +9,7 @@ describe Rack::DevMark::Title do
9
9
  let (:src) { %Q~<html><head>head</head><body>body</body></html>~ }
10
10
  let (:out) { %Q~<html><head>head</head><body>body</body></html>~ }
11
11
  it "does not insert anything" do
12
- expect(subject.insert_into(src, 'env')).to eq(src)
12
+ expect(subject.insert_into(src, 'env', 'rev')).to eq(src)
13
13
  end
14
14
  end
15
15
  end
@@ -5,43 +5,42 @@ describe Rack::DevMark do
5
5
  before do
6
6
  @rack_env = ENV['RACK_ENV']
7
7
  @rails_env = ENV['RAILS_ENV']
8
- Rack::DevMark.production_env = 'production'
9
8
  end
10
9
  after do
11
10
  ENV['RACK_ENV'] = @rack_env
12
11
  ENV['RAILS_ENV'] = @rails_env
13
- end
14
- it "returns nil" do
15
- ENV['RAILS_ENV'] = nil
16
- ENV['RACK_ENV'] = nil
17
- expect(subject.env).to eq(nil)
18
- end
19
- it "returns rack_env" do
20
- ENV['RAILS_ENV'] = nil
21
- ENV['RACK_ENV'] = 'abc'
22
- expect(subject.env).to eq('abc')
23
- end
24
- it "returns rails_env instead of rack_env" do
25
- ENV['RACK_ENV'] = 'abc'
26
- ENV['RAILS_ENV'] = 'def'
27
- expect(subject.env).to eq('def')
28
- end
29
- it 'has default production_env' do
30
- expect(subject.production_env).to eq(['production'])
31
- end
32
- it 'sets production_env' do
33
- Rack::DevMark.production_env = 'abc'
34
- expect(subject.production_env).to eq(['abc'])
35
- end
36
- it 'sets production_env by array' do
37
- Rack::DevMark.production_env = ['abc', 'def']
38
- expect(subject.production_env).to eq(['abc', 'def'])
39
- end
40
- it 'has default theme' do
41
- expect(subject.theme).to eq(:github_fork_ribbon)
42
- end
43
- it 'sets production_env' do
44
- Rack::DevMark.theme = :abc
45
- expect(subject.theme).to eq(:abc)
12
+ subject.instance_variable_set("@env", nil)
13
+ end
14
+ describe "::env" do
15
+ it "returns nil" do
16
+ ENV['RAILS_ENV'] = nil
17
+ ENV['RACK_ENV'] = nil
18
+ expect(subject.env).to eq(nil)
19
+ end
20
+ it "returns rack_env" do
21
+ ENV['RAILS_ENV'] = nil
22
+ ENV['RACK_ENV'] = 'abc'
23
+ expect(subject.env).to eq('abc')
24
+ end
25
+ it "returns rails_env instead of rack_env" do
26
+ ENV['RACK_ENV'] = 'abc'
27
+ ENV['RAILS_ENV'] = 'def'
28
+ expect(subject.env).to eq('def')
29
+ end
30
+ end
31
+ describe "::revision" do
32
+ after do
33
+ ::File.delete('REVISION') if ::File.exists?('REVISION')
34
+ subject.instance_variable_set("@revision", nil)
35
+ end
36
+ it "returns revision" do
37
+ ::File.open('REVISION', 'w') do |f|
38
+ f.write('abcde')
39
+ end
40
+ expect(subject.revision).to eq('abcde')
41
+ end
42
+ it "returns nil if REVISION does not exist" do
43
+ expect(subject.revision).to eq(nil)
44
+ end
46
45
  end
47
46
  end
@@ -5,6 +5,6 @@ RSpec.shared_examples "theme" do
5
5
 
6
6
  let (:src) { %Q~<html><head>head<title>title</title></head><body>body</body></html>~ }
7
7
  it "insert env mark" do
8
- expect(subject.insert_into(src, 'env')).to eq(out)
8
+ expect(subject.insert_into(src, 'env', 'rev')).to eq(out)
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,83 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dev-mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Taniwaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-01 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.1'
27
- - !ruby/object:Gem::Dependency
28
- name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '3.1'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '3.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - '>='
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
- - - '>='
45
+ - - ">="
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
- - - '>='
52
+ - - ">="
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: coveralls
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - '>='
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - '>='
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  description: Differentiate development environemt from production
@@ -87,8 +73,8 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
90
- - .gitignore
91
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
92
78
  - Gemfile
93
79
  - LICENSE
94
80
  - README.md
@@ -102,7 +88,6 @@ files:
102
88
  - lib/rack/dev-mark.rb
103
89
  - lib/rack/dev-mark/error.rb
104
90
  - lib/rack/dev-mark/middleware.rb
105
- - lib/rack/dev-mark/railtie.rb
106
91
  - lib/rack/dev-mark/theme.rb
107
92
  - lib/rack/dev-mark/theme/base.rb
108
93
  - lib/rack/dev-mark/theme/github_fork_ribbon.rb
@@ -113,7 +98,6 @@ files:
113
98
  - screenshot-development.png
114
99
  - screenshot-production.png
115
100
  - spec/rack/dev-mark/middleware_spec.rb
116
- - spec/rack/dev-mark/railtie_spec.rb
117
101
  - spec/rack/dev-mark/theme/base_spec.rb
118
102
  - spec/rack/dev-mark/theme/github_fork_ribbon_spec.rb
119
103
  - spec/rack/dev-mark/title_spec.rb
@@ -132,26 +116,26 @@ require_paths:
132
116
  - lib
133
117
  required_ruby_version: !ruby/object:Gem::Requirement
134
118
  requirements:
135
- - - '>='
119
+ - - ">="
136
120
  - !ruby/object:Gem::Version
137
121
  version: '0'
138
122
  required_rubygems_version: !ruby/object:Gem::Requirement
139
123
  requirements:
140
- - - '>='
124
+ - - ">="
141
125
  - !ruby/object:Gem::Version
142
126
  version: '0'
143
127
  requirements: []
144
128
  rubyforge_project:
145
- rubygems_version: 2.0.14
129
+ rubygems_version: 2.2.2
146
130
  signing_key:
147
131
  specification_version: 4
148
132
  summary: Differentiate development environemt from production
149
133
  test_files:
150
134
  - spec/rack/dev-mark/middleware_spec.rb
151
- - spec/rack/dev-mark/railtie_spec.rb
152
135
  - spec/rack/dev-mark/theme/base_spec.rb
153
136
  - spec/rack/dev-mark/theme/github_fork_ribbon_spec.rb
154
137
  - spec/rack/dev-mark/title_spec.rb
155
138
  - spec/rack/dev-mark_spec.rb
156
139
  - spec/spec_helper.rb
157
140
  - spec/support/theme_helper.rb
141
+ has_rdoc:
@@ -1,14 +0,0 @@
1
- require 'rack/dev-mark/middleware'
2
-
3
- module Rack
4
- module DevMark
5
- class Railtie < ::Rails::Railtie
6
- initializer 'rack-dev-mark' do |app|
7
- app.middleware.delete Rack::DevMark::Middleware
8
- unless Rack::DevMark.production_env.include? Rack::DevMark.env.to_s
9
- app.middleware.use Rack::DevMark::Middleware, Rack::DevMark.theme
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- if !!Gem.loaded_specs["rails"]
4
-
5
- require 'rails'
6
- require 'rack/dev-mark/railtie'
7
-
8
- describe Rack::DevMark::Railtie do
9
- let(:env) { 'test' }
10
- let(:production_env) { :production }
11
- let(:app) { Class.new(Rails::Application) }
12
- before do
13
- @env = ENV['RAILS_ENV']
14
- ENV['RAILS_ENV'] = env
15
- Rack::DevMark.production_env = production_env
16
- app.initialize!
17
- end
18
- after do
19
- ENV['RAILS_ENV'] = @env
20
- Rails.application = nil
21
- end
22
-
23
- context "development env" do
24
- it "adds rack middleware" do
25
- expect(app.middleware.middlewares).to include(Rack::DevMark::Middleware)
26
- end
27
- context "production_env has test" do
28
- let(:production_env) { 'test' }
29
- it "does not add rack middleware" do
30
- expect(app.middleware.middlewares).not_to include(Rack::DevMark::Middleware)
31
- end
32
- end
33
- end
34
- context "production env" do
35
- let(:env) { 'production' }
36
- it "does not add rack middleware" do
37
- expect(app.middleware.middlewares).not_to include(Rack::DevMark::Middleware)
38
- end
39
- context "production_env has abc" do
40
- let(:production_env) { :abc }
41
- it "does not add rack middleware" do
42
- expect(app.middleware.middlewares).to include(Rack::DevMark::Middleware)
43
- end
44
- end
45
- end
46
- end
47
-
48
- end