rack-dev-mark 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 42a5ffd6f42ef7be54a8f771995e8f25b83eba55
4
- data.tar.gz: 182572ef0e6b865632f8c9fbe3242609a89fd5fd
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWYzMTgzODMzODRiNGNiNGFjM2NkYWE2OWZkZjcxZDJhYzhkNTM4NA==
5
+ data.tar.gz: !binary |-
6
+ YjViMzZiYzlkYmZlNjkzNmYwOGMwYjMyYzRlYTdjNzY3OWZiZmFjYw==
5
7
  SHA512:
6
- metadata.gz: 2e542980f53aa02e8941498ead409fbef42498dba8b28eb0014dda01bfef1f88491685e8370c506f51cd93cb5f77e4499fa4fb93dd73b4925cf77c8c903a100a
7
- data.tar.gz: fb53da781a35607a3e10ea7b4af7d5c5cbe9d230ae839015081700cd09e2216b052500650d816a18fdcdeb309ff8d07a7d69191793f1d10cf6fcf6a72e16d2ba
8
+ metadata.gz: !binary |-
9
+ Y2ZjNjQ5MTEwYzA3ZTAyOGM3Mzc3Y2E4ODY3M2UzNjllNjhmZjNiMWNlNTY4
10
+ NGUwNGVmNzI2Njg4MTBlOTYyYWRmNjU5NmQ2MWVkMTYyMDc2MTgzOWNjN2I1
11
+ ZDI1OWFjNDAwMjlkZDU3MGJlMjdkMGQ4N2I1MmI5MWUzMjI4OGY=
12
+ data.tar.gz: !binary |-
13
+ N2IwMTg3MWE4Yjg5ODViZWFjYWQ1OTNmMjUyNWE1ZjkxMDc4ZDRhNzVkYzQz
14
+ MWRkMmQyM2Y2YzFhMjRmYzVkOGExZmRjYTdjZDEzMDg1YzliNWRkNDYzMmY0
15
+ MmZjMWI1YTk1YTU3ZjgwNTkyNDA5NDVlNGY5NjM1M2IzOThkNjU=
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rack-dev-mark.svg)](http://badge.fury.io/rb/rack-dev-mark) [![Build Status](https://secure.travis-ci.org/dtaniwaki/rack-dev-mark.png?branch=master)](http://travis-ci.org/dtaniwaki/rack-dev-mark) [![Coverage Status](https://coveralls.io/repos/dtaniwaki/rack-dev-mark/badge.png?branch=master)](https://coveralls.io/r/dtaniwaki/rack-dev-mark?branch=master)
4
4
 
5
- Differentiate development environment from production. You can choose [themes](lib/rack/dev-mark/theme/README.md)
5
+ Differentiate development environment from production.
6
+ You can choose [themes](lib/rack/dev-mark/theme/README.md) to differentiate the page.
6
7
 
7
8
  ## Screenshot
8
9
 
@@ -39,7 +40,25 @@ In `config/application.rb`
39
40
  ```ruby
40
41
  module MyApp
41
42
  class Application < Rails::Application
42
- if !%w(production).include?(Rails.env)
43
+ if Rails.env != 'production'
44
+ config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware
45
+ end
46
+ end
47
+ end
48
+ ```
49
+
50
+ The middleware sets [title](lib/rack/dev-mark/theme/title.rb) and [github_fork_ribbon](lib/rack/dev-mark/theme/github_fork_ribbon.rb) themes as default.
51
+
52
+ #### Exclude Multiple Environments in Rails
53
+
54
+ Show the dev mark except env1, env2, env3.
55
+
56
+ In `config/application.rb`
57
+
58
+ ```ruby
59
+ module MyApp
60
+ class Application < Rails::Application
61
+ if !%w(env1 env2 env3).include?(Rails.env)
43
62
  config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware
44
63
  end
45
64
  end
@@ -59,6 +78,13 @@ class NewTheme < Rack::DevMark::Theme::Base
59
78
  html
60
79
  end
61
80
  end
81
+
82
+ class AnotherTheme < Rack::DevMark::Theme::Base
83
+ def insert_into(html, env, revision)
84
+ # Do something for your theme
85
+ html
86
+ end
87
+ end
62
88
  ```
63
89
 
64
90
  Then, insert it in your app.
@@ -66,7 +92,7 @@ Then, insert it in your app.
66
92
  ### For your Rack app
67
93
 
68
94
  ```ruby
69
- use Rack::DevMark::Middleware, NewTheme.new
95
+ use Rack::DevMark::Middleware, [NewTheme.new, AnotherTheme.new]
70
96
  ```
71
97
 
72
98
  ### For your Rails app
@@ -76,13 +102,15 @@ In `config/application.rb`
76
102
  ```ruby
77
103
  module MyApp
78
104
  class Application < Rails::Application
79
- if !%w(production).include?(Rails.env)
80
- config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware, NewTheme.new
105
+ if Rails.env != 'production'
106
+ config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::DevMark::Middleware, [NewTheme.new, AnotherTheme.new]
81
107
  end
82
108
  end
83
109
  end
84
110
  ```
85
111
 
112
+ You can add any combination of themes.
113
+
86
114
  ## Contributing
87
115
 
88
116
  1. Fork it
@@ -1,7 +1,6 @@
1
1
  require 'rack'
2
2
  require 'rack/dev-mark/error'
3
3
  require 'rack/dev-mark/utils'
4
- require 'rack/dev-mark/title'
5
4
  require 'rack/dev-mark/theme'
6
5
  require 'rack/dev-mark/middleware'
7
6
  require 'rack/dev-mark/version'
@@ -4,10 +4,11 @@ module Rack
4
4
  include Rack::Utils
5
5
  include Rack::DevMark::Utils
6
6
 
7
- def initialize(app, theme = :github_fork_ribbon)
7
+ def initialize(app, themes = [:title, :github_fork_ribbon])
8
8
  @app = app
9
- @title = Rack::DevMark::Title.new
10
- @theme = theme.is_a?(Symbol) ? Rack::DevMark::Theme.const_get(camelize(theme.to_s)).new : theme
9
+ @themes = [themes].flatten.map do |theme|
10
+ theme.is_a?(Symbol) ? Rack::DevMark::Theme.const_get(camelize(theme.to_s)).new : theme
11
+ end
11
12
  end
12
13
 
13
14
  def call(env)
@@ -15,6 +16,8 @@ module Rack
15
16
 
16
17
  headers = HeaderHash.new(headers)
17
18
 
19
+ headers['X-Rack-Dev-Mark-Env'] = Rack::DevMark.env
20
+
18
21
  if headers['Content-Type'].to_s =~ %r{^text/html;}i
19
22
  new_body = ''
20
23
  response.each do |b|
@@ -35,8 +38,9 @@ module Rack
35
38
  private
36
39
 
37
40
  def insert_dev_marks(body)
38
- body = @title.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
39
- body = @theme.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
41
+ @themes.each do |theme|
42
+ body = theme.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
43
+ end
40
44
  body
41
45
  end
42
46
  end
@@ -1,10 +1,16 @@
1
1
  # Theme
2
2
 
3
- ## github-fork-ribbon
3
+ ## title
4
+
5
+ Just add the environment into the page title.
6
+
7
+ e.g.
4
8
 
5
- "Fork Me on GitHub" like ribbon
9
+ `My Homepage` on development env will be `(development) My Homepage`
10
+
11
+ ## github-fork-ribbon
6
12
 
7
- https://github.com/simonwhitaker/github-fork-ribbon-css
13
+ ["Fork Me on GitHub" like ribbon](https://github.com/simonwhitaker/github-fork-ribbon-css) originally created by [simonwhitaker](https://github.com/simonwhitaker)
8
14
 
9
15
  ![github-fork-ribbon](screenshots/github_fork_ribbon.png)
10
16
 
@@ -0,0 +1,11 @@
1
+ module Rack
2
+ module DevMark
3
+ module Theme
4
+ class Title
5
+ def insert_into(html, env, revision)
6
+ html.sub %r{(<title[^>]*>)}i, "\\1(#{env}) "
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module DevMark
3
- VERSION = '0.1.5'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "rack", ">= 1.1"
20
20
 
21
21
  gem.add_development_dependency "rake"
22
- gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency "rspec", ">= 3.0"
23
23
  gem.add_development_dependency "coveralls"
24
24
  end
@@ -1,29 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rack::DevMark::Middleware do
4
- let(:app) { double call: [200, {'Content-Type' => 'text/html; charset=utf-8'}, ['response']] }
5
- subject { Rack::DevMark::Middleware.new(app) }
4
+ let(:headers) { {'Content-Type' => 'text/html; charset=utf-8'} }
5
+ let(:body) { ['response'] }
6
+ let(:theme) { d = double; allow(d).to receive(:insert_into){ |b, _, _| "#{b} dev-mark" }; d }
7
+ let(:app) { double call: [200, headers, body] }
8
+ subject { Rack::DevMark::Middleware.new(app, theme) }
6
9
  before do
7
10
  allow(Rack::DevMark).to receive(:env).and_return('test')
8
11
  allow(Rack::DevMark).to receive(:revision).and_return('rev')
9
12
  end
10
13
 
11
- it "inserts planbcd tag" do
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')
14
+ it "inserts dev mark" do
14
15
  status, headers, body = subject.call({})
15
16
  expect(status).to eq(200)
16
- expect(headers).to eq({'Content-Type' => 'text/html; charset=utf-8'})
17
- expect(body).to eq(['response'])
17
+ expect(headers).to include('Content-Type' => 'text/html; charset=utf-8')
18
+ expect(body).to eq(["response dev-mark"])
19
+ end
20
+ it "adds http headers" do
21
+ _, headers, _ = subject.call({})
22
+ expect(headers).to include('X-Rack-Dev-Mark-Env' => 'test')
23
+ end
24
+ context "multiple themes" do
25
+ let(:_theme) { d = double; allow(d).to receive(:insert_into){ |b, _, _| "#{b} dev-mark" }; d }
26
+ let(:theme) { [_theme] * 3 }
27
+ it "uses title and github_fork_ribbon" do
28
+ theme.each_with_index do |theme, idx|
29
+ expect(theme).to receive(:insert_into).once.and_return('')
30
+ end
31
+ subject.call({})
32
+ end
33
+ end
34
+ context "default themes" do
35
+ subject { Rack::DevMark::Middleware.new(app) }
36
+ it "uses title and github_fork_ribbon" do
37
+ expect_any_instance_of(Rack::DevMark::Theme::Title).to receive(:insert_into).once.and_return('')
38
+ expect_any_instance_of(Rack::DevMark::Theme::GithubForkRibbon).to receive(:insert_into).once.and_return('')
39
+ subject.call({})
40
+ end
18
41
  end
19
42
  context "not html request" do
20
- let(:app) { double call: [200, {'Content-Type' => 'application/json;'}, ['{}']] }
43
+ let(:headers) { {'Content-Type' => 'application/json;'} }
44
+ let(:body) { ['{}'] }
21
45
  it "does not insert planbcd tag if the body does not have head tag" do
22
- expect_any_instance_of(Rack::DevMark::Title).not_to receive(:insert_into)
23
- expect_any_instance_of(Rack::DevMark::Theme::GithubForkRibbon).not_to receive(:insert_into)
46
+ expect(theme).not_to receive(:insert_to)
24
47
  status, headers, body = subject.call({})
25
48
  expect(status).to eq(200)
26
- expect(headers).to eq({'Content-Type' => 'application/json;'})
49
+ expect(headers).to include('Content-Type' => 'application/json;')
27
50
  expect(body).to eq(['{}'])
28
51
  end
29
52
  end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rack::DevMark::Title do
3
+ describe Rack::DevMark::Theme::Title do
4
4
  it_behaves_like "theme" do
5
5
  let (:out) { %Q~<html><head>head<title>(env) title</title></head><body>body</body></html>~ }
6
- subject { Rack::DevMark::Title.new }
6
+ subject { Rack::DevMark::Theme::Title.new }
7
7
  end
8
8
  context "no title tag" do
9
9
  let (:src) { %Q~<html><head>head</head><body>body</body></html>~ }
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dev-mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.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-11 00:00:00.000000000 Z
11
+ date: 2014-06-14 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
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Differentiate development environemt from production
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".gitignore"
77
- - ".travis.yml"
76
+ - .gitignore
77
+ - .travis.yml
78
78
  - Gemfile
79
79
  - LICENSE
80
80
  - README.md
@@ -93,7 +93,7 @@ files:
93
93
  - lib/rack/dev-mark/theme/base.rb
94
94
  - lib/rack/dev-mark/theme/github_fork_ribbon.rb
95
95
  - lib/rack/dev-mark/theme/screenshots/github_fork_ribbon.png
96
- - lib/rack/dev-mark/title.rb
96
+ - lib/rack/dev-mark/theme/title.rb
97
97
  - lib/rack/dev-mark/utils.rb
98
98
  - lib/rack/dev-mark/version.rb
99
99
  - rack-dev-mark.gemspec
@@ -102,7 +102,7 @@ files:
102
102
  - spec/rack/dev-mark/middleware_spec.rb
103
103
  - spec/rack/dev-mark/theme/base_spec.rb
104
104
  - spec/rack/dev-mark/theme/github_fork_ribbon_spec.rb
105
- - spec/rack/dev-mark/title_spec.rb
105
+ - spec/rack/dev-mark/theme/title_spec.rb
106
106
  - spec/rack/dev-mark_spec.rb
107
107
  - spec/spec_helper.rb
108
108
  - spec/support/theme_helper.rb
@@ -118,12 +118,12 @@ require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ">="
121
+ - - ! '>='
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - ">="
126
+ - - ! '>='
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  requirements: []
@@ -136,8 +136,7 @@ test_files:
136
136
  - spec/rack/dev-mark/middleware_spec.rb
137
137
  - spec/rack/dev-mark/theme/base_spec.rb
138
138
  - spec/rack/dev-mark/theme/github_fork_ribbon_spec.rb
139
- - spec/rack/dev-mark/title_spec.rb
139
+ - spec/rack/dev-mark/theme/title_spec.rb
140
140
  - spec/rack/dev-mark_spec.rb
141
141
  - spec/spec_helper.rb
142
142
  - spec/support/theme_helper.rb
143
- has_rdoc:
@@ -1,9 +0,0 @@
1
- module Rack
2
- module DevMark
3
- class Title
4
- def insert_into(html, env, revision)
5
- html.sub %r{(<title[^>]*>)}i, "\\1(#{env}) "
6
- end
7
- end
8
- end
9
- end