shack 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +16 -0
- data/README.md +34 -0
- data/Rakefile +23 -0
- data/certs/pjaspers.pem +19 -17
- data/lib/shack/configuration.rb +58 -0
- data/lib/shack/middleware.rb +23 -6
- data/lib/shack/stamp.rb +72 -8
- data/lib/shack/version.rb +1 -1
- data/lib/shack.rb +12 -1
- data/shack.gemspec +1 -1
- data/test/configration_test.rb +28 -0
- data/test/helper.rb +1 -0
- data/test/middleware_test.rb +61 -15
- data/test/shack_test.rb +5 -2
- data/test/stamp_test.rb +3 -3
- data.tar.gz.sig +0 -0
- metadata +26 -21
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b00d119b5b428f8faf4ad091c542be01296cdafe
|
4
|
+
data.tar.gz: 7d349a657a6c59f0e43f4c29d867bbade88fa426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7704e252d1172a064540d856d70fc84a58f145970e7a085f05e0ef5494b8ed38d6f48980cc5de71255ea1a952ced8be58304db26b464a59e3d5a8a0def481860
|
7
|
+
data.tar.gz: 39be1338d7d5b48c89ad6069119bdda6b96c08c7499c9d7e0b1243a0ef0339b299f5e4116f048545ffb325633836db722093c1545d16862d5171ed885220981e
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
## 0.0.3
|
2
|
+
|
3
|
+
- Don't show shack on print pages.
|
4
|
+
- Expose sha for easy access from app. (`Shack.sha`)
|
5
|
+
- Allow placement of sha from the config
|
6
|
+
|
7
|
+
```
|
8
|
+
Shack::Middleware.configure do |shack|
|
9
|
+
shack.horizontal = :left # or :right
|
10
|
+
shack.vertical = :top # or :bottom
|
11
|
+
end
|
12
|
+
```
|
13
|
+
- Add ability to override CSS styles (use `#sha-stamp`)
|
14
|
+
- Add quick way to fire up demo server (`rake demo`)
|
15
|
+
- Don't inject on XHR requests.
|
16
|
+
|
1
17
|
## 0.0.2
|
2
18
|
|
3
19
|
- Expose `{{short_sha}}` in custom content block. - 6180bbc
|
data/README.md
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
A `Rack` middleware that will add a unique identifier (`sha`) to the application. It will set a custom header (`X-Shack-Sha`) containing the sha and will automagically insert a small banner in the HTML.
|
6
6
|
|
7
|
+
Visit a live demo at https://canadiaweather.herokuapp.com or:
|
8
|
+
|
7
9
|
![Shack in action](http://cl.ly/image/2F1w1E0G2C3R/Screen%20Shot%202014-12-01%20at%2000.47.23.png)
|
8
10
|
|
9
11
|
```
|
@@ -47,6 +49,8 @@ end
|
|
47
49
|
|
48
50
|
And since it's Rails, it can also be done automagically if a file called `REVISION` is found in the root of your project. No initializer required. Note: by default it won't show the banner in production environments, because that just feels wrong.
|
49
51
|
|
52
|
+
It's also possible to get the sha, in the running app, `Shack.sha`. This could be helpful in passing the sha along to a service like Airbrake.
|
53
|
+
|
50
54
|
## Configuration
|
51
55
|
|
52
56
|
You can either set the sha directly:
|
@@ -69,12 +73,42 @@ end
|
|
69
73
|
|
70
74
|
There is also a `{{short_sha}}` substition available, which returns the first 8 chars of the set `sha`.
|
71
75
|
|
76
|
+
## Styling
|
77
|
+
|
78
|
+
If you define your own CSS for `#shack-stamp` and `#shack-stamp__content`, you can override the default styling. (It uses classes so your specificity should be higher)
|
79
|
+
|
80
|
+
If you just want to change the position of the sha, you can do this in a configuration block:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# Sets the sha to the top left corner
|
84
|
+
Shack::Middleware.configure do |shack|
|
85
|
+
shack.horizontal = :left # or :right
|
86
|
+
shack.vertical = :top # or :bottom
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
72
90
|
## How do I set the sha?
|
73
91
|
|
74
92
|
Either write it to a `REVISION` file on deploy (Capistrano used to this by default, now you can [add a task](https://github.com/capistrano/capistrano/pull/757), in `mina` I'm waiting on this [pull request](https://github.com/mina-deploy/mina/pull/260)), or set an `ENV` variable containing the sha.
|
75
93
|
|
94
|
+
So instead of using regular mina add this to your Gemfile:
|
95
|
+
|
96
|
+
```
|
97
|
+
gem "mina", git: "https://github.com/pjaspers/mina.git", branch: "pj-write-sha-to-revision-file"
|
98
|
+
```
|
99
|
+
|
76
100
|
Now you can set the sha in the configure block.
|
77
101
|
|
102
|
+
## OK that's fine, but I'm on Heroku
|
103
|
+
|
104
|
+
In [canadia](https://github.com/pjaspers/canadia) I made an after deploy hook that added an `ENV` variable which set the sha. The easiest way I could do this is with something like this:
|
105
|
+
|
106
|
+
```
|
107
|
+
curl -n -H "Authorization: Bearer $HEROKU_API_KEY" -X PATCH https://api.heroku.com/apps/canadiaweather/config-vars -H "Accept: application/vnd.heroku+json; version=3" -H "Content-Type: application/json" -d '{"SHA":"'"$TRAVIS_COMMIT"'"}'
|
108
|
+
```
|
109
|
+
|
110
|
+
(I used Travis to do the deploying, look [here](https://github.com/pjaspers/canadia/blob/8201454ed538ade36e133645bf1fcd1ee10e05a6/.travis.yml) for all the glorious details)
|
111
|
+
|
78
112
|
## Signed gem
|
79
113
|
|
80
114
|
`shack` is cryptographically signed. To be sure the gem you install hasn’t been tampered with:
|
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ end
|
|
7
7
|
|
8
8
|
task :default => :test
|
9
9
|
|
10
|
+
desc "Drops you in a repl with Shack already loaded"
|
10
11
|
task :console do
|
11
12
|
require 'pry'
|
12
13
|
require './lib/shack'
|
@@ -14,6 +15,28 @@ task :console do
|
|
14
15
|
Pry.start Shack
|
15
16
|
end
|
16
17
|
|
18
|
+
desc "Starts a small webapp to see shack in action"
|
19
|
+
task :demo do
|
20
|
+
require "rack"
|
21
|
+
require "./lib/shack"
|
22
|
+
app = Rack::Builder.new do
|
23
|
+
Shack::Middleware.configure do |shack|
|
24
|
+
shack.sha = "80adf8f24baee8d0feb43cdc1ce744c69a54ac99"
|
25
|
+
shack.content = "<a href='https://github.com/pjaspers/shack/commit/{{sha}}'>{{short_sha}}</a>"
|
26
|
+
shack.vertical = :top
|
27
|
+
shack.horizontal = :left
|
28
|
+
end
|
29
|
+
use Shack::Middleware
|
30
|
+
# 1.9 has a problem with `run -> (env)`, so that's why the -> is touching the (
|
31
|
+
# Yep. Annoys the hell out of me.
|
32
|
+
run ->(env) {
|
33
|
+
[200, {"Content-Type" => "text/html"}, ["<html><body>KAAAHN</body></html>"]]
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
Rack::Server.start app: app
|
38
|
+
end
|
39
|
+
|
17
40
|
task :checksum do
|
18
41
|
require 'digest/sha2'
|
19
42
|
abort_with_error "Set 'GEM' with name-0.x.x to calculate checksum" unless ENV["GEM"]
|
data/certs/pjaspers.pem
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
2
|
+
MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQ0wCwYDVQQDDARwaWV0
|
3
|
+
MRgwFgYKCZImiZPyLGQBGRYIcGphc3BlcnMxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
4
|
+
HhcNMTUwNjE1MjEzOTA5WhcNMTYwNjE0MjEzOTA5WjA+MQ0wCwYDVQQDDARwaWV0
|
5
|
+
MRgwFgYKCZImiZPyLGQBGRYIcGphc3BlcnMxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
6
|
+
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtzN0BUrwZwO6mTJH1GKId
|
7
|
+
bz24SlSY02Ji9X49ejG6F+0w/KvywAxZA0PB0tdCm8kiv8AqU1SC7dFqbX9hdVbW
|
8
|
+
UHA9+V0OFW+I2DDk3wfROTd9qtlTgreXRBXEZjQdBf8gOMJFoASgIUgW+g2b2UV9
|
9
|
+
YvNYAeYik3O/pvW0AF6fPCyuWie16MbjoOF5m8v35HPor9f9FlXAI9vEXvEUwUWz
|
10
|
+
pmHy0jp+tnMBUppbGzxEhI2lE5b+9e5qEejCpOwznLb2jEaJXnRdtpaP7UuTq/LU
|
11
|
+
ugRw36WgmuSZZuvcshjelZXqT2lwt6b7rHqoSUU3Nehf+6yM+W9srYAk5Qz2DPnx
|
12
|
+
AgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBS64fOC
|
13
|
+
k/HOJxfu4qOE8dM+79MUyzAcBgNVHREEFTATgRFwaWV0QHBqYXNwZXJzLmNvbTAc
|
14
|
+
BgNVHRIEFTATgRFwaWV0QHBqYXNwZXJzLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEA
|
15
|
+
Tz90+cjJQ+x1FR3mqxRO4zyPi4DbHBmMg+KXP3nzNUwpTG7ELGqeH3wnHKFAX8DQ
|
16
|
+
v81Cn8UQg3rrx9QCvtBeqVMdwICjhB/w1Qbe2Qf3xqIXfP/6rciqIa/OCpN06ABn
|
17
|
+
TfrQrMkOT5OkWLUTCNPadUtKR1OilDTkZ4gnZKYcGMO5KW1qZl1wuyUeXvvPYLUU
|
18
|
+
EDPjBOHBHnCZhLmX8SxZ7dMRiYuAJmz7SLuhdG91DhUSWSxtUcupi4RdrXKpUfRY
|
19
|
+
IeKuzOf0mL4ERBawVY3UOI58eUf8otccPDHB+a0QSwgUefwttEiBkB5y9r5915/b
|
20
|
+
cEwq742XFnUzr0ltFTqM+g==
|
19
21
|
-----END CERTIFICATE-----
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Shack
|
2
|
+
# Used to configure the middleware
|
3
|
+
class Configuration
|
4
|
+
# The sha that should be displayed
|
5
|
+
attr_accessor :sha
|
6
|
+
|
7
|
+
# A string (can be html) that will be displayed in the UI
|
8
|
+
attr_accessor :content
|
9
|
+
|
10
|
+
# Boolean. Show or hide the samp
|
11
|
+
attr_accessor :hide_stamp
|
12
|
+
|
13
|
+
# Sets the vertical placement.
|
14
|
+
# :top or : bottom (defaults to :bottom)
|
15
|
+
attr_accessor :vertical
|
16
|
+
|
17
|
+
# Sets the horizontal placement.
|
18
|
+
# :left or :right (default to :right)
|
19
|
+
attr_accessor :horizontal
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@vertical = :bottom
|
23
|
+
@horizontal = :right
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](key)
|
27
|
+
if respond_to? key
|
28
|
+
public_send(key)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_hash
|
33
|
+
{content: content,
|
34
|
+
vertical: vertical,
|
35
|
+
horizontal: horizontal}
|
36
|
+
end
|
37
|
+
|
38
|
+
def hide_stamp?
|
39
|
+
!!hide_stamp
|
40
|
+
end
|
41
|
+
|
42
|
+
def horizontal=(thing)
|
43
|
+
if [:left, :right].include? thing
|
44
|
+
@horizontal = thing
|
45
|
+
else
|
46
|
+
fail ArgumentError.new("horizontal needs to be :left or :right")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def vertical=(thing)
|
51
|
+
if [:top, :bottom].include? thing
|
52
|
+
@vertical = thing
|
53
|
+
else
|
54
|
+
fail ArgumentError.new("vertical needs to be :top or :bottom")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/shack/middleware.rb
CHANGED
@@ -8,6 +8,8 @@ module Shack
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
+
# Make it easy to get sha from other processes
|
12
|
+
Shack.sha = sha
|
11
13
|
status, headers, body = @app.call(env)
|
12
14
|
return [status, headers, body] unless sha
|
13
15
|
headers[HEADER_NAME] = sha
|
@@ -19,8 +21,12 @@ module Shack
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
def config
|
25
|
+
self.class.config
|
26
|
+
end
|
27
|
+
|
22
28
|
def inject_stamp(status, headers, body)
|
23
|
-
return nil if !!
|
29
|
+
return nil if !!config.hide_stamp?
|
24
30
|
return nil unless Stamp.stampable?(headers)
|
25
31
|
response = Rack::Response.new([], status, headers)
|
26
32
|
|
@@ -35,20 +41,31 @@ module Shack
|
|
35
41
|
response.finish
|
36
42
|
end
|
37
43
|
|
38
|
-
# Initialiser over
|
44
|
+
# Initialiser over config-sha.
|
39
45
|
def sha
|
40
|
-
@sha ||
|
46
|
+
@sha || config.sha
|
41
47
|
end
|
42
48
|
|
43
49
|
def stamped(body)
|
44
|
-
Stamp.new(body, sha,
|
50
|
+
Stamp.new(body, sha, config).result
|
45
51
|
end
|
46
52
|
|
47
53
|
class << self
|
48
|
-
|
54
|
+
attr_writer :configuration
|
55
|
+
|
56
|
+
def config
|
57
|
+
@configuration ||= Configuration.new
|
58
|
+
end
|
49
59
|
|
60
|
+
# Allow configuration of the Middleware
|
61
|
+
#
|
62
|
+
# Shack::Middleware.configure do |shack|
|
63
|
+
# shack.sha = "thisiasha"
|
64
|
+
# shack.hide_stamp = true
|
65
|
+
# end
|
66
|
+
#
|
50
67
|
def configure(&block)
|
51
|
-
block.call(
|
68
|
+
block.call(config)
|
52
69
|
end
|
53
70
|
end
|
54
71
|
end
|
data/lib/shack/stamp.rb
CHANGED
@@ -1,18 +1,32 @@
|
|
1
1
|
module Shack
|
2
2
|
# Takes the body and adds a stamp to it, containing the supplied content.
|
3
|
-
#
|
3
|
+
#
|
4
|
+
# Takes some additional options to set the sha in the correct position
|
5
|
+
#
|
6
|
+
# Stamp.new("html body", "123", {vertical: :left, horizontal: :right}).html
|
7
|
+
# # => HTML with the stamp set at the top left corner
|
8
|
+
#
|
4
9
|
class Stamp
|
5
10
|
# body - original body
|
6
11
|
# content - gets added to view
|
7
|
-
|
12
|
+
# options - Either a hash or a Configuration instance
|
13
|
+
def initialize(body, sha, options = {})
|
8
14
|
@body = body
|
9
15
|
@sha = sha || ""
|
10
16
|
@short_sha = @sha[0..8]
|
11
|
-
|
17
|
+
|
18
|
+
options = Configuration.new.to_hash.merge(options || {})
|
19
|
+
@custom_content = options[:content] if options[:content]
|
20
|
+
@vertical = options[:vertical]
|
21
|
+
@horizontal = options[:horizontal]
|
12
22
|
end
|
13
23
|
|
24
|
+
# Only inject html on html requests, also avoid xhr requests
|
25
|
+
#
|
26
|
+
# headers - Headers from a Rack request
|
14
27
|
def self.stampable?(headers)
|
15
|
-
!!(headers["Content-Type"] =~ %r{text/html})
|
28
|
+
!!(headers["Content-Type"] =~ %r{text/html}) &&
|
29
|
+
!!(headers["HTTP_X_REQUESTED_WITH"] != "XMLHttpRequest")
|
16
30
|
end
|
17
31
|
|
18
32
|
def result
|
@@ -30,12 +44,62 @@ module Shack
|
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
47
|
+
# Returns the CSS needed to round the correct corner
|
48
|
+
#
|
49
|
+
# `border-top-left-radius`
|
50
|
+
def rounded_corner(horizontal, vertical)
|
51
|
+
css = [] << "border"
|
52
|
+
attrs = {
|
53
|
+
top: "bottom", bottom: "top",
|
54
|
+
left: "right", right: "left" }
|
55
|
+
css << attrs.fetch(vertical)
|
56
|
+
css << attrs.fetch(horizontal)
|
57
|
+
css << "radius"
|
58
|
+
css.join("-")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the CSS needed for positioning the stamp
|
62
|
+
#
|
63
|
+
# `position: fixed; top: 0; left: 0;`
|
64
|
+
def position_css(horizontal, vertical)
|
65
|
+
attrs = {
|
66
|
+
top: "top: 0;", bottom: "bottom: 0;",
|
67
|
+
left: "left: 0;", right: "right: 0;" }
|
68
|
+
css = [] << "position: fixed;"
|
69
|
+
css << attrs.fetch(vertical)
|
70
|
+
css << attrs.fetch(horizontal)
|
71
|
+
css.join("")
|
72
|
+
end
|
73
|
+
|
33
74
|
def html
|
34
75
|
<<HTML
|
35
|
-
<
|
36
|
-
|
37
|
-
|
38
|
-
|
76
|
+
<style>
|
77
|
+
.sha-stamp {
|
78
|
+
#{position_css(@horizontal, @vertical)}
|
79
|
+
#{rounded_corner(@horizontal, @vertical)}: 5px;
|
80
|
+
height: 16px;
|
81
|
+
background: rgb(0, 0, 0) transparent; background-color: rgba(0, 0, 0, 0.2);
|
82
|
+
padding: 0 5px;
|
83
|
+
z-index: 2147483647; font-size: 12px;
|
84
|
+
}
|
85
|
+
.sha-stamp__content {
|
86
|
+
text-align: center;
|
87
|
+
color: white;
|
88
|
+
font-family: "Lucida Console", Monaco, monospace;
|
89
|
+
font-weight: normal;
|
90
|
+
font-size: 12px;
|
91
|
+
margin: 0;
|
92
|
+
}
|
93
|
+
.sha-stamp__content a {
|
94
|
+
text-decoration: none;
|
95
|
+
color: white;
|
96
|
+
}
|
97
|
+
@media print {
|
98
|
+
.sha-stamp { display: none; }
|
99
|
+
}
|
100
|
+
</style>
|
101
|
+
<div id="shack-stamp" class="sha-stamp">
|
102
|
+
<p id="shack-stamp__content" class="sha-stamp__content">#{content}</p>
|
39
103
|
</div>
|
40
104
|
HTML
|
41
105
|
end
|
data/lib/shack/version.rb
CHANGED
data/lib/shack.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
require "shack/version"
|
2
|
+
require "shack/configuration"
|
2
3
|
require "shack/middleware"
|
3
4
|
require "shack/stamp"
|
4
5
|
require "shack/railtie" if defined?(Rails)
|
5
6
|
|
6
7
|
module Shack
|
7
|
-
#
|
8
|
+
# If the Middleware is called and initialized, this sha will be set
|
9
|
+
# This could be used for easy passing to something like `Airbrake`
|
10
|
+
def self.sha
|
11
|
+
if defined? @@sha
|
12
|
+
@@sha
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.sha=(sha)
|
17
|
+
@@sha = sha
|
18
|
+
end
|
8
19
|
end
|
data/shack.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "shack"
|
8
8
|
spec.version = Shack::VERSION
|
9
9
|
spec.authors = ["pjaspers"]
|
10
|
-
spec.email = ["piet@
|
10
|
+
spec.email = ["piet@pjaspers.com"]
|
11
11
|
spec.summary = %q{Sha + Rack = Shack }
|
12
12
|
spec.description = %q{Rack middleware to expose a potential sha}
|
13
13
|
spec.homepage = ""
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "helper.rb"
|
2
|
+
|
3
|
+
describe Shack::Configuration do
|
4
|
+
|
5
|
+
it "defaults vertical to bottom" do
|
6
|
+
assert_equal :bottom, Shack::Configuration.new.vertical
|
7
|
+
end
|
8
|
+
|
9
|
+
it "defaults horizontal to right" do
|
10
|
+
assert_equal :right, Shack::Configuration.new.horizontal
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has handy hide_stamp?" do
|
14
|
+
config = Shack::Configuration.new
|
15
|
+
config.hide_stamp = nil
|
16
|
+
refute config.hide_stamp?
|
17
|
+
end
|
18
|
+
|
19
|
+
it "raises for invalid horizontal settings" do
|
20
|
+
config = Shack::Configuration.new
|
21
|
+
assert_raises(ArgumentError) { config.horizontal = "Green Mile" }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises for invalid vertical settings" do
|
25
|
+
config = Shack::Configuration.new
|
26
|
+
assert_raises(ArgumentError) { config.vertical = "Green Mile" }
|
27
|
+
end
|
28
|
+
end
|
data/test/helper.rb
CHANGED
data/test/middleware_test.rb
CHANGED
@@ -4,6 +4,7 @@ require "rack/mock"
|
|
4
4
|
describe Shack::Middleware do
|
5
5
|
before do
|
6
6
|
@app = ->(env) { [200, env, "app"] }
|
7
|
+
reset_config
|
7
8
|
end
|
8
9
|
|
9
10
|
describe "without a sha" do
|
@@ -28,13 +29,6 @@ describe Shack::Middleware do
|
|
28
29
|
@middleware = Shack::Middleware.new(@app, @sha)
|
29
30
|
end
|
30
31
|
|
31
|
-
after do
|
32
|
-
Shack::Middleware.configure do |shack|
|
33
|
-
shack.sha = nil
|
34
|
-
shack.content = nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
32
|
it "doesn't break the original app" do
|
39
33
|
status, _, _ = @middleware.call(fake_env("http://something.com"))
|
40
34
|
assert_equal status, 200
|
@@ -44,6 +38,14 @@ describe Shack::Middleware do
|
|
44
38
|
_, headers, _ = @middleware.call(fake_env("http://something.com"))
|
45
39
|
assert_equal @sha, headers[Shack::Middleware::HEADER_NAME]
|
46
40
|
end
|
41
|
+
|
42
|
+
it "exposes the sha to the top Shack module" do
|
43
|
+
if Shack.class_variable_defined? "@@sha"
|
44
|
+
Shack.remove_class_variable "@@sha"
|
45
|
+
end
|
46
|
+
_, headers, _ = @middleware.call(fake_env("http://something.com"))
|
47
|
+
assert_equal @sha, Shack.sha
|
48
|
+
end
|
47
49
|
end
|
48
50
|
|
49
51
|
describe "injecting html" do
|
@@ -53,19 +55,21 @@ describe Shack::Middleware do
|
|
53
55
|
_, _, response = middleware.call(fake_env("http://something.com"))
|
54
56
|
assert_match(/Rollo Tomassi/, response.body.first)
|
55
57
|
end
|
58
|
+
|
59
|
+
it "doesn't inject on xhr requests" do
|
60
|
+
app = ->(_) { [200, { "Content-Type" => "text/html" }, fake_page] }
|
61
|
+
middleware = Shack::Middleware.new(app, "Rollo Tomassi")
|
62
|
+
_, _, response = middleware.call(xhr_env("http://something.com"))
|
63
|
+
assert_match(/Rollo Tomassi/, response.body.first)
|
64
|
+
end
|
65
|
+
|
56
66
|
end
|
57
67
|
|
58
68
|
describe ".configure" do
|
59
|
-
after do
|
60
|
-
Shack::Middleware.configure do |shack|
|
61
|
-
shack.sha = nil
|
62
|
-
shack.content = nil
|
63
|
-
end
|
64
|
-
end
|
65
69
|
|
66
70
|
it "can set a sha" do
|
67
71
|
Shack::Middleware.configure { |s| s.sha = "O'Sullivan" }
|
68
|
-
assert_equal Shack::Middleware.sha, "O'Sullivan"
|
72
|
+
assert_equal Shack::Middleware.config.sha, "O'Sullivan"
|
69
73
|
end
|
70
74
|
|
71
75
|
it "favors the initialized sha over the configured one" do
|
@@ -80,7 +84,21 @@ describe Shack::Middleware do
|
|
80
84
|
Shack::Middleware.configure do |s|
|
81
85
|
s.content = string
|
82
86
|
end
|
83
|
-
assert_equal Shack::Middleware.content, string
|
87
|
+
assert_equal Shack::Middleware.config.content, string
|
88
|
+
end
|
89
|
+
|
90
|
+
it "can can set the horizontal orientation" do
|
91
|
+
response = response_from_configured_app do |c|
|
92
|
+
c.horizontal = :left
|
93
|
+
end
|
94
|
+
assert_match(/left: 0;/, response.body.first)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "can can set the vertical orientation" do
|
98
|
+
response = response_from_configured_app do |c|
|
99
|
+
c.vertical = :top
|
100
|
+
end
|
101
|
+
assert_match(/top: 0;/, response.body.first)
|
84
102
|
end
|
85
103
|
|
86
104
|
it "sets the stamp with the configuration" do
|
@@ -93,7 +111,18 @@ describe Shack::Middleware do
|
|
93
111
|
_, _, response = middleware.call(fake_env("http://something.com"))
|
94
112
|
assert_match(/Ronnie The Rocket - abc123/, response.body.first)
|
95
113
|
end
|
114
|
+
|
115
|
+
it "can set vertical to top" do
|
116
|
+
Shack::Middleware.configure { |s| s.vertical = :top }
|
117
|
+
assert_equal Shack::Middleware.config.vertical, :top
|
118
|
+
end
|
119
|
+
|
120
|
+
it "can set horizontal to left" do
|
121
|
+
Shack::Middleware.configure { |s| s.horizontal = :left }
|
122
|
+
assert_equal Shack::Middleware.config.horizontal, :left
|
123
|
+
end
|
96
124
|
end
|
125
|
+
|
97
126
|
def fake_page
|
98
127
|
"<html><body></body></html>"
|
99
128
|
end
|
@@ -101,4 +130,21 @@ describe Shack::Middleware do
|
|
101
130
|
def fake_env(url, options = {})
|
102
131
|
Rack::MockRequest.env_for(url, options)
|
103
132
|
end
|
133
|
+
|
134
|
+
def xhr_env(url, options = {})
|
135
|
+
options = { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"}.merge(options || {})
|
136
|
+
Rack::MockRequest.env_for(url, options)
|
137
|
+
end
|
138
|
+
|
139
|
+
def reset_config
|
140
|
+
Shack::Middleware.configuration = nil
|
141
|
+
end
|
142
|
+
|
143
|
+
def response_from_configured_app(&block)
|
144
|
+
app = ->(_) { [200, { "Content-Type" => "text/html" }, fake_page] }
|
145
|
+
Shack::Middleware.configure { |s| block.call(s) }
|
146
|
+
middleware = Shack::Middleware.new(app, "sha")
|
147
|
+
_, _, response = middleware.call(fake_env("http://something.com"))
|
148
|
+
response
|
149
|
+
end
|
104
150
|
end
|
data/test/shack_test.rb
CHANGED
data/test/stamp_test.rb
CHANGED
@@ -23,17 +23,17 @@ describe Shack::Stamp do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should use custom_content if provided" do
|
26
|
-
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", "Rollo Tomassi")
|
26
|
+
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", content: "Rollo Tomassi")
|
27
27
|
assert_match(/Rollo Tomassi/, s.result)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should use sha in custom_content if provided" do
|
31
|
-
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", "Rollo Tomassi said {{sha}}")
|
31
|
+
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", content: "Rollo Tomassi said {{sha}}")
|
32
32
|
assert_match(/Rollo Tomassi said Jack Vincennes/, s.result)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "uses short sha in custom_content if wanted" do
|
36
|
-
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", "Rollo Tomassi said {{short_sha}}")
|
36
|
+
s = Shack::Stamp.new("<html><body></body></html>", "Jack Vincennes", content: "Rollo Tomassi said {{short_sha}}")
|
37
37
|
assert_match(/Rollo Tomassi said Jack Vi/, s.result)
|
38
38
|
refute_match(/Jack Vincennes/, s.result)
|
39
39
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pjaspers
|
@@ -10,25 +10,27 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
13
|
+
MIIDbDCCAlSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQ0wCwYDVQQDDARwaWV0
|
14
|
+
MRgwFgYKCZImiZPyLGQBGRYIcGphc3BlcnMxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
15
|
+
HhcNMTUwNjE1MjEzOTA5WhcNMTYwNjE0MjEzOTA5WjA+MQ0wCwYDVQQDDARwaWV0
|
16
|
+
MRgwFgYKCZImiZPyLGQBGRYIcGphc3BlcnMxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
17
|
+
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtzN0BUrwZwO6mTJH1GKId
|
18
|
+
bz24SlSY02Ji9X49ejG6F+0w/KvywAxZA0PB0tdCm8kiv8AqU1SC7dFqbX9hdVbW
|
19
|
+
UHA9+V0OFW+I2DDk3wfROTd9qtlTgreXRBXEZjQdBf8gOMJFoASgIUgW+g2b2UV9
|
20
|
+
YvNYAeYik3O/pvW0AF6fPCyuWie16MbjoOF5m8v35HPor9f9FlXAI9vEXvEUwUWz
|
21
|
+
pmHy0jp+tnMBUppbGzxEhI2lE5b+9e5qEejCpOwznLb2jEaJXnRdtpaP7UuTq/LU
|
22
|
+
ugRw36WgmuSZZuvcshjelZXqT2lwt6b7rHqoSUU3Nehf+6yM+W9srYAk5Qz2DPnx
|
23
|
+
AgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBS64fOC
|
24
|
+
k/HOJxfu4qOE8dM+79MUyzAcBgNVHREEFTATgRFwaWV0QHBqYXNwZXJzLmNvbTAc
|
25
|
+
BgNVHRIEFTATgRFwaWV0QHBqYXNwZXJzLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEA
|
26
|
+
Tz90+cjJQ+x1FR3mqxRO4zyPi4DbHBmMg+KXP3nzNUwpTG7ELGqeH3wnHKFAX8DQ
|
27
|
+
v81Cn8UQg3rrx9QCvtBeqVMdwICjhB/w1Qbe2Qf3xqIXfP/6rciqIa/OCpN06ABn
|
28
|
+
TfrQrMkOT5OkWLUTCNPadUtKR1OilDTkZ4gnZKYcGMO5KW1qZl1wuyUeXvvPYLUU
|
29
|
+
EDPjBOHBHnCZhLmX8SxZ7dMRiYuAJmz7SLuhdG91DhUSWSxtUcupi4RdrXKpUfRY
|
30
|
+
IeKuzOf0mL4ERBawVY3UOI58eUf8otccPDHB+a0QSwgUefwttEiBkB5y9r5915/b
|
31
|
+
cEwq742XFnUzr0ltFTqM+g==
|
30
32
|
-----END CERTIFICATE-----
|
31
|
-
date: 2015-
|
33
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
32
34
|
dependencies:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: bundler
|
@@ -46,7 +48,7 @@ dependencies:
|
|
46
48
|
version: '1.7'
|
47
49
|
description: Rack middleware to expose a potential sha
|
48
50
|
email:
|
49
|
-
- piet@
|
51
|
+
- piet@pjaspers.com
|
50
52
|
executables: []
|
51
53
|
extensions: []
|
52
54
|
extra_rdoc_files: []
|
@@ -62,12 +64,14 @@ files:
|
|
62
64
|
- checksum/shack-0.0.1.sha512
|
63
65
|
- checksum/shack-0.0.2.sha512
|
64
66
|
- lib/shack.rb
|
67
|
+
- lib/shack/configuration.rb
|
65
68
|
- lib/shack/middleware.rb
|
66
69
|
- lib/shack/railtie.rb
|
67
70
|
- lib/shack/stamp.rb
|
68
71
|
- lib/shack/version.rb
|
69
72
|
- shack.gemspec
|
70
73
|
- test/benchmark.rb
|
74
|
+
- test/configration_test.rb
|
71
75
|
- test/helper.rb
|
72
76
|
- test/middleware_test.rb
|
73
77
|
- test/shack_test.rb
|
@@ -92,12 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
96
|
version: '0'
|
93
97
|
requirements: []
|
94
98
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.2
|
96
100
|
signing_key:
|
97
101
|
specification_version: 4
|
98
102
|
summary: Sha + Rack = Shack
|
99
103
|
test_files:
|
100
104
|
- test/benchmark.rb
|
105
|
+
- test/configration_test.rb
|
101
106
|
- test/helper.rb
|
102
107
|
- test/middleware_test.rb
|
103
108
|
- test/shack_test.rb
|
metadata.gz.sig
CHANGED
Binary file
|