rack-dev-mark 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWYzMTgzODMzODRiNGNiNGFjM2NkYWE2OWZkZjcxZDJhYzhkNTM4NA==
4
+ MDZhYWU3YWUzMjdiM2MxMDc2ZmY3ODdjZDA2NTlmZDBjNDMwYzY0ZQ==
5
5
  data.tar.gz: !binary |-
6
- YjViMzZiYzlkYmZlNjkzNmYwOGMwYjMyYzRlYTdjNzY3OWZiZmFjYw==
6
+ ZWIwMDliNmZmZmQ5NTg2NTNjNWNiODVlNGI3NDQ0YjM1MDQ5N2E4OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2ZjNjQ5MTEwYzA3ZTAyOGM3Mzc3Y2E4ODY3M2UzNjllNjhmZjNiMWNlNTY4
10
- NGUwNGVmNzI2Njg4MTBlOTYyYWRmNjU5NmQ2MWVkMTYyMDc2MTgzOWNjN2I1
11
- ZDI1OWFjNDAwMjlkZDU3MGJlMjdkMGQ4N2I1MmI5MWUzMjI4OGY=
9
+ OTFjY2RiMDIzMmY2MGQwNjEzZjk4ZDZmNmFhNjI5NTJlYWZmMWFjYjg0YmU0
10
+ ZTYzNjhjZDkwYTA0ZTA5OWFkZTRiMDlmMjA3NTdiZjQ3ZGZkNWEwZjI3ZDQ4
11
+ MGYyZmMxYTZiMWZjNTk3ZGNmNzhjZmJmZmQ5ZjRiZTlkNWMxMmU=
12
12
  data.tar.gz: !binary |-
13
- N2IwMTg3MWE4Yjg5ODViZWFjYWQ1OTNmMjUyNWE1ZjkxMDc4ZDRhNzVkYzQz
14
- MWRkMmQyM2Y2YzFhMjRmYzVkOGExZmRjYTdjZDEzMDg1YzliNWRkNDYzMmY0
15
- MmZjMWI1YTk1YTU3ZjgwNTkyNDA5NDVlNGY5NjM1M2IzOThkNjU=
13
+ YzliN2QzODAzMmM2OTdkZWFmNTY5YWQzNDVmYTFhN2RjYjFhY2ZlYjI3YjAw
14
+ Njg1MDJlYzc1N2IxZmE0MjM1Mzk3MzAyMGZmN2RmNzljYTMyOTJkZTY2OTAy
15
+ OWY5ZDc1MmMzMDQ3YmUwMzM0MjkyYjY5YmRjMzc2ZDA0NzBmNmI=
@@ -7,7 +7,9 @@ module Rack
7
7
  def initialize(app, themes = [:title, :github_fork_ribbon])
8
8
  @app = app
9
9
  @themes = [themes].flatten.map do |theme|
10
- theme.is_a?(Symbol) ? Rack::DevMark::Theme.const_get(camelize(theme.to_s)).new : theme
10
+ theme = theme.is_a?(Symbol) ? Rack::DevMark::Theme.const_get(camelize(theme.to_s)).new : theme
11
+ theme.setup Rack::DevMark.env, Rack::DevMark.revision
12
+ theme
11
13
  end
12
14
  end
13
15
 
@@ -39,7 +41,7 @@ module Rack
39
41
 
40
42
  def insert_dev_marks(body)
41
43
  @themes.each do |theme|
42
- body = theme.insert_into(body, Rack::DevMark.env, Rack::DevMark.revision)
44
+ body = theme.insert_into(body)
43
45
  end
44
46
  body
45
47
  end
@@ -8,6 +8,12 @@ e.g.
8
8
 
9
9
  `My Homepage` on development env will be `(development) My Homepage`
10
10
 
11
+ ### options
12
+
13
+ `type`: `prefix` (default) or `postfix`
14
+
15
+ `upcase`: `true` or `false` (default)
16
+
11
17
  ## github-fork-ribbon
12
18
 
13
19
  ["Fork Me on GitHub" like ribbon](https://github.com/simonwhitaker/github-fork-ribbon-css) originally created by [simonwhitaker](https://github.com/simonwhitaker)
@@ -2,15 +2,20 @@ module Rack
2
2
  module DevMark
3
3
  module Theme
4
4
  class Base
5
+ attr_reader :env, :revision
6
+
5
7
  def initialize(*args)
6
8
  raise RuntimeError, 'Abstract class can not be instantiated' if self.class == Rack::DevMark::Theme::Base
7
9
  end
8
10
 
9
- def insert_into(html, env, revision)
10
-
11
+ def setup(env, revision)
12
+ @env = env
13
+ @revision = revision
11
14
  end
12
15
 
13
- private
16
+ def insert_into(html)
17
+
18
+ end
14
19
 
15
20
  def stylesheet_link_tag(path)
16
21
  %Q~<style>#{::File.open(::File.join(::File.dirname(__FILE__), '../../../../vendor/assets/stylesheets', path)).read}</style>~
@@ -9,7 +9,7 @@ module Rack
9
9
  @options = options
10
10
  end
11
11
 
12
- def insert_into(html, env, revision)
12
+ def insert_into(html)
13
13
  position = @options[:position] || 'left'
14
14
  color = @options[:color] || 'red'
15
15
  fixed = @options[:fixed] ? ' fixed' : ''
@@ -1,9 +1,19 @@
1
1
  module Rack
2
2
  module DevMark
3
3
  module Theme
4
- class Title
5
- def insert_into(html, env, revision)
6
- html.sub %r{(<title[^>]*>)}i, "\\1(#{env}) "
4
+ class Title < Base
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def insert_into(html)
10
+ s = env.to_s
11
+ s = s.upcase if @options[:upcase]
12
+ if @options[:type].to_s == 'postfix'
13
+ html.sub %r{(</title[^>]*>)}i, " (#{s})\\1"
14
+ else
15
+ html.sub %r{(<title[^>]*>)}i, "\\1(#{s}) "
16
+ end
7
17
  end
8
18
  end
9
19
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module DevMark
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Rack::DevMark::Middleware do
4
4
  let(:headers) { {'Content-Type' => 'text/html; charset=utf-8'} }
5
5
  let(:body) { ['response'] }
6
- let(:theme) { d = double; allow(d).to receive(:insert_into){ |b, _, _| "#{b} dev-mark" }; d }
6
+ let(:theme) { d = double setup: nil; allow(d).to receive(:insert_into){ |b| "#{b} dev-mark" }; d }
7
7
  let(:app) { double call: [200, headers, body] }
8
8
  subject { Rack::DevMark::Middleware.new(app, theme) }
9
9
  before do
@@ -21,8 +21,15 @@ describe Rack::DevMark::Middleware do
21
21
  _, headers, _ = subject.call({})
22
22
  expect(headers).to include('X-Rack-Dev-Mark-Env' => 'test')
23
23
  end
24
+ context "symbol theme" do
25
+ let(:theme) { :title }
26
+ it "uses title" do
27
+ expect_any_instance_of(Rack::DevMark::Theme::Title).to receive(:insert_into).once.and_return('')
28
+ subject.call({})
29
+ end
30
+ end
24
31
  context "multiple themes" do
25
- let(:_theme) { d = double; allow(d).to receive(:insert_into){ |b, _, _| "#{b} dev-mark" }; d }
32
+ let(:_theme) { d = double setup: nil; allow(d).to receive(:insert_into){ |b| "#{b} dev-mark" }; d }
26
33
  let(:theme) { [_theme] * 3 }
27
34
  it "uses title and github_fork_ribbon" do
28
35
  theme.each_with_index do |theme, idx|
@@ -6,4 +6,12 @@ describe Rack::DevMark::Theme::Base do
6
6
  Rack::DevMark::Theme::Base.new
7
7
  }.to raise_error(Rack::DevMark::RuntimeError)
8
8
  end
9
+ describe "subclass" do
10
+ subject { Class.new(Rack::DevMark::Theme::Base).new }
11
+ it "sets up" do
12
+ subject.setup 'env', 'rev'
13
+ expect(subject.env).to eq('env')
14
+ expect(subject.revision).to eq('rev')
15
+ end
16
+ end
9
17
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rack::DevMark::Theme::GithubForkRibbon do
4
+ include_context "theme context"
4
5
  it_behaves_like "theme" do
5
6
  let :out do
6
7
  s = <<-EOS
@@ -1,15 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rack::DevMark::Theme::Title do
4
+ include_context "theme context"
4
5
  it_behaves_like "theme" do
5
6
  let (:out) { %Q~<html><head>head<title>(env) title</title></head><body>body</body></html>~ }
6
7
  subject { Rack::DevMark::Theme::Title.new }
7
8
  end
9
+ context "upcase is true" do
10
+ let (:out) { %Q~<html><head>head<title>(ENV) title</title></head><body>body</body></html>~ }
11
+ subject { Rack::DevMark::Theme::Title.new(upcase: true) }
12
+ it_behaves_like "theme"
13
+ end
14
+ context "upcase is true" do
15
+ let (:out) { %Q~<html><head>head<title>(env) title</title></head><body>body</body></html>~ }
16
+ subject { Rack::DevMark::Theme::Title.new(upcase: false) }
17
+ it_behaves_like "theme"
18
+ end
19
+ context "type is prefix" do
20
+ let (:out) { %Q~<html><head>head<title>(env) title</title></head><body>body</body></html>~ }
21
+ subject { Rack::DevMark::Theme::Title.new(type: 'prefix') }
22
+ it_behaves_like "theme"
23
+ end
24
+ context "type is postfix" do
25
+ let (:out) { %Q~<html><head>head<title>title (env)</title></head><body>body</body></html>~ }
26
+ subject { Rack::DevMark::Theme::Title.new(type: 'postfix') }
27
+ it_behaves_like "theme"
28
+ end
8
29
  context "no title tag" do
9
30
  let (:src) { %Q~<html><head>head</head><body>body</body></html>~ }
10
31
  let (:out) { %Q~<html><head>head</head><body>body</body></html>~ }
11
32
  it "does not insert anything" do
12
- expect(subject.insert_into(src, 'env', 'rev')).to eq(src)
33
+ expect(subject.insert_into(src)).to eq(src)
13
34
  end
14
35
  end
15
36
  end
@@ -1,10 +1,16 @@
1
- RSpec.shared_examples "theme" do
1
+ RSpec.shared_context "theme context" do
2
2
  def read_stylesheet(path)
3
3
  ::File.open(::File.join(::File.dirname(__FILE__), '../../vendor/assets/stylesheets', path)).read
4
4
  end
5
5
 
6
+ before do
7
+ subject.setup 'env', 'rev'
8
+ end
9
+ end
10
+
11
+ RSpec.shared_examples "theme" do
6
12
  let (:src) { %Q~<html><head>head<title>title</title></head><body>body</body></html>~ }
7
- it "insert env mark" do
8
- expect(subject.insert_into(src, 'env', 'rev')).to eq(out)
13
+ it "inserts env mark" do
14
+ expect(subject.insert_into(src)).to eq(out)
9
15
  end
10
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-dev-mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-14 00:00:00.000000000 Z
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack