rack-env_ribbon 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +3 -0
- data/lib/rack/env_ribbon/html_converter.rb +83 -0
- data/lib/rack/env_ribbon/railtie.rb +12 -0
- data/lib/rack/env_ribbon/version.rb +5 -0
- data/lib/rack/env_ribbon.rb +39 -0
- data/vendor/assets/stylesheets/env_ribbon.css +4 -0
- data/vendor/assets/stylesheets/env_ribbon.ie.css +4 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c597c00aec04888f3809cc50dd3f461c27680823
|
4
|
+
data.tar.gz: 21afbf13e1c9337914cae6454c01867cf114db54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b0fc1880a71ab58666463b2f5c45efd478e1dfb20affecc27bd1c726fa59045a548b7a7c1040cdcdb113cf917b436fefdfff2af7092276346b73010a8db26961
|
7
|
+
data.tar.gz: 751186cfde79d763a3a07ee9d54341253e030a46f8ef980e297b16a012829956bb631ef4efd1ff6379de58a54f4221e86e5c731f9df81646a8b710171abd6de6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Shota Iguchi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Rack::EnvRibbon
|
2
|
+
Add env ribbon on your rack application views.
|
3
|
+
|
4
|
+
![](screen_shot.png)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```sh
|
9
|
+
$ gem install rack-env_ribbon
|
10
|
+
```
|
11
|
+
|
12
|
+
### Rack application
|
13
|
+
|
14
|
+
Add `use Rack::EnvRibbon` on your `config.ru` file.
|
15
|
+
|
16
|
+
```rb
|
17
|
+
require 'rack/env_ribbon'
|
18
|
+
|
19
|
+
app # => your rack application object
|
20
|
+
|
21
|
+
use Rack::EnvRibbon
|
22
|
+
run app
|
23
|
+
```
|
24
|
+
|
25
|
+
### Sinatra
|
26
|
+
|
27
|
+
Add `use Rack::EnvRibbon` in the same way as rack application.
|
28
|
+
|
29
|
+
```rb
|
30
|
+
require 'sinatra'
|
31
|
+
|
32
|
+
require 'rack/env_ribbon'
|
33
|
+
|
34
|
+
use Rack::EnvRibbon
|
35
|
+
|
36
|
+
get '/' do
|
37
|
+
<<-HTML
|
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>body</p>
|
46
|
+
</body>
|
47
|
+
</html>
|
48
|
+
HTML
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
### Rails
|
53
|
+
|
54
|
+
Add this line to your application's Gemfile:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
gem 'rack-env_ribbon', require: 'rack/env_ribbon/railtie'
|
58
|
+
```
|
59
|
+
|
60
|
+
And then execute:
|
61
|
+
```bash
|
62
|
+
$ bundle
|
63
|
+
```
|
64
|
+
|
65
|
+
## License
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
module Rack
|
2
|
+
class EnvRibbon
|
3
|
+
class HtmlConverter
|
4
|
+
attr_reader :html, :env
|
5
|
+
|
6
|
+
def initialize(html, env)
|
7
|
+
@html = html
|
8
|
+
@env = env.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
@valid ||= has_tag?('html') && has_tag?('body')
|
13
|
+
end
|
14
|
+
|
15
|
+
def insert_env_string_into_title
|
16
|
+
tag = 'title'
|
17
|
+
insert_into(tag, "(#{env}) ") if has_tag?(tag)
|
18
|
+
end
|
19
|
+
|
20
|
+
def insert_env_ribbon_style_into_head
|
21
|
+
css_file = ::File.open(::File.join(assets_path, 'stylesheets/env_ribbon.css'))
|
22
|
+
ie_css_file = ::File.open(::File.join(assets_path, 'stylesheets/env_ribbon.ie.css'))
|
23
|
+
|
24
|
+
content = <<-EOS
|
25
|
+
<style>
|
26
|
+
#{css_file.read}
|
27
|
+
</style>
|
28
|
+
|
29
|
+
<!--[if lt IE 9]>
|
30
|
+
<style>
|
31
|
+
#{ie_css_file.read}
|
32
|
+
</style>
|
33
|
+
<![endif]-->
|
34
|
+
EOS
|
35
|
+
|
36
|
+
css_file.close
|
37
|
+
ie_css_file.close
|
38
|
+
|
39
|
+
insert_into('head', content, last_line: true, new_line: true)
|
40
|
+
end
|
41
|
+
|
42
|
+
def insert_env_ribbon_into_body
|
43
|
+
content = <<-EOS
|
44
|
+
<a class="github-fork-ribbon left-top red fixed" onClick="this.style.display='none'" title="#{env}">#{env}</a>
|
45
|
+
EOS
|
46
|
+
|
47
|
+
insert_into('body', content, new_line: true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def result
|
51
|
+
html
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def start_tag_regexp(tag)
|
57
|
+
/(<#{tag}[^>]*>)/i
|
58
|
+
end
|
59
|
+
|
60
|
+
def end_tag_regexp(tag)
|
61
|
+
/(<\/#{tag}>)/i
|
62
|
+
end
|
63
|
+
|
64
|
+
def has_tag?(tag)
|
65
|
+
!!(html =~ start_tag_regexp(tag) && html =~ end_tag_regexp(tag))
|
66
|
+
end
|
67
|
+
|
68
|
+
def insert_into(tag, content, last_line: false, new_line: false)
|
69
|
+
if last_line
|
70
|
+
content_placement = new_line ? "\n#{content}\n\\1" : "#{content}\\1"
|
71
|
+
html.sub!(end_tag_regexp(tag), content_placement)
|
72
|
+
else
|
73
|
+
content_placement = new_line ? "\n\\1#{content}\n" : "\\1#{content}"
|
74
|
+
html.sub!(start_tag_regexp(tag), content_placement)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def assets_path
|
79
|
+
::File.expand_path('../../../vendor/assets', __dir__)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rack/env_ribbon/html_converter'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class EnvRibbon
|
5
|
+
def initialize(app, opts = {})
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
status, headers, body = @app.call(env)
|
11
|
+
new_body = []
|
12
|
+
|
13
|
+
if headers[CONTENT_TYPE] =~ /\btext\/html\b/
|
14
|
+
body.each do |b|
|
15
|
+
converter = HtmlConverter.new(b, app_env)
|
16
|
+
next unless converter.valid?
|
17
|
+
converter.insert_env_ribbon_into_body
|
18
|
+
converter.insert_env_string_into_title
|
19
|
+
converter.insert_env_ribbon_style_into_head
|
20
|
+
new_body << converter.result
|
21
|
+
end
|
22
|
+
|
23
|
+
unless new_body.empty?
|
24
|
+
body = new_body
|
25
|
+
content_length = body.map(&:bytesize).inject(&:+)
|
26
|
+
headers[CONTENT_LENGTH] &&= content_length.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
[status, headers, body]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def app_env
|
36
|
+
@app_env ||= ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
/*!
|
2
|
+
* "Fork me on GitHub" CSS ribbon v0.2.0 | MIT License
|
3
|
+
* https://github.com/simonwhitaker/github-fork-ribbon-css
|
4
|
+
*/.github-fork-ribbon{width:12.1em;height:12.1em;position:absolute;overflow:hidden;top:0;right:0;z-index:9999;pointer-events:none;font-size:13px;text-decoration:none;text-indent:-999999px}.github-fork-ribbon.fixed{position:fixed}.github-fork-ribbon:after,.github-fork-ribbon:before{position:absolute;display:block;width:15.38em;height:1.54em;top:3.23em;right:-3.23em;-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);-o-transform:rotate(45deg);transform:rotate(45deg)}.github-fork-ribbon:before{content:"";padding:.38em 0;background-color:#a00;background-image:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,0)),to(rgba(0,0,0,.15)));background-image:-webkit-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-moz-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-ms-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:-o-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.15));background-image:linear-gradient(to bottom,rgba(0,0,0,0),rgba(0,0,0,.15));-webkit-box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);-moz-box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);box-shadow:0 .15em .23em 0 rgba(0,0,0,.5);pointer-events:auto}.github-fork-ribbon:after{content:attr(title);color:#fff;font:700 1em "Helvetica Neue",Helvetica,Arial,sans-serif;line-height:1.54em;text-decoration:none;text-shadow:0 -.08em rgba(0,0,0,.5);text-align:center;text-indent:0;padding:.15em 0;margin:.15em 0;border-width:.08em 0;border-style:dotted;border-color:#fff;border-color:rgba(255,255,255,.7)}.github-fork-ribbon.left-bottom,.github-fork-ribbon.left-top{right:auto;left:0}.github-fork-ribbon.left-bottom,.github-fork-ribbon.right-bottom{top:auto;bottom:0}.github-fork-ribbon.left-bottom:after,.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.left-top:after,.github-fork-ribbon.left-top:before{right:auto;left:-3.23em}.github-fork-ribbon.left-bottom:after,.github-fork-ribbon.left-bottom:before,.github-fork-ribbon.right-bottom:after,.github-fork-ribbon.right-bottom:before{top:auto;bottom:3.23em}.github-fork-ribbon.left-top:after,.github-fork-ribbon.left-top:before,.github-fork-ribbon.right-bottom:after,.github-fork-ribbon.right-bottom:before{-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg)}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
/*!
|
2
|
+
* "Fork me on GitHub" CSS ribbon v0.2.0 | MIT License
|
3
|
+
* https://github.com/simonwhitaker/github-fork-ribbon-css
|
4
|
+
*/html{overflow:auto}body{position:relative;width:100%;height:auto;overflow:hidden}.github-fork-ribbon{width:15.38em;height:5.62em;top:-3.92em;right:-4.46em;-ms-filter:"progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865474, M12=-0.7071067811865477, M21=0.7071067811865477, M22=0.7071067811865474, SizingMethod='auto expand')"}.github-fork-ribbon.left-top,.github-fork-ribbon.right-bottom{-ms-filter:"progid:DXImageTransform.Microsoft.Matrix(M11=0.7071067811865483, M12=0.7071067811865467, M21=-0.7071067811865467, M22=0.7071067811865483, SizingMethod='auto expand')"}.github-fork-ribbon:after,.github-fork-ribbon:before{left:auto!important;right:auto!important;font-size:inherit}.github-fork-ribbon.left-bottom,.github-fork-ribbon.left-top{left:-3.92em}.github-fork-ribbon.left-bottom,.github-fork-ribbon.right-bottom{bottom:4.77em}
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-env_ribbon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shota Iguchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
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: pry-byebug
|
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
|
+
description:
|
70
|
+
email:
|
71
|
+
- shota-iguchi@cookpad.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/rack/env_ribbon.rb
|
80
|
+
- lib/rack/env_ribbon/html_converter.rb
|
81
|
+
- lib/rack/env_ribbon/railtie.rb
|
82
|
+
- lib/rack/env_ribbon/version.rb
|
83
|
+
- vendor/assets/stylesheets/env_ribbon.css
|
84
|
+
- vendor/assets/stylesheets/env_ribbon.ie.css
|
85
|
+
homepage: https://github.com/iguchi1124/rack-env_ribbon
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.5.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Add env ribbon on your rack application views.
|
109
|
+
test_files: []
|