jibe 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eee9e5b52bac267618e79118f80c2bf158cc7b17
4
- data.tar.gz: b9ddc5835939b63f2e997bd196ab04f0170af330
3
+ metadata.gz: 33888929add103943b15a2826aeb54e53113b58b
4
+ data.tar.gz: 99057dfff580047555b6776d36c4d93de035434f
5
5
  SHA512:
6
- metadata.gz: f5c92d379fffdeb949af1bfc54888168d4dfd835a2602e4079f340b773cdd6ed18e0280765002fe71381df2441bee519c1385bf1df12534183509e09bd5b855e
7
- data.tar.gz: f0aac6e16133c31a8a72831dc2cd1f221ead034676c8fc08d92ec9c7ef7e8f78ae7287e4c27830f4ea9571ba0a98c00fad72ece3f2b1fc16108b556c07d1fb89
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{Keep your data jibed!}
12
- spec.description = %q{Keep your data jibed without any shenanigans!}
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
@@ -1,5 +1,5 @@
1
1
  require "jibe/version"
2
- require "jibe/railtie" if defined?(Rails::Railtie)
2
+ require "jibe/railtie" if defined? Rails
3
3
 
4
4
  module Jibe
5
5
  mattr_accessor :director
@@ -0,0 +1,9 @@
1
+ require "jibe/view_helpers"
2
+
3
+ module Jibe
4
+ class Railtie < Rails::Railtie
5
+ initializer "jibe.view_helpers" do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
data/lib/jibe/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jibe
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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: Keep your data jibed without any shenanigans!
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: Keep your data jibed!
82
+ summary: Jibe keeps all your data 'n sync!
80
83
  test_files: []