rack-showme 0.0.1
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.
- data/Gemfile +4 -0
- data/README.markdown +20 -0
- data/Rakefile +2 -0
- data/lib/rack/showme/options.rb +17 -0
- data/lib/rack/showme/public/showme.css +12 -0
- data/lib/rack/showme/version.rb +5 -0
- data/lib/rack/showme.rb +49 -0
- data/rack-showme.gemspec +18 -0
- data/test/test_helper.rb +1 -0
- metadata +55 -0
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Rack-Showme
|
2
|
+
|
3
|
+
Rack middleware that injects a message into HTML responses.
|
4
|
+
|
5
|
+
## Using with Rails
|
6
|
+
|
7
|
+
Add the following line to your Gemfile
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "rack-showme"
|
11
|
+
```
|
12
|
+
|
13
|
+
Then add the following lines to your application.rb file
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require "rack/showme
|
17
|
+
config.middleware.use "Rack::Showme"
|
18
|
+
Rack::Showme::Options.message = "Development"
|
19
|
+
```
|
20
|
+
|
data/Rakefile
ADDED
data/lib/rack/showme.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "rack/showme/options"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Showme
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@env = env
|
11
|
+
@status, @headers, @response = @app.call(env)
|
12
|
+
|
13
|
+
inject_html if initial_page_request?
|
14
|
+
|
15
|
+
[@status, @headers, @response]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def ajax_request?
|
20
|
+
@env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
|
21
|
+
end
|
22
|
+
|
23
|
+
def initial_page_request?
|
24
|
+
!ajax_request? && html_response?
|
25
|
+
end
|
26
|
+
|
27
|
+
def html_response?
|
28
|
+
@headers && @headers["Content-Type"] && @headers["Content-Type"].include?("text/html")
|
29
|
+
end
|
30
|
+
|
31
|
+
def inject_html
|
32
|
+
css_line = %Q{<style type="text/css">#{read_public_file("showme.css")}</style>\n}
|
33
|
+
code = "<div id=\"show-me-message\"> #{Options.message}</div>"
|
34
|
+
|
35
|
+
body = @response.body
|
36
|
+
body.gsub!("<body>", "<body>#{code}")
|
37
|
+
body.gsub!("</body>", "#{css_line}</body>")
|
38
|
+
@response.body = body
|
39
|
+
|
40
|
+
@headers["Content-Length"] = @response.body.bytesize.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def read_public_file(filename)
|
44
|
+
output = ::File.open(::File.join(::File.dirname(__FILE__), "showme", "public", filename), "r:UTF-8") do |f|
|
45
|
+
f.read
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/rack-showme.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack/showme/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-showme"
|
7
|
+
s.version = Rack::Showme::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Omar Vargas"]
|
10
|
+
s.email = ["ovargas27@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/ovargas27/rack-showme"
|
12
|
+
s.summary = %q{Injects a message into HTML responses.}
|
13
|
+
s.description = %q{Rack middleware that injects a message into HTML responses.}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-showme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Omar Vargas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Rack middleware that injects a message into HTML responses.
|
15
|
+
email:
|
16
|
+
- ovargas27@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- README.markdown
|
23
|
+
- Rakefile
|
24
|
+
- lib/rack/showme.rb
|
25
|
+
- lib/rack/showme/options.rb
|
26
|
+
- lib/rack/showme/public/showme.css
|
27
|
+
- lib/rack/showme/version.rb
|
28
|
+
- rack-showme.gemspec
|
29
|
+
- test/test_helper.rb
|
30
|
+
homepage: https://github.com/ovargas27/rack-showme
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.23
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Injects a message into HTML responses.
|
54
|
+
test_files: []
|
55
|
+
has_rdoc:
|