insulate 1.0.0 → 1.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 +4 -4
- data/README.md +4 -12
- data/insulate.gemspec +1 -1
- data/lib/insulate/action_controller_filters.rb +23 -14
- data/lib/insulate/version.rb +1 -1
- data/lib/insulate.rb +0 -1
- metadata +3 -6
- data/app/views/insulate/_callback.html.erb +0 -10
- data/lib/insulate/rails/engine.rb +0 -8
- data/vendor/assets/javascripts/insulate.js +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dcc6c1468070e6d248fddd9ee4af609f4b24fa6
|
4
|
+
data.tar.gz: a2d954d791fac57f5b85d2532662d6e89800a14b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60fa7ce1d0acce026fe9782a7dc8c4f09f02c7cf2ef8e5cea38a6edfd984556323b9d196b0a5ceeb68ae0c6bd40d49f88987a2f7711b8249d7ce49344fbc3920
|
7
|
+
data.tar.gz: 7bef667899f13ae0d11dad373a48666f456a647bd0b8a37ad584378390409391d18273b38518c166a99e258282bef9ba216a0293a032988a8c8685d9016947f1
|
data/README.md
CHANGED
@@ -20,29 +20,21 @@ And then execute:
|
|
20
20
|
$ bundle install
|
21
21
|
```
|
22
22
|
|
23
|
-
Lastly, add the following line to the application.js manifest after `//= require jquery` and before `//= require_tree .`:
|
24
|
-
|
25
|
-
```
|
26
|
-
//= require insulate
|
27
|
-
```
|
28
|
-
|
29
23
|
## Usage
|
30
24
|
|
31
|
-
It's all very simple.
|
25
|
+
It's all very simple. Installing this gem automatically injects (at runtime) a global string variable, `INSULATE_PAGE_ID`, into every page served by your app. This string is always in the format `controller#action`, so if you want to conditionally execute some JavaScript code based on the current controller action, just check the value of this variable.
|
32
26
|
|
33
27
|
CoffeeScript example:
|
34
28
|
|
35
29
|
```coffeescript
|
36
|
-
|
30
|
+
if INSULATE_PAGE_ID is 'users#new'
|
37
31
|
alert 'Create a new user!'
|
38
32
|
```
|
39
33
|
|
40
34
|
JavaScript example:
|
41
35
|
|
42
36
|
```javascript
|
43
|
-
|
37
|
+
if (INSULATE_PAGE_ID === 'users#edit') {
|
44
38
|
alert('Edit an existing user!');
|
45
|
-
}
|
39
|
+
}
|
46
40
|
```
|
47
|
-
|
48
|
-
Any callback function you define this way will be executed on jQuery's `$(document).ready()` event (hence why jQuery is a dependency of this gem).
|
data/insulate.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "nokogiri"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
@@ -2,8 +2,7 @@ module Insulate
|
|
2
2
|
module ActionControllerFilters
|
3
3
|
def self.included base
|
4
4
|
base.module_eval do
|
5
|
-
|
6
|
-
after_filter :inject_callback_script, :if => :html_response_from_render?
|
5
|
+
after_filter :inject_script, :if => :html_response_from_render?
|
7
6
|
end
|
8
7
|
end
|
9
8
|
|
@@ -13,20 +12,30 @@ module Insulate
|
|
13
12
|
[nil, 'text/html'].include?(response.content_type) && self.status != 302
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
def inject_script
|
16
|
+
doc = Nokogiri::HTML response.body
|
17
|
+
head = doc.at_css 'head'
|
18
|
+
if head
|
19
|
+
# inject the following script as the first child of the <head>
|
20
|
+
script = doc.create_element 'script', script_contents(controller_path, action_name), :type => 'text/javascript'
|
21
|
+
|
22
|
+
head_children = head.children
|
23
|
+
if head_children.empty?
|
24
|
+
head.add_child script
|
25
|
+
else
|
26
|
+
head_children.before script
|
27
|
+
end
|
28
|
+
|
29
|
+
# replace the response
|
30
|
+
response.body = doc.to_html
|
28
31
|
end
|
29
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def script_contents(controller, action)
|
37
|
+
"window.INSULATE_PAGE_ID='#{controller}##{action}';"
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
41
|
::ActionController::Base.send :include, ActionControllerFilters
|
data/lib/insulate/version.rb
CHANGED
data/lib/insulate.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insulate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Horvat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
@@ -64,13 +64,10 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
|
-
- app/views/insulate/_callback.html.erb
|
68
67
|
- insulate.gemspec
|
69
68
|
- lib/insulate.rb
|
70
69
|
- lib/insulate/action_controller_filters.rb
|
71
|
-
- lib/insulate/rails/engine.rb
|
72
70
|
- lib/insulate/version.rb
|
73
|
-
- vendor/assets/javascripts/insulate.js
|
74
71
|
homepage: https://github.com/lukehorvat/insulate
|
75
72
|
licenses:
|
76
73
|
- MIT
|