jibe 0.0.3 → 0.0.4
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 +20 -9
- data/app/assets/javascript/jibe.js.coffee +39 -16
- data/jibe.gemspec +1 -1
- data/lib/jibe.rb +2 -1
- data/lib/jibe/version.rb +1 -1
- data/lib/jibe/view_helpers.rb +24 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bdd84d7feae05580d1c69afcc28d953030ec5f8
|
4
|
+
data.tar.gz: 10308c8778b8996cfed0f8a5de829bce160016a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e8c3b2caa25986d945356b19f4b634cbf0010655b1af33b1484c537cdb8fe2f14c323ff7d1f7f46b6203d98f6ad503a1cf1ce43bb260891ccce418750c9ced2
|
7
|
+
data.tar.gz: bba8e8d2f366636f09b2bfc6038ac224af5b95121a137fb13c804000221d6bc5f3132ab2e0fcc57f396d02461dc3e79c596f7bcfd5bd0cc754c6a76755b94ff5
|
data/README.md
CHANGED
@@ -6,11 +6,21 @@ Jibe keeps simple data 'n sync with very little setup. For now, it relies on Pus
|
|
6
6
|
|
7
7
|
First, Add `gem 'jibe'` to your application's Gemfile and `bundle`.
|
8
8
|
|
9
|
-
Then, [Set up Pusher.](https://github.com/pusher/pusher-gem)
|
9
|
+
Then, [Set up Pusher.](https://github.com/pusher/pusher-gem)
|
10
|
+
|
11
|
+
You'll need to throw your pusher key into a meta tag named `pusher-key`:
|
12
|
+
|
13
|
+
```
|
14
|
+
<%= tag :meta, name: "pusher-key", content: CONFIG["pusher_key"] %>
|
15
|
+
```
|
10
16
|
|
11
17
|
Add `//= require jibe` to your `application.js` file.
|
12
18
|
|
13
|
-
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
With only 2 1-word tweaks, your views will stay in sync!
|
23
|
+
Add `jibe` to the model you'd like to stay in sync. In our case, `app/models/comment.rb`.
|
14
24
|
|
15
25
|
```
|
16
26
|
class Comment < ActiveRecord::Base
|
@@ -18,7 +28,7 @@ class Comment < ActiveRecord::Base
|
|
18
28
|
end
|
19
29
|
```
|
20
30
|
|
21
|
-
Replace a collection render call
|
31
|
+
Replace a collection render call. In our case, its in `app/views/comments/index.html.erb`.
|
22
32
|
|
23
33
|
```
|
24
34
|
<table>
|
@@ -26,7 +36,7 @@ Replace a collection render call:
|
|
26
36
|
</table>
|
27
37
|
```
|
28
38
|
|
29
|
-
with:
|
39
|
+
should be replaced with:
|
30
40
|
|
31
41
|
```
|
32
42
|
<table>
|
@@ -41,20 +51,21 @@ Now, all those `@comments` will stay in sync. At this point, its probably worth
|
|
41
51
|
```
|
42
52
|
<%=
|
43
53
|
jibe @comments,
|
44
|
-
strategy: "
|
45
|
-
scope: "completed", # useful in conjunction with JS callbacks
|
46
|
-
|
54
|
+
strategy: "append", # where should jibe place new records (prepend/append)
|
55
|
+
scope: [@post, "completed"], # checks AR objects against *_id attrs, strings are useful in conjunction with JS callbacks
|
56
|
+
silent: true # don't manipulate the DOM
|
47
57
|
%>
|
48
58
|
```
|
49
59
|
|
50
|
-
You can
|
60
|
+
You can control the way the DOM is updated by using the `beforeCreate`, `afterCreate`, `beforeUpdate`, `afterUpdate`, `beforeDestroy`, `afterDestroy` events. This is helpful for transitions.
|
51
61
|
|
52
62
|
```
|
53
63
|
Jibe.events["comments"] =
|
54
64
|
beforeCreate: (partial, data, scope) ->
|
55
65
|
# partial = the DOM node
|
56
66
|
# data = the model's attributes (override with jibe_data method in your model)
|
57
|
-
# scope =
|
67
|
+
# scope = based on the jibe tag in your view
|
68
|
+
# Jibe.inScope("completed", scope) is useful to check if the record is within the scope
|
58
69
|
|
59
70
|
```
|
60
71
|
|
@@ -8,39 +8,62 @@ Jibe.tearDown = ->
|
|
8
8
|
|
9
9
|
Jibe.initialized = false
|
10
10
|
|
11
|
+
Jibe.inScope = (test, scope) ->
|
12
|
+
!$.inArray test, scope == -1
|
13
|
+
|
14
|
+
Jibe.compareScopeWithData = (scope, data) ->
|
15
|
+
if !scope.length
|
16
|
+
in_scope = true
|
17
|
+
else
|
18
|
+
scope_passes = 0
|
19
|
+
|
20
|
+
$.each scope, (index, s) ->
|
21
|
+
s_split = s.split("=")
|
22
|
+
if s_split.length
|
23
|
+
if "#{data.data[s_split[0]]}" == "#{s_split[1]}" || "#{data.data.data[s_split[0]]}" == "#{s_split[1]}"
|
24
|
+
scope_passes += 1
|
25
|
+
else
|
26
|
+
scope_passes += 1
|
27
|
+
|
28
|
+
in_scope = scope_passes == scope.length
|
29
|
+
|
30
|
+
in_scope
|
31
|
+
|
11
32
|
Jibe.init = ->
|
12
33
|
unless Jibe.initialized
|
13
34
|
Jibe.initialized = true
|
14
35
|
pusher_key = $("meta[name='pusher-key']").attr("content")
|
15
36
|
Jibe.pusher = new Pusher pusher_key
|
16
|
-
channel = Jibe.pusher.subscribe "
|
37
|
+
channel = Jibe.pusher.subscribe "jibe"
|
17
38
|
|
18
39
|
channel.bind "event", (data) ->
|
19
40
|
$("script[type='x-jibe'][data-resource='#{data.collection}']").each ->
|
20
|
-
scope = $(this).data("scope")
|
41
|
+
scope = if typeof $(this).data("scope") == "undefined" then [] else $(this).data("scope").split(" ")
|
21
42
|
wrapper = $(this).parent()
|
22
43
|
before_hook_name = "before#{data.action_capitalized}"
|
23
44
|
after_hook_name = "after#{data.action_capitalized}"
|
24
45
|
partial = $(data.partial)
|
25
46
|
on_page = $(this).parent().find(".#{data.dom_id}, ##{data.dom_id}, .#{data.model}[data-id='#{data.id}']")
|
26
47
|
has_events = typeof Jibe.events[data.collection] != "undefined"
|
48
|
+
in_scope = Jibe.compareScopeWithData scope, data
|
27
49
|
|
28
|
-
if
|
29
|
-
Jibe.events[data.collection][before_hook_name]
|
30
|
-
|
31
|
-
if data.action_name == "create"
|
32
|
-
if $(this).data("strategy") == "prepend"
|
33
|
-
partial.prependTo wrapper
|
34
|
-
else
|
35
|
-
partial.appendTo wrapper
|
36
|
-
else if data.action_name == "update"
|
37
|
-
on_page.replaceWith partial
|
50
|
+
if in_scope
|
51
|
+
if has_events && typeof Jibe.events[data.collection][before_hook_name] == "function"
|
52
|
+
Jibe.events[data.collection][before_hook_name].call null, partial, data.data, scope
|
38
53
|
|
39
|
-
|
40
|
-
|
54
|
+
if typeof $(this).data("silent") == "undefined"
|
55
|
+
if data.action_name == "create"
|
56
|
+
if $(this).data("strategy") == "prepend"
|
57
|
+
partial.prependTo wrapper
|
58
|
+
else
|
59
|
+
partial.appendTo wrapper
|
60
|
+
else if data.action_name == "update"
|
61
|
+
on_page.replaceWith partial
|
62
|
+
else if data.action_name == "destroy"
|
63
|
+
on_page.remove()
|
41
64
|
|
42
|
-
|
43
|
-
|
65
|
+
if has_events && typeof Jibe.events[data.collection][after_hook_name] == "function"
|
66
|
+
Jibe.events[data.collection][after_hook_name].call null, partial, data.data, scope
|
44
67
|
|
45
68
|
$ ->
|
46
69
|
Jibe.init()
|
data/jibe.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["dallas@excitereative.ca"]
|
11
11
|
spec.summary = %q{Jibe keeps all your data 'n sync!}
|
12
12
|
spec.description = %q{Jibe keeps your pages live - with almost no effort!}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/dallasread/jibe"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/jibe.rb
CHANGED
@@ -31,7 +31,7 @@ module Jibe
|
|
31
31
|
unless skip_jibe
|
32
32
|
if Jibe.director == :pusher
|
33
33
|
model = self.class.name.downcase
|
34
|
-
Pusher["
|
34
|
+
Pusher["jibe"].trigger("event", {
|
35
35
|
action_name: action_name,
|
36
36
|
action_capitalized: action_name.capitalize,
|
37
37
|
id: id,
|
@@ -41,6 +41,7 @@ module Jibe
|
|
41
41
|
partial: Jibe::Render.new.to_string(self),
|
42
42
|
data: jibe_data
|
43
43
|
})
|
44
|
+
logger.info "\033[0;34mJibing #{model} #{action_name}...\033[0m"
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
data/lib/jibe/version.rb
CHANGED
data/lib/jibe/view_helpers.rb
CHANGED
@@ -4,33 +4,38 @@ module Jibe
|
|
4
4
|
if args.try(:last).is_a? Hash
|
5
5
|
strategy = args.try(:last)[:strategy]
|
6
6
|
scope = args.try(:last)[:scope]
|
7
|
+
silent = args.try(:last)[:silent]
|
7
8
|
restrict_to = args.try(:last)[:restrict_to]
|
9
|
+
partial = args.try(:partial)
|
8
10
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
data = {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
if restrict_to
|
19
|
-
data[:restrict_to] = []
|
11
|
+
|
12
|
+
resource = "#{args.first.class.to_s.split("::").first}".downcase.pluralize
|
13
|
+
|
14
|
+
data = {}
|
15
|
+
data[:resource] = resource
|
16
|
+
data[:strategy] = strategy if strategy
|
17
|
+
data[:silent] = silent if silent
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
if scope
|
20
|
+
if scope.is_a? Array
|
21
|
+
scopes = []
|
22
|
+
|
23
|
+
scope.each do |s|
|
24
|
+
s = "#{s.class.name.downcase}_id=#{s.id}" unless s.is_a? String
|
25
|
+
scopes.push s
|
24
26
|
end
|
27
|
+
|
28
|
+
data[:scope] = scopes.join(" ")
|
29
|
+
elsif scope.is_a? Object
|
30
|
+
data[:scope] = "#{scope.class.name.downcase}_id=#{scope.id}"
|
25
31
|
else
|
26
|
-
data[:
|
32
|
+
data[:scope] = scope
|
27
33
|
end
|
28
|
-
|
29
|
-
data[:restrict_to] = data[:restrict_to].join(",")
|
30
34
|
end
|
31
|
-
|
35
|
+
|
36
|
+
data[:silent] = true if args.first.nil?
|
32
37
|
html = content_tag :script, nil, type: "x-jibe", data: data
|
33
|
-
html += render *args
|
38
|
+
html += render *args unless args.first.nil?
|
34
39
|
html.html_safe
|
35
40
|
end
|
36
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jibe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dallas Read
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- lib/jibe/railtie.rb
|
57
57
|
- lib/jibe/version.rb
|
58
58
|
- lib/jibe/view_helpers.rb
|
59
|
-
homepage:
|
59
|
+
homepage: https://github.com/dallasread/jibe
|
60
60
|
licenses:
|
61
61
|
- MIT
|
62
62
|
metadata: {}
|