insulate 0.0.1 → 1.0.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/Gemfile +0 -1
- data/README.md +31 -12
- data/app/views/insulate/_callback.html.erb +10 -0
- data/insulate.gemspec +2 -0
- data/lib/insulate/action_controller_filters.rb +33 -0
- data/lib/insulate/rails/engine.rb +8 -0
- data/lib/insulate/version.rb +1 -1
- data/lib/insulate.rb +7 -3
- data/vendor/assets/javascripts/insulate.js +3 -0
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d894f3bf475a3f7006194f98a406f5665ae68ba
|
4
|
+
data.tar.gz: 9857f4e9ca4471c9eb036a9ebda89e07ea164baa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30b517d55aa2f29cd2deb2839d130b3056641b9e91fc504a81f94cab40dc9063f769df97c38d01a8b2e2e00bb209266430ca2ae7a81c39c54a04103e34ca242e
|
7
|
+
data.tar.gz: 6764530b185b19424830c9120e70b60e079f54948cbda5d99a51dcd9d321153942ff065cb306b7590912d271a13c19df484933890afee0b823a0f92f6eda8bce
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,48 @@
|
|
1
1
|
# Insulate
|
2
2
|
|
3
|
-
|
3
|
+
*"Page-specific JavaScript".*
|
4
|
+
|
5
|
+
Easily partition your JavaScript code based on controller actions. Works great with Rails' asset pipeline default configuration (i.e. all JavaScript concatenated into one huge application.js file).
|
6
|
+
|
7
|
+
This gem is a fork of [Paloma](https://github.com/kbparagua/paloma), an excellent and much more comprehensive page-specific JavaScript solution. What does it do differently? Basically, I've just removed a lot of the shiny features and fluff in order to provide something that is extremely simple, compact, and *just works*. Think of it as Paloma Lite.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
8
12
|
|
9
|
-
|
13
|
+
```ruby
|
14
|
+
gem 'insulate'
|
15
|
+
```
|
10
16
|
|
11
17
|
And then execute:
|
12
18
|
|
13
|
-
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
14
22
|
|
15
|
-
|
23
|
+
Lastly, add the following line to the application.js manifest after `//= require jquery` and before `//= require_tree .`:
|
16
24
|
|
17
|
-
|
25
|
+
```
|
26
|
+
//= require insulate
|
27
|
+
```
|
18
28
|
|
19
29
|
## Usage
|
20
30
|
|
21
|
-
|
31
|
+
It's all very simple. For every controller action that you want to hook into, just add a callback function to a global `Insulate` object. The key must be a string in the format `controller#action`.
|
32
|
+
|
33
|
+
CoffeeScript example:
|
34
|
+
|
35
|
+
```coffeescript
|
36
|
+
Insulate['users#new'] = ->
|
37
|
+
alert 'Create a new user!'
|
38
|
+
```
|
39
|
+
|
40
|
+
JavaScript example:
|
22
41
|
|
23
|
-
|
42
|
+
```javascript
|
43
|
+
Insulate['users#edit'] = function() {
|
44
|
+
alert('Edit an existing user!');
|
45
|
+
};
|
46
|
+
```
|
24
47
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
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,6 +18,8 @@ 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 "jquery-rails"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Insulate
|
2
|
+
module ActionControllerFilters
|
3
|
+
def self.included base
|
4
|
+
base.module_eval do
|
5
|
+
prepend_view_path "#{Insulate.root}/app/views/"
|
6
|
+
after_filter :inject_callback_script, :if => :html_response_from_render?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def html_response_from_render?
|
13
|
+
[nil, 'text/html'].include?(response.content_type) && self.status != 302
|
14
|
+
end
|
15
|
+
|
16
|
+
def inject_callback_script
|
17
|
+
callback_script = view_context.render(
|
18
|
+
:partial => 'insulate/callback',
|
19
|
+
:locals => { :controller => controller_path, :action => action_name })
|
20
|
+
|
21
|
+
body_closing_tag_index = response_body[0].rindex('</body>')
|
22
|
+
if body_closing_tag_index.present?
|
23
|
+
# Insert callback_script just before </body> tag
|
24
|
+
response_body[0].insert body_closing_tag_index, callback_script
|
25
|
+
else
|
26
|
+
# Append callback_script in the response body
|
27
|
+
response_body[0].concat callback_script
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
::ActionController::Base.send :include, ActionControllerFilters
|
33
|
+
end
|
data/lib/insulate/version.rb
CHANGED
data/lib/insulate.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require "insulate/version"
|
2
|
-
|
3
1
|
module Insulate
|
4
|
-
|
2
|
+
def self.root
|
3
|
+
@insulate_root ||= "#{File.dirname(__FILE__)}/../"
|
4
|
+
end
|
5
5
|
end
|
6
|
+
|
7
|
+
require 'insulate/version'
|
8
|
+
require 'insulate/action_controller_filters'
|
9
|
+
require 'insulate/rails/engine'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: insulate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Horvat
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2013-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jquery-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,9 +64,13 @@ files:
|
|
50
64
|
- LICENSE.txt
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
67
|
+
- app/views/insulate/_callback.html.erb
|
53
68
|
- insulate.gemspec
|
54
69
|
- lib/insulate.rb
|
70
|
+
- lib/insulate/action_controller_filters.rb
|
71
|
+
- lib/insulate/rails/engine.rb
|
55
72
|
- lib/insulate/version.rb
|
73
|
+
- vendor/assets/javascripts/insulate.js
|
56
74
|
homepage: https://github.com/lukehorvat/insulate
|
57
75
|
licenses:
|
58
76
|
- MIT
|