rack-toolbar 0.1.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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +85 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rack/toolbar/version.rb +5 -0
- data/lib/rack/toolbar.rb +64 -0
- data/rack-toolbar.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7290b0c5c77f8cdaea3f74a545caf3c9346752c
|
4
|
+
data.tar.gz: 1b421d6076390e190f3af39159958845638e96e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f31c3485d5349def0489f9fa527751cbe2758cd9aa9a18fbfc9ea5e77a19b372b1c71c02d4101d8ead4a83cf19de1bb1dd8f259c394516836a7ba4853dce5efd
|
7
|
+
data.tar.gz: d8385ca9bb07b109ae0d8ec97caf3a80cec701b03179d396eade0bb8bd77967f2ad06ad644554aaa0efc05674f7be94db7f7e8f93a7ddce0840a9440fd6b95e5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Rack::Toolbar
|
2
|
+
|
3
|
+
Allows you to create simple Rack Middleware that will insert HTML (or whatever!) into responses at specific points.
|
4
|
+
|
5
|
+
This gem was extracted from [Rack::Insight](https://github.com/pboling/rack-insight).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rack-toolbar'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rack-toolbar
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
If your app is delivering a response like:
|
26
|
+
|
27
|
+
<html>
|
28
|
+
<head></head>
|
29
|
+
<body>
|
30
|
+
<h1>Important</h1>
|
31
|
+
</body>
|
32
|
+
</html>
|
33
|
+
|
34
|
+
### Simple Setup
|
35
|
+
|
36
|
+
You want to inject something into the response!
|
37
|
+
|
38
|
+
Configure your app to use Rack::Toolbar
|
39
|
+
|
40
|
+
use Rack::Toolbar, {snippet: "<div>More Important!</div>", insertion_point: "<body>", insertion_method: :after}
|
41
|
+
|
42
|
+
The `div` specified will be injected `:after` the `<body` tag.
|
43
|
+
|
44
|
+
<html>
|
45
|
+
<head></head>
|
46
|
+
<body>
|
47
|
+
<div>More Important!</div>
|
48
|
+
<h1>Important</h1>
|
49
|
+
</body>
|
50
|
+
</html>
|
51
|
+
|
52
|
+
### Easy Setup
|
53
|
+
|
54
|
+
You want to build a Middleware that will deliver a custom response based on whatever.
|
55
|
+
|
56
|
+
Create your middleware to inherit from Rack::Toolbar, and define a `render` method:
|
57
|
+
|
58
|
+
class CustomMiddleware < Rack::Toolbar
|
59
|
+
def render
|
60
|
+
"<script>javascript:void(0)</script>"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Configure your app to use your CustomMiddleware. You can still use the `:insertion_*` options, but `:snippet` will be ignored.
|
65
|
+
|
66
|
+
use CustomMiddleware, {insertion_point: "</head>", insertion_method: :before}
|
67
|
+
|
68
|
+
## Development
|
69
|
+
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/destination_errors/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Make sure to add tests!
|
81
|
+
6. Create a new Pull Request
|
82
|
+
|
83
|
+
## Contributors
|
84
|
+
|
85
|
+
See the [Network View](https://github.com/pboling/rack-toolbar/network)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/toolbar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rack/toolbar.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "rack/toolbar/version"
|
2
|
+
|
3
|
+
# Subclasses must define a render method which returns the snippet of HTML that will be inserted into the response body
|
4
|
+
# according to the INSERTION_METHOD and INSERTION_POINT. By default this is set before to the closing </body> tag.
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
class Toolbar
|
8
|
+
CONTENT_TYPE_REGEX = /text\/html|application\/xhtml\+xml/
|
9
|
+
INSERTION_METHOD = :before # alternatively :after
|
10
|
+
INSERTION_POINT = "</body>" # alternatively "<body>" to have injection at the top of the body, or whatever else floats your boat.
|
11
|
+
SNIPPET = <<EOS
|
12
|
+
<h1>Welcome to rack-toolbar</h1>
|
13
|
+
<ul>
|
14
|
+
<li>Define render in Middleware subclass of Rack::Toolbar to return an HTML snippet.</li>
|
15
|
+
<li>or</li>
|
16
|
+
<li>Pass an HTML snippet as an argument and use Rack::Toolbar directly: Rack::Toolbar.new(snippet).</li>
|
17
|
+
<li>or</li>
|
18
|
+
<li>Redefine Rack::Toolbar::SNIPPET and ignore with the warnings.</li>
|
19
|
+
</ul>
|
20
|
+
EOS
|
21
|
+
|
22
|
+
def initialize(app, options = {})
|
23
|
+
@app = app
|
24
|
+
@options = options || {}
|
25
|
+
@options[:snippet] ||= self.class::SNIPPET
|
26
|
+
@options[:insertion_point] ||= self.class::INSERTION_POINT
|
27
|
+
@options[:insertion_method] ||= self.class::INSERTION_METHOD
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
@status, @headers, @response = @app.call(env)
|
32
|
+
[@status, @headers, self]
|
33
|
+
end
|
34
|
+
|
35
|
+
def okay_to_modify?
|
36
|
+
return false unless @headers["Content-Type"] =~ self.class::CONTENT_TYPE_REGEX
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def each(&block)
|
41
|
+
if okay_to_modify?
|
42
|
+
body = @response.inject("") do |memo, part|
|
43
|
+
memo << part
|
44
|
+
memo
|
45
|
+
end
|
46
|
+
index = body.rindex(@options[:insertion_point])
|
47
|
+
if index
|
48
|
+
if @options[:insertion_method] != :before
|
49
|
+
index += @options[:insertion_point].length
|
50
|
+
end
|
51
|
+
body.insert(index, render)
|
52
|
+
@headers["Content-Length"] = body.bytesize.to_s
|
53
|
+
@response = [body]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@response.each(&block)
|
57
|
+
end
|
58
|
+
|
59
|
+
def render
|
60
|
+
@options[:snippet]
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/toolbar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-toolbar"
|
8
|
+
spec.version = Rack::Toolbar::VERSION
|
9
|
+
spec.authors = ["Peter Boling"]
|
10
|
+
spec.email = ["peter.boling@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Provides an easy way to create Rack Middleware that injects things into the response body}
|
13
|
+
spec.description = %q{Provides an easy way to create Rack Middleware that injects things into the response body. Extracted from rack-insight.}
|
14
|
+
spec.homepage = "https://github.com/pboling/rack-toolbar"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
24
|
+
spec.add_development_dependency "rack-test", "~> 0.6"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-toolbar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Boling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: Provides an easy way to create Rack Middleware that injects things into
|
84
|
+
the response body. Extracted from rack-insight.
|
85
|
+
email:
|
86
|
+
- peter.boling@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/rack/toolbar.rb
|
100
|
+
- lib/rack/toolbar/version.rb
|
101
|
+
- rack-toolbar.gemspec
|
102
|
+
homepage: https://github.com/pboling/rack-toolbar
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.6
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Provides an easy way to create Rack Middleware that injects things into the
|
125
|
+
response body
|
126
|
+
test_files: []
|