jibe 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascript/jibe.js.coffee +49 -0
- data/jibe.gemspec +2 -2
- data/lib/jibe.rb +1 -1
- data/lib/jibe/railtie.rb +9 -0
- data/lib/jibe/version.rb +1 -1
- data/lib/jibe/view_helpers.rb +37 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33888929add103943b15a2826aeb54e53113b58b
|
4
|
+
data.tar.gz: 99057dfff580047555b6776d36c4d93de035434f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db9c4f3ac7c1ec8f304865ebb0c604cef73f73cc99b58f2373c9c182477b129cd71288196328c504262b9fa81a75b6b127e643e348afca2f8af5afcc47dd5961
|
7
|
+
data.tar.gz: 33bfc22a589cf5875294df37475b38972a3e94ab94d8b68b2e5cd9adcfef218e812a4b2195cd7d1e5d09efedf5056ef4c13b86b7f34db9b70cd2083702afc879
|
@@ -0,0 +1,49 @@
|
|
1
|
+
@Jibe ||= {}
|
2
|
+
|
3
|
+
Jibe.events ||= {}
|
4
|
+
|
5
|
+
Jibe.tearDown = ->
|
6
|
+
Jibe.initialized = false
|
7
|
+
Jibe.pusher.disconnect()
|
8
|
+
|
9
|
+
Jibe.initialized = false
|
10
|
+
|
11
|
+
Jibe.init = ->
|
12
|
+
unless Jibe.initialized
|
13
|
+
Jibe.initialized = true
|
14
|
+
pusher_key = $("meta[name='pusher-key']").attr("content")
|
15
|
+
Jibe.pusher = new Pusher pusher_key
|
16
|
+
channel = Jibe.pusher.subscribe "Jibe"
|
17
|
+
|
18
|
+
channel.bind "event", (data) ->
|
19
|
+
$("script[type='x-jibe'][data-resource='#{data.collection}']").each ->
|
20
|
+
scope = $(this).data("scope")
|
21
|
+
wrapper = $(this).parent()
|
22
|
+
before_hook_name = "before#{data.action_capitalized}"
|
23
|
+
after_hook_name = "after#{data.action_capitalized}"
|
24
|
+
partial = $(data.partial)
|
25
|
+
on_page = $(this).parent().find(".#{data.dom_id}, ##{data.dom_id}, .#{data.model}[data-id='#{data.id}']")
|
26
|
+
has_events = typeof Jibe.events[data.collection] != "undefined"
|
27
|
+
|
28
|
+
if has_events && typeof Jibe.events[data.collection][before_hook_name] == "function"
|
29
|
+
Jibe.events[data.collection][before_hook_name].call null, partial, data.data, scope
|
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
|
38
|
+
|
39
|
+
if has_events && typeof Jibe.events[data.collection][after_hook_name] == "function"
|
40
|
+
Jibe.events[data.collection][after_hook_name].call null, partial, data.data, scope
|
41
|
+
|
42
|
+
if data.action_name == "destroy"
|
43
|
+
on_page.remove()
|
44
|
+
|
45
|
+
$ ->
|
46
|
+
Jibe.init()
|
47
|
+
|
48
|
+
document.addEventListener "page:fetch", Jibe.tearDown
|
49
|
+
document.addEventListener "page:change", Jibe.init
|
data/jibe.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Jibe::VERSION
|
9
9
|
spec.authors = ["Dallas Read"]
|
10
10
|
spec.email = ["dallas@excitereative.ca"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Jibe keeps all your data 'n sync!}
|
12
|
+
spec.description = %q{Jibe keeps your pages live - with almost no effort!}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/jibe.rb
CHANGED
data/lib/jibe/railtie.rb
ADDED
data/lib/jibe/version.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Jibe
|
2
|
+
module ViewHelpers
|
3
|
+
def jibe *args
|
4
|
+
if args.try(:last).is_a? Hash
|
5
|
+
strategy = args.try(:last)[:strategy]
|
6
|
+
scope = args.try(:last)[:scope]
|
7
|
+
restrict_to = args.try(:last)[:restrict_to]
|
8
|
+
end
|
9
|
+
|
10
|
+
strategy = "append" if strategy.blank?
|
11
|
+
resource = "#{args.first.first.class.name}".downcase.pluralize
|
12
|
+
data = {
|
13
|
+
strategy: strategy,
|
14
|
+
resource: resource,
|
15
|
+
scope: scope
|
16
|
+
}
|
17
|
+
|
18
|
+
if restrict_to
|
19
|
+
data[:restrict_to] = []
|
20
|
+
|
21
|
+
if restrict_to.is_a? Array
|
22
|
+
restrict_to.each do |restrict|
|
23
|
+
data[:restrict_to].push "#{restrict.class.name.downcase}-#{restrict.id}"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
data[:restrict_to].push "#{restrict_to.class.name.downcase}-#{restrict_to.id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
data[:restrict_to] = data[:restrict_to].join(",")
|
30
|
+
end
|
31
|
+
|
32
|
+
html = content_tag :script, nil, type: "x-jibe", data: data
|
33
|
+
html += render *args
|
34
|
+
html.html_safe
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dallas Read
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description: Jibe keeps your pages live - with almost no effort!
|
42
42
|
email:
|
43
43
|
- dallas@excitereative.ca
|
44
44
|
executables: []
|
@@ -50,9 +50,12 @@ files:
|
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
+
- app/assets/javascript/jibe.js.coffee
|
53
54
|
- jibe.gemspec
|
54
55
|
- lib/jibe.rb
|
56
|
+
- lib/jibe/railtie.rb
|
55
57
|
- lib/jibe/version.rb
|
58
|
+
- lib/jibe/view_helpers.rb
|
56
59
|
homepage: ''
|
57
60
|
licenses:
|
58
61
|
- MIT
|
@@ -76,5 +79,5 @@ rubyforge_project:
|
|
76
79
|
rubygems_version: 2.2.2
|
77
80
|
signing_key:
|
78
81
|
specification_version: 4
|
79
|
-
summary:
|
82
|
+
summary: Jibe keeps all your data 'n sync!
|
80
83
|
test_files: []
|