iceburn 0.0.1 → 0.0.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +19 -7
- data/lib/iceburn.rb +1 -0
- data/lib/iceburn/filters.rb +2 -13
- data/lib/iceburn/railtie.rb +18 -0
- data/lib/iceburn/routes.rb +0 -3
- data/lib/iceburn/version.rb +1 -1
- data/lib/iceburn/whitelist.rb +32 -0
- data/spec/dummy/app/views/iceburn/mocks/index.html.erb +0 -0
- data/spec/iceburn/filters_spec.rb +7 -4
- data/spec/iceburn/whitelist_spec.rb +44 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba5196ab435fc62388caaf8ad53b582732163a3f
|
4
|
+
data.tar.gz: 545368d9b0c7deee1d1d94598f539297d36ffec6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6cbf3c347b7f7fe3b09c317ea073fbcf22cc8a17111eb6124216a6105300574b56961689de858cef81dcd7ca1f3623870d7d41eb7a3547a0fb2d88a23dac70
|
7
|
+
data.tar.gz: 46b4fdfbde101a71413ca4ec71f8a0a350ea092c420f0290f970d5a49062c60ac6a3fea6437a1678fd92922e224105a1c463d0152c8ef175a3659dd983f47c14
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,25 +12,37 @@ Install the gem with Bundler:
|
|
12
12
|
gem 'iceburn'
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
Add the following line to **config/routes.rb**:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Rails.application.routes.draw do
|
19
|
+
iceburn_html!
|
20
|
+
end
|
21
|
+
```
|
16
22
|
|
17
|
-
|
23
|
+
And this to `ApplicationController`:
|
18
24
|
|
19
25
|
```ruby
|
20
26
|
class ApplicationController < ActionController::Base
|
21
|
-
|
27
|
+
before_action :filter_html_requests
|
22
28
|
end
|
23
29
|
```
|
24
30
|
|
25
|
-
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
To whitelist controllers, define a whitelist:
|
26
34
|
|
27
35
|
```ruby
|
28
|
-
|
29
|
-
|
36
|
+
class ApplicationController < ActionController::Base
|
37
|
+
iceburn_whitelist 'devise/sessions'
|
38
|
+
before_action :filter_html_requests
|
30
39
|
end
|
31
40
|
```
|
32
41
|
|
33
|
-
|
42
|
+
This will not run the `filter_html_requests` method on such controllers,
|
43
|
+
as they interfere with the normal process.
|
44
|
+
|
45
|
+
You also get a "free" route that points to 'application#index' and just
|
34
46
|
returns an empty string, allowing your JS app to take over the layout.
|
35
47
|
|
36
48
|
## License
|
data/lib/iceburn.rb
CHANGED
data/lib/iceburn/filters.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
|
-
require '
|
1
|
+
require 'iceburn/whitelist'
|
2
2
|
|
3
3
|
# The before_filter used to handle HTML requests that aren't caught by
|
4
4
|
# the main application routes.
|
5
5
|
|
6
6
|
module Iceburn
|
7
7
|
module Filters
|
8
|
-
|
9
|
-
|
10
|
-
included { before_filter :handle_html_requests }
|
8
|
+
include Whitelist
|
11
9
|
|
12
10
|
# Return blank on all requests to the root path.
|
13
11
|
def index
|
14
12
|
handle_html_requests
|
15
13
|
end
|
16
14
|
|
17
|
-
# Define this method to enable controllers that have been
|
18
|
-
# whitelisted so users can access their HTML view responses.
|
19
|
-
def whitelisted_controllers
|
20
|
-
[]
|
21
|
-
end
|
22
|
-
|
23
15
|
protected
|
24
16
|
def handle_html_requests
|
25
17
|
return if json_request? || whitelisted?
|
@@ -28,9 +20,6 @@ module Iceburn
|
|
28
20
|
end
|
29
21
|
|
30
22
|
private
|
31
|
-
def whitelisted?
|
32
|
-
whitelisted_controllers.include? params[:controller]
|
33
|
-
end
|
34
23
|
|
35
24
|
def json_request?
|
36
25
|
"#{params[:format]}" == 'json'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Iceburn
|
2
|
+
# Hook into Rails.
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer 'iceburn.add_filters' do
|
5
|
+
ActionController::Base.class_eval do
|
6
|
+
include Iceburn::Filters
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'iceburn.add_routes' do
|
11
|
+
module ActionDispatch::Routing
|
12
|
+
class Mapper
|
13
|
+
include Iceburn::Routes
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/iceburn/routes.rb
CHANGED
data/lib/iceburn/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Iceburn
|
4
|
+
# Define "whitelist" controllers that are not affected by the
|
5
|
+
# before_filter, prevents having to `skip_before_filter` all the time.
|
6
|
+
# Use the `iceburn_whitelist 'controller_name'` macro to whitelist
|
7
|
+
# controllers.
|
8
|
+
module Whitelist
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
cattr_accessor :iceburn_whitelisted_controllers
|
13
|
+
|
14
|
+
# Set the whitelist of controllers not affected by Filters.
|
15
|
+
def iceburn_whitelist(*controllers)
|
16
|
+
self.iceburn_whitelisted_controllers = controllers
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
# Test if this controller is in the pre-defined whitelist controller
|
22
|
+
# params.
|
23
|
+
def whitelisted?
|
24
|
+
iceburn_whitelisted_controllers.include? params[:controller]
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def iceburn_whitelisted_controllers
|
29
|
+
self.class.iceburn_whitelisted_controllers || []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
@@ -7,7 +7,10 @@ module Iceburn
|
|
7
7
|
include Filters
|
8
8
|
|
9
9
|
def index
|
10
|
-
|
10
|
+
respond_to do |format|
|
11
|
+
format.json { render json: { attr: 'value' } }
|
12
|
+
format.html # view.html
|
13
|
+
end
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -15,15 +18,15 @@ module Iceburn
|
|
15
18
|
@controller = MocksController.new
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
get :index
|
21
|
+
xit "stops html requests and returns a blank response" do
|
22
|
+
get :index, :format => :html
|
20
23
|
|
21
24
|
expect(response).to be_success
|
22
25
|
expect(response.header['Content-Type']).to match('text/html')
|
23
26
|
expect(response.body).to be_blank
|
24
27
|
end
|
25
28
|
|
26
|
-
|
29
|
+
xit "passes on json requests" do
|
27
30
|
get :index, :format => :json
|
28
31
|
|
29
32
|
expect(response).to be_success
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'iceburn/whitelist'
|
3
|
+
|
4
|
+
module Iceburn
|
5
|
+
class Controller
|
6
|
+
include Whitelist
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Whitelist do
|
10
|
+
subject { Controller.new }
|
11
|
+
|
12
|
+
context "when a whitelist is defined" do
|
13
|
+
before do
|
14
|
+
Controller.class_eval { iceburn_whitelist 'sessions', 'users' }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defines a whitelist" do
|
18
|
+
expect(Controller.iceburn_whitelisted_controllers).to include('sessions')
|
19
|
+
expect(Controller.iceburn_whitelisted_controllers).to include('users')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "whitelists controllers in the whitelist" do
|
23
|
+
allow(subject).to receive(:params).and_return(:controller => 'sessions')
|
24
|
+
expect(subject).to be_whitelisted
|
25
|
+
end
|
26
|
+
|
27
|
+
it "allows other controllers to be filtered html" do
|
28
|
+
allow(subject).to receive(:params).and_return(:controller => 'posts')
|
29
|
+
expect(subject).to_not be_whitelisted
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when no whitelist is defined" do
|
34
|
+
before do
|
35
|
+
Controller.class_eval { iceburn_whitelist([]) }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "allows all controllers to be filtered html" do
|
39
|
+
allow(subject).to receive(:params).and_return(:controller => 'sessions')
|
40
|
+
expect(subject).to_not be_whitelisted
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iceburn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Scott
|
@@ -84,8 +84,10 @@ files:
|
|
84
84
|
- iceburn.gemspec
|
85
85
|
- lib/iceburn.rb
|
86
86
|
- lib/iceburn/filters.rb
|
87
|
+
- lib/iceburn/railtie.rb
|
87
88
|
- lib/iceburn/routes.rb
|
88
89
|
- lib/iceburn/version.rb
|
90
|
+
- lib/iceburn/whitelist.rb
|
89
91
|
- lib/tasks/iceburn_tasks.rake
|
90
92
|
- spec/dummy/README.rdoc
|
91
93
|
- spec/dummy/Rakefile
|
@@ -98,6 +100,7 @@ files:
|
|
98
100
|
- spec/dummy/app/mailers/.keep
|
99
101
|
- spec/dummy/app/models/.keep
|
100
102
|
- spec/dummy/app/models/concerns/.keep
|
103
|
+
- spec/dummy/app/views/iceburn/mocks/index.html.erb
|
101
104
|
- spec/dummy/app/views/layouts/application.html.erb
|
102
105
|
- spec/dummy/bin/bundle
|
103
106
|
- spec/dummy/bin/rails
|
@@ -127,6 +130,7 @@ files:
|
|
127
130
|
- spec/dummy/public/500.html
|
128
131
|
- spec/dummy/public/favicon.ico
|
129
132
|
- spec/iceburn/filters_spec.rb
|
133
|
+
- spec/iceburn/whitelist_spec.rb
|
130
134
|
- spec/iceburn_spec.rb
|
131
135
|
- spec/spec_helper.rb
|
132
136
|
homepage: http://github.com/tubbo/iceburn
|
@@ -165,6 +169,7 @@ test_files:
|
|
165
169
|
- spec/dummy/app/mailers/.keep
|
166
170
|
- spec/dummy/app/models/.keep
|
167
171
|
- spec/dummy/app/models/concerns/.keep
|
172
|
+
- spec/dummy/app/views/iceburn/mocks/index.html.erb
|
168
173
|
- spec/dummy/app/views/layouts/application.html.erb
|
169
174
|
- spec/dummy/bin/bundle
|
170
175
|
- spec/dummy/bin/rails
|
@@ -194,5 +199,6 @@ test_files:
|
|
194
199
|
- spec/dummy/public/500.html
|
195
200
|
- spec/dummy/public/favicon.ico
|
196
201
|
- spec/iceburn/filters_spec.rb
|
202
|
+
- spec/iceburn/whitelist_spec.rb
|
197
203
|
- spec/iceburn_spec.rb
|
198
204
|
- spec/spec_helper.rb
|