rack-env_ribbon 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -14
- data/lib/rack/env_ribbon.rb +23 -5
- data/lib/rack/env_ribbon/html_converter.rb +4 -2
- data/lib/rack/env_ribbon/railtie.rb +1 -2
- data/lib/rack/env_ribbon/version.rb +3 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 324d7c6c79dc4c94779f88ee445b0e80d4a2dab9
|
4
|
+
data.tar.gz: 6b4f3b38fb4a8153fed7d530c417d881acf68edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c63b24c7effb2b294e3aec5fb51b9eb4374e8d46093389968588264672754fdac2fc921019d7efa9bdbae7f301106a31e26a4a91ffa573cd5232d66099c893a3
|
7
|
+
data.tar.gz: 4e71b95aeb8dbc38a040605150cc46f89a2a00a745c8aacb0c913bbf71725e13259b464911a70c0197bf51c64ef7bcdd274c3b706e0c793dabc594dd88c434a6
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ run app
|
|
24
24
|
|
25
25
|
### Sinatra
|
26
26
|
|
27
|
-
Add `use Rack::EnvRibbon` in the same way as rack application
|
27
|
+
Add `use Rack::EnvRibbon` in the same way as rack application
|
28
28
|
|
29
29
|
```rb
|
30
30
|
require 'sinatra'
|
@@ -35,29 +35,30 @@ use Rack::EnvRibbon
|
|
35
35
|
|
36
36
|
get '/' do
|
37
37
|
<<-HTML
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
<!DOCTYPE html>
|
39
|
+
<html lang="ja">
|
40
|
+
<head>
|
41
|
+
<meta charset="utf-8">
|
42
|
+
<title>sinatra app</title>
|
43
|
+
</head>
|
44
|
+
<body>
|
45
|
+
<p>app body</p>
|
46
|
+
</body>
|
47
|
+
</html>
|
48
48
|
HTML
|
49
49
|
end
|
50
50
|
```
|
51
51
|
|
52
52
|
### Rails
|
53
53
|
|
54
|
-
Add this line to your application's Gemfile
|
54
|
+
Add this line to your application's Gemfile
|
55
55
|
|
56
56
|
```ruby
|
57
|
-
gem 'rack-env_ribbon'
|
57
|
+
gem 'rack-env_ribbon'
|
58
58
|
```
|
59
59
|
|
60
|
-
And then execute
|
60
|
+
And then execute
|
61
|
+
|
61
62
|
```bash
|
62
63
|
$ bundle
|
63
64
|
```
|
data/lib/rack/env_ribbon.rb
CHANGED
@@ -1,32 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack/utils'
|
1
4
|
require 'rack/env_ribbon/html_converter'
|
2
5
|
|
3
6
|
module Rack
|
4
7
|
class EnvRibbon
|
8
|
+
include Rack::Utils
|
9
|
+
|
5
10
|
def initialize(app, opts = {})
|
6
11
|
@app = app
|
7
12
|
end
|
8
13
|
|
9
14
|
def call(env)
|
10
15
|
status, headers, body = @app.call(env)
|
16
|
+
headers = HeaderHash.new(headers)
|
11
17
|
|
12
|
-
if headers
|
18
|
+
if applicable?(status, headers)
|
13
19
|
new_body = []
|
20
|
+
new_content_length = 0
|
14
21
|
|
15
|
-
# The response body must respond to each.
|
22
|
+
# The response body must respond to `each` method.
|
16
23
|
body.each do |html|
|
17
24
|
converter = HtmlConverter.new(html, app_env)
|
18
|
-
next unless converter.
|
25
|
+
next unless converter.valid_html?
|
26
|
+
|
19
27
|
converter.insert_env_ribbon_into_body
|
20
28
|
converter.insert_env_string_into_title
|
21
29
|
converter.insert_env_ribbon_style_into_head
|
22
|
-
|
30
|
+
result = converter.result
|
31
|
+
|
32
|
+
new_body << result
|
33
|
+
new_content_length += result.bytesize
|
23
34
|
end
|
24
35
|
|
25
36
|
new_body.compact!
|
26
37
|
|
27
38
|
unless new_body.empty?
|
28
39
|
body = new_body
|
29
|
-
headers[CONTENT_LENGTH] &&=
|
40
|
+
headers[CONTENT_LENGTH] &&= new_content_length
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
@@ -38,5 +49,12 @@ module Rack
|
|
38
49
|
def app_env
|
39
50
|
@app_env ||= ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
40
51
|
end
|
52
|
+
|
53
|
+
def applicable?(status, headers)
|
54
|
+
!STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
|
55
|
+
headers[CONTENT_TYPE] =~ /\btext\/html\b/
|
56
|
+
end
|
41
57
|
end
|
42
58
|
end
|
59
|
+
|
60
|
+
require 'rack/env_ribbon/railtie' if defined?(Rails::Railtie)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
class EnvRibbon
|
3
5
|
class HtmlConverter
|
@@ -8,8 +10,8 @@ module Rack
|
|
8
10
|
@env = env.to_s
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
+
def valid_html?
|
14
|
+
has_tag?('html') && has_tag?('body')
|
13
15
|
end
|
14
16
|
|
15
17
|
def insert_env_string_into_title
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-env_ribbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Iguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -38,6 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: poltergeist
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: pry
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|