upjs-rails 0.2.1 → 0.2.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -45
  3. data/Rakefile +3 -0
  4. data/bower.json +6 -1
  5. data/dist/up.css +27 -4
  6. data/dist/up.js +197 -60
  7. data/dist/up.min.css +1 -1
  8. data/dist/up.min.js +1 -1
  9. data/lib/assets/javascripts/up/bus.js.coffee +16 -6
  10. data/lib/assets/javascripts/up/flow.js.coffee +30 -13
  11. data/lib/assets/javascripts/up/form.js.coffee +40 -10
  12. data/lib/assets/javascripts/up/history.js.coffee +8 -1
  13. data/lib/assets/javascripts/up/magic.js.coffee +17 -5
  14. data/lib/assets/javascripts/up/modal.js.coffee +16 -2
  15. data/lib/assets/javascripts/up/motion.js.coffee +14 -1
  16. data/lib/assets/javascripts/up/navigation.js.coffee +15 -6
  17. data/lib/assets/javascripts/up/popup.js.coffee +21 -3
  18. data/lib/assets/javascripts/up/tooltip.js.coffee +15 -1
  19. data/lib/assets/javascripts/up/util.js.coffee +24 -8
  20. data/lib/assets/stylesheets/up/tooltip.css.sass +30 -5
  21. data/lib/upjs/rails/current_location.rb +19 -0
  22. data/lib/upjs/rails/version.rb +1 -1
  23. data/lib/upjs-rails.rb +1 -4
  24. data/spec_app/Gemfile.lock +11 -11
  25. data/spec_app/app/assets/stylesheets/application.css +2 -0
  26. data/spec_app/app/assets/stylesheets/jasmine_specs.css +5 -0
  27. data/spec_app/app/views/pages/home.html.haml +8 -1
  28. data/spec_app/spec/javascripts/support/jasmine.yml +1 -0
  29. data/spec_app/spec/javascripts/up/bus_spec.js.coffee +12 -0
  30. data/spec_app/spec/javascripts/up/flow_spec.js.coffee +92 -68
  31. data/spec_app/spec/javascripts/up/form_spec.js.coffee +100 -0
  32. data/spec_app/spec/javascripts/up/history_spec.js.coffee +12 -0
  33. data/spec_app/spec/javascripts/up/link_spec.js.coffee +47 -0
  34. data/spec_app/spec/javascripts/up/magic_spec.js.coffee +49 -0
  35. data/spec_app/spec/javascripts/up/marker_spec.js.coffee +14 -12
  36. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +30 -0
  37. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +25 -0
  38. data/spec_app/spec/javascripts/up/navigation_spec.js.coffee +60 -24
  39. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +30 -0
  40. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +46 -0
  41. data/spec_app/spec/javascripts/up/util_spec.js.coffee +27 -25
  42. metadata +13 -3
  43. data/lib/upjs/rails/redirection.rb +0 -26
@@ -1,17 +1,42 @@
1
1
  $stratum: 30000
2
2
  $distance-from-trigger: 6px
3
+ $corner-size: 8px
4
+ $background: #666
3
5
 
4
6
  .up-tooltip
5
7
  z-index: $stratum
6
8
  position: fixed
7
- background-color: rgba(30, 30, 30, 0.8)
9
+ background-color: $background
8
10
  color: white
9
- padding: 6px 8px
10
- box-shadow: 0 0 4px rgba(0, 0, 0, 0.2)
11
+ padding: 6px 9px
12
+ //box-shadow: 0 0 4px rgba(0, 0, 0, 0.2)
11
13
 
12
14
  &[up-origin=top]
13
15
  margin-top: -$distance-from-trigger
16
+ &:after
17
+ content: ''
18
+ position: absolute
19
+ border-style: solid
20
+ border-width: $corner-size $corner-size 0
21
+ border-color: $background transparent
22
+ display: block
23
+ width: 0
24
+ z-index: 1
25
+ bottom: -$corner-size
26
+ left: 50%
27
+ margin-left: -$corner-size
14
28
 
15
29
  &[up-origin=bottom]
16
- margin-bottom: -$distance-from-trigger
17
-
30
+ margin-top: $distance-from-trigger
31
+ &:after
32
+ content: ''
33
+ position: absolute
34
+ border-style: solid
35
+ border-width: 0 $corner-size $corner-size
36
+ border-color: $background transparent
37
+ display: block
38
+ width: 0
39
+ z-index: 1
40
+ top: -$corner-size
41
+ left: 50%
42
+ margin-left: -$corner-size
@@ -0,0 +1,19 @@
1
+ module Upjs
2
+ module Rails
3
+ module CurrentLocation
4
+
5
+ def self.included(base)
6
+ base.before_filter :set_header_for_current_location
7
+ end
8
+
9
+ private
10
+
11
+ def set_header_for_current_location
12
+ headers['X-Up-Current-Location'] = request.fullpath
13
+ end
14
+
15
+ ActionController::Base.include(self)
16
+
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Upjs
2
2
  module Rails
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
data/lib/upjs-rails.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require "upjs/rails/version"
2
2
  require "upjs/rails/engine"
3
- require "upjs/rails/redirection"
3
+ require "upjs/rails/current_location"
4
4
  require "upjs/rails/request"
5
-
6
-
7
-
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- upjs-rails (0.1.0)
4
+ upjs-rails (0.2.1)
5
5
  rails (>= 3)
6
6
 
7
7
  GEM
@@ -105,32 +105,32 @@ GEM
105
105
  hpricot (~> 0.8.6)
106
106
  ruby_parser (~> 3.1.1)
107
107
  i18n (0.7.0)
108
- jasmine-core (2.1.3)
109
- jasmine-rails (0.10.6)
108
+ jasmine-core (2.2.0)
109
+ jasmine-rails (0.10.7)
110
110
  jasmine-core (>= 1.3, < 3.0)
111
- phantomjs
111
+ phantomjs (< 2.0)
112
112
  railties (>= 3.1.0)
113
113
  sprockets-rails
114
114
  jquery-rails (4.0.2)
115
115
  rails-dom-testing (~> 1.0)
116
116
  railties (>= 4.2.0)
117
117
  thor (>= 0.14, < 2.0)
118
- json (1.8.1)
118
+ json (1.8.2)
119
119
  libv8 (3.16.14.3)
120
120
  loofah (2.0.1)
121
121
  nokogiri (>= 1.5.9)
122
122
  mail (2.6.3)
123
123
  mime-types (>= 1.16, < 3)
124
124
  mime-types (2.4.3)
125
- mini_portile (0.6.1)
126
- minitest (5.5.0)
125
+ mini_portile (0.6.2)
126
+ minitest (5.5.1)
127
127
  multi_json (1.10.1)
128
128
  multi_test (0.1.1)
129
- nokogiri (1.6.5)
129
+ nokogiri (1.6.6.2)
130
130
  mini_portile (~> 0.6.0)
131
- phantomjs (1.9.7.1)
131
+ phantomjs (1.9.8.0)
132
132
  rack (1.6.0)
133
- rack-test (0.6.2)
133
+ rack-test (0.6.3)
134
134
  rack (>= 1.0)
135
135
  rails (4.2.0)
136
136
  actionmailer (= 4.2.0)
@@ -200,7 +200,7 @@ GEM
200
200
  multi_json (~> 1.0)
201
201
  rack (~> 1.0)
202
202
  tilt (~> 1.1, != 1.3.0)
203
- sprockets-rails (2.2.2)
203
+ sprockets-rails (2.2.4)
204
204
  actionpack (>= 3.0)
205
205
  activesupport (>= 3.0)
206
206
  sprockets (>= 2.8, < 4.0)
@@ -10,6 +10,8 @@
10
10
  * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
11
  * file per style scope.
12
12
  *
13
+ *= require up
13
14
  *= require_tree .
14
15
  *= require_self
15
16
  */
17
+
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require up
3
+ *= require_self
4
+ */
5
+
@@ -1,5 +1,12 @@
1
1
  .menu
2
+
3
+ %p
4
+ fullpath:
5
+ = request.fullpath
6
+
7
+ %p
8
+ url:
9
+ = request.url
2
10
 
3
11
  = link_to 'Cards panel', cards_path, class: 'menu__item'
4
- = link_to 'Modal test', modal_test_path, class: 'menu__item'
5
12
  = link_to 'Another screen', '#', class: 'menu__item'
@@ -22,6 +22,7 @@ src_files:
22
22
  # list of file expressions to include as css files
23
23
  # relative path from css_dir
24
24
  css_files:
25
+ - "application.{css.sass,css,sass}"
25
26
 
26
27
  # path to parent directory of spec_files
27
28
  # relative path from Rails.root
@@ -0,0 +1,12 @@
1
+ describe 'up.bus', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.bus.on', ->
6
+
7
+ it 'should have tests'
8
+
9
+ describe 'up.bus.emit', ->
10
+
11
+ it 'should have tests'
12
+
@@ -1,75 +1,99 @@
1
1
  describe 'up.flow', ->
2
2
 
3
- describe '.replace', ->
4
-
5
- beforeEach ->
6
- jasmine.Ajax.install()
7
-
8
- affix('.before').text('old-before')
9
- affix('.middle').text('old-middle')
10
- affix('.after').text('old-after')
11
-
12
- @promise = up.replace('.middle', '/path')
13
-
14
- jasmine.Ajax.requests.mostRecent().respondWith
15
- status: 200
16
- contentType: '/text/html'
17
- responseText:
18
- """
19
- <div class="before">new-before</div>
20
- <div class="middle">new-middle</div>
21
- <div class="after">new-after</div>
22
- """
23
-
24
- it 'replaces the given selector with the same selector from a freshly fetched page', (done) ->
25
- @promise.then ->
26
- expect($('.before')).toHaveText('old-before')
27
- expect($('.middle')).toHaveText('new-middle')
28
- expect($('.after')).toHaveText('old-after')
29
- done()
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.replace', ->
6
+
7
+ beforeEach ->
8
+ jasmine.Ajax.install()
9
+
10
+ affix('.before').text('old-before')
11
+ affix('.middle').text('old-middle')
12
+ affix('.after').text('old-after')
13
+
14
+ @respond = ->
15
+ jasmine.Ajax.requests.mostRecent().respondWith
16
+ status: 200
17
+ contentType: 'text/html'
18
+ responseText:
19
+ """
20
+ <div class="before">new-before</div>
21
+ <div class="middle">new-middle</div>
22
+ <div class="after">new-after</div>
23
+ """
30
24
 
31
- it 'should set the browser location to the given URL', (done) ->
32
- @promise.then ->
33
- expect(window.location.pathname).toBe('/path')
34
- done()
25
+ it 'replaces the given selector with the same selector from a freshly fetched page', (done) ->
26
+ @request = up.replace('.middle', '/path')
27
+ @respond()
28
+ @request.then ->
29
+ expect($('.before')).toHaveText('old-before')
30
+ expect($('.middle')).toHaveText('new-middle')
31
+ expect($('.after')).toHaveText('old-after')
32
+ done()
35
33
 
36
- it 'marks the element with the URL from which it was retrieved', (done) ->
37
- @promise.then ->
38
- expect($('.middle').attr('up-source')).toMatch(/\/path$/)
39
- done()
40
-
41
- describe '.destroy', ->
42
-
43
- it 'removes the element with the given selector', ->
44
- affix('.element')
45
- up.destroy('.element')
46
- expect($('.element')).not.toExist()
34
+ it 'should set the browser location to the given URL', (done) ->
35
+ @request = up.replace('.middle', '/path')
36
+ @respond()
37
+ @request.then ->
38
+ expect(window.location.pathname).toBe('/path')
39
+ done()
40
+
41
+ it 'marks the element with the URL from which it was retrieved', (done) ->
42
+ @request = up.replace('.middle', '/path')
43
+ @respond()
44
+ @request.then ->
45
+ expect($('.middle').attr('up-source')).toMatch(/\/path$/)
46
+ done()
47
+
48
+ it 'replaces multiple selectors separated with a comma', (done) ->
49
+ @request = up.replace('.middle, .after', '/path')
50
+ @respond()
51
+ @request.then ->
52
+ expect($('.before')).toHaveText('old-before')
53
+ expect($('.middle')).toHaveText('new-middle')
54
+ expect($('.after')).toHaveText('new-after')
55
+ done()
56
+
57
+ describe 'up.implant', ->
58
+
59
+ it 'should have tests'
47
60
 
48
- it 'calls destructors for custom elements', ->
49
- up.awaken('.element', ($element) -> destructor)
50
- destructor = jasmine.createSpy('destructor')
51
- up.ready(affix('.element'))
52
- up.destroy('.element')
53
- expect(destructor).toHaveBeenCalled()
61
+ describe 'up.destroy', ->
54
62
 
55
- describe '.reload', ->
56
-
57
- it 'reloads the given selector from the closest known source URL', (done) ->
58
- affix('.container[up-source="/source"] .element').find('.element').text('old text')
59
-
60
- up.reload('.element').then ->
61
- expect($('.element')).toHaveText('new text')
62
- done()
63
+ it 'removes the element with the given selector', ->
64
+ affix('.element')
65
+ up.destroy('.element')
66
+ expect($('.element')).not.toExist()
67
+
68
+ it 'calls destructors for custom elements', ->
69
+ up.awaken('.element', ($element) -> destructor)
70
+ destructor = jasmine.createSpy('destructor')
71
+ up.ready(affix('.element'))
72
+ up.destroy('.element')
73
+ expect(destructor).toHaveBeenCalled()
63
74
 
64
- request = jasmine.Ajax.requests.mostRecent()
65
- expect(request.url).toMatch(/\/source$/)
66
-
67
- request.respondWith
68
- status: 200
69
- contentType: '/text/html'
70
- responseText:
71
- """
72
- <div class="container">
73
- <div class="element">new text</div>
74
- </div>
75
- """
75
+ describe 'up.reload', ->
76
+
77
+ it 'reloads the given selector from the closest known source URL', (done) ->
78
+ affix('.container[up-source="/source"] .element').find('.element').text('old text')
79
+
80
+ up.reload('.element').then ->
81
+ expect($('.element')).toHaveText('new text')
82
+ done()
83
+
84
+ request = jasmine.Ajax.requests.mostRecent()
85
+ expect(request.url).toMatch(/\/source$/)
86
+
87
+ request.respondWith
88
+ status: 200
89
+ contentType: '/text/html'
90
+ responseText:
91
+ """
92
+ <div class="container">
93
+ <div class="element">new text</div>
94
+ </div>
95
+ """
96
+
97
+ describe 'up.reset', ->
98
+
99
+ it 'should have tests'
@@ -0,0 +1,100 @@
1
+ describe 'up.form', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.observe', ->
6
+
7
+ it 'should have tests'
8
+
9
+ describe 'up.submit', ->
10
+
11
+ beforeEach ->
12
+ jasmine.Ajax.install()
13
+
14
+ $form = affix('form[action="/path/to"][method="put"][up-target=".response"]')
15
+ $form.append('<input name="field1" value="value1">')
16
+ $form.append('<input name="field2" value="value2">')
17
+
18
+ affix('.response').text('old-text')
19
+
20
+ @promise = up.submit($form)
21
+
22
+ @request = jasmine.Ajax.requests.mostRecent()
23
+ expect(@request.url).toMatch /\/path\/to$/
24
+ expect(@request.method).toBe 'PUT'
25
+ expect(@request.data()).toEqual
26
+ field1: ['value1']
27
+ field2: ['value2']
28
+
29
+ it 'submits the given form and replaces the target with the response', (done) ->
30
+
31
+ @request.respondWith
32
+ status: 200
33
+ contentType: 'text/html'
34
+ responseText:
35
+ """
36
+ text-before
37
+
38
+ <div class="response">
39
+ new-text
40
+ </div>
41
+
42
+ text-after
43
+ """
44
+
45
+ @promise.then ->
46
+ expect($('.response')).toHaveText('new-text')
47
+ expect($('body')).not.toHaveText('text-before')
48
+ expect($('body')).not.toHaveText('text-after')
49
+ done()
50
+
51
+ it 'places the response into the form if the submission returns a 5xx status code', (done) ->
52
+ @request.respondWith
53
+ status: 500
54
+ contentType: 'text/html'
55
+ responseText:
56
+ """
57
+ text-before
58
+
59
+ <form>
60
+ error-messages
61
+ </form>
62
+
63
+ text-after
64
+ """
65
+
66
+ @promise.always ->
67
+ expect($('.response')).toHaveText('old-text')
68
+ expect($('form')).toHaveText('error-messages')
69
+ expect($('body')).not.toHaveText('text-before')
70
+ expect($('body')).not.toHaveText('text-after')
71
+ done()
72
+
73
+ it 'respects a X-Up-Current-Location header that the server sends in case of a redirect', (done) ->
74
+
75
+ @request.respondWith
76
+ status: 200
77
+ contentType: 'text/html'
78
+ responseHeaders: { 'X-Up-Current-Location': '/other/path' }
79
+ responseText:
80
+ """
81
+ <div class="response">
82
+ new-text
83
+ </div>
84
+ """
85
+
86
+ @promise.then ->
87
+ expect(up.browser.url()).toMatch(/\/other\/path$/)
88
+ done()
89
+
90
+ describe 'unobtrusive behavior', ->
91
+
92
+ describe 'form[up-target]', ->
93
+
94
+ it 'should have tests'
95
+
96
+ describe 'input[up-observe]', ->
97
+
98
+ it 'should have tests'
99
+
100
+
@@ -0,0 +1,12 @@
1
+ describe 'up.history', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.history.replace', ->
6
+
7
+ it 'should have tests'
8
+
9
+ describe 'up.history.push', ->
10
+
11
+ it 'should have tests'
12
+
@@ -0,0 +1,47 @@
1
+ describe 'up.link', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.follow', ->
6
+
7
+ it 'loads the given link via AJAX and replaces the response in the given target', (done) ->
8
+ jasmine.Ajax.install()
9
+
10
+ affix('.before').text('old-before')
11
+ affix('.middle').text('old-middle')
12
+ affix('.after').text('old-after')
13
+ $link = affix('a[href="/path"][up-target=".middle"]')
14
+
15
+ promise = up.follow($link)
16
+
17
+ jasmine.Ajax.requests.mostRecent().respondWith
18
+ status: 200
19
+ contentType: 'text/html'
20
+ responseText:
21
+ """
22
+ <div class="before">new-before</div>
23
+ <div class="middle">new-middle</div>
24
+ <div class="after">new-after</div>
25
+ """
26
+
27
+ promise.then ->
28
+ expect($('.before')).toHaveText('old-before')
29
+ expect($('.middle')).toHaveText('new-middle')
30
+ expect($('.after')).toHaveText('old-after')
31
+ done()
32
+
33
+ describe 'up.visit', ->
34
+
35
+ it 'should have tests'
36
+
37
+ describe 'unobtrusive behavior', ->
38
+
39
+ describe 'a[up-target]', ->
40
+
41
+ it 'should have tests'
42
+
43
+ describe '[up-follow]', ->
44
+
45
+ it 'should have tests'
46
+
47
+
@@ -0,0 +1,49 @@
1
+ describe 'up.magic', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.on', ->
6
+
7
+ it 'registers a delagating event listener to the document body', ->
8
+
9
+ affix('.container .child')
10
+ observeClass = jasmine.createSpy()
11
+ up.on 'click', '.child', (event, $element) ->
12
+ observeClass($element.attr('class'))
13
+
14
+ $('.container').click()
15
+ $('.child').click()
16
+
17
+ expect(observeClass).not.toHaveBeenCalledWith('container')
18
+ expect(observeClass).toHaveBeenCalledWith('child')
19
+
20
+ describe 'up.awaken', ->
21
+
22
+ it 'applies an event initializer whenever a matching fragment is inserted', ->
23
+
24
+ observeClass = jasmine.createSpy()
25
+ up.awaken '.child', ($element) ->
26
+ observeClass($element.attr('class'))
27
+
28
+ up.ready(affix('.container .child'))
29
+
30
+ expect(observeClass).not.toHaveBeenCalledWith('container')
31
+ expect(observeClass).toHaveBeenCalledWith('child')
32
+
33
+ it 'lets allows initializers return a destructor function, which is called when the awakened fragments gets destroyed', ->
34
+
35
+ destructor = jasmine.createSpy()
36
+ up.awaken '.child', ($element) ->
37
+ destructor
38
+
39
+ up.ready(affix('.container .child'))
40
+ expect(destructor).not.toHaveBeenCalled()
41
+
42
+ up.destroy('.container')
43
+ expect(destructor).toHaveBeenCalled()
44
+
45
+ describe 'up.ready', ->
46
+
47
+ it 'should have tests'
48
+
49
+
@@ -1,14 +1,16 @@
1
1
  describe 'up.marker', ->
2
2
 
3
- describe '[up-marker]', ->
4
-
5
- it 'hides empty containers', ->
6
- $element = affix('.element[up-marker]')
7
- up.ready($element)
8
- expect($element).not.toBeVisible()
9
-
10
- it 'does not hide empty containers', ->
11
- $element = affix('.element[up-marker]').text('content')
12
- up.ready($element)
13
- expect($element).toBeVisible()
14
-
3
+ describe 'unobtrusive behavior', ->
4
+
5
+ describe '[up-marker]', ->
6
+
7
+ it 'hides empty containers', ->
8
+ $element = affix('.element[up-marker]')
9
+ up.ready($element)
10
+ expect($element).not.toBeVisible()
11
+
12
+ it 'does not hide empty containers', ->
13
+ $element = affix('.element[up-marker]').text('content')
14
+ up.ready($element)
15
+ expect($element).toBeVisible()
16
+
@@ -0,0 +1,30 @@
1
+ describe 'up.modal', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.modal.defaults', ->
6
+
7
+ it 'should have tests'
8
+
9
+ describe 'up.modal.open', ->
10
+
11
+ it 'should have tests'
12
+
13
+ describe 'up.modal.close', ->
14
+
15
+ it 'should have tests'
16
+
17
+ describe 'up.modal.source', ->
18
+
19
+ it 'should have tests'
20
+
21
+ describe 'unobtrusive behavior', ->
22
+
23
+ describe 'a[up-modal]', ->
24
+
25
+ it 'should have tests'
26
+
27
+ describe '[up-close]', ->
28
+
29
+ it 'should have tests'
30
+
@@ -0,0 +1,25 @@
1
+ describe 'up.motion', ->
2
+
3
+ describe 'Javascript functions', ->
4
+
5
+ describe 'up.animate', ->
6
+
7
+ it 'should have tests'
8
+
9
+ describe 'up.morph', ->
10
+
11
+ it 'should have tests'
12
+
13
+ describe 'up.transition', ->
14
+
15
+ it 'should have tests'
16
+
17
+ describe 'up.animation', ->
18
+
19
+ it 'should have tests'
20
+
21
+ describe 'up.motion.none', ->
22
+
23
+ it 'should have tests'
24
+
25
+