unpoly-rails 0.22.1 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/design/positioning.txt +28 -0
  4. data/dist/unpoly.css +27 -20
  5. data/dist/unpoly.js +171 -59
  6. data/dist/unpoly.min.css +1 -1
  7. data/dist/unpoly.min.js +3 -3
  8. data/lib/assets/javascripts/unpoly/browser.js.coffee +12 -0
  9. data/lib/assets/javascripts/unpoly/bus.js.coffee +21 -22
  10. data/lib/assets/javascripts/unpoly/form.js.coffee +9 -5
  11. data/lib/assets/javascripts/unpoly/layout.js.coffee +3 -2
  12. data/lib/assets/javascripts/unpoly/link.js.coffee +3 -2
  13. data/lib/assets/javascripts/unpoly/navigation.js.coffee +2 -2
  14. data/lib/assets/javascripts/unpoly/proxy.js.coffee +11 -9
  15. data/lib/assets/javascripts/unpoly/tooltip.js.coffee +9 -2
  16. data/lib/assets/javascripts/unpoly/util.js.coffee +79 -11
  17. data/lib/assets/stylesheets/unpoly/tooltip.css.sass +32 -22
  18. data/lib/unpoly/rails/version.rb +1 -1
  19. data/spec_app/Gemfile.lock +1 -1
  20. data/spec_app/app/assets/images/grid.png +0 -0
  21. data/spec_app/app/assets/javascripts/integration_test.coffee +2 -0
  22. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +7 -0
  23. data/spec_app/app/assets/stylesheets/integration_test.sass +24 -0
  24. data/spec_app/app/assets/stylesheets/jasmine_specs.sass +1 -0
  25. data/spec_app/app/controllers/{test_controller.rb → binding_test_controller.rb} +1 -1
  26. data/spec_app/app/controllers/css_test_controller.rb +5 -0
  27. data/spec_app/app/controllers/form_test/basics_controller.rb +14 -0
  28. data/spec_app/app/controllers/form_test/uploads_controller.rb +15 -0
  29. data/spec_app/app/controllers/pages_controller.rb +5 -0
  30. data/spec_app/app/views/css_test/tooltip.erb +15 -0
  31. data/spec_app/app/views/form_test/basics/new.erb +33 -0
  32. data/spec_app/app/views/form_test/submission_result.erb +30 -0
  33. data/spec_app/app/views/form_test/uploads/new.erb +27 -0
  34. data/spec_app/app/views/layouts/integration_test.erb +14 -0
  35. data/spec_app/app/views/pages/start.erb +25 -0
  36. data/spec_app/config/initializers/assets.rb +4 -1
  37. data/spec_app/config/routes.rb +8 -2
  38. data/spec_app/spec/controllers/{test_controller_spec.rb → binding_test_controller_spec.rb} +1 -1
  39. data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +9 -0
  40. data/spec_app/spec/javascripts/support/jasmine.yml +2 -2
  41. data/spec_app/spec/javascripts/up/form_spec.js.coffee +21 -1
  42. data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +54 -17
  43. metadata +21 -13
  44. data/spec_app/app/assets/javascripts/application.js +0 -20
  45. data/spec_app/app/assets/stylesheets/application.css +0 -17
  46. data/spec_app/app/assets/stylesheets/blocks/card.css.sass +0 -11
  47. data/spec_app/app/assets/stylesheets/blocks/controls.css.sass +0 -7
  48. data/spec_app/app/assets/stylesheets/blocks/menu.css.sass +0 -13
  49. data/spec_app/app/assets/stylesheets/blocks/panel.css.sass +0 -8
  50. data/spec_app/app/assets/stylesheets/jasmine_specs.css +0 -5
  51. data/spec_app/app/controllers/concerns/.keep +0 -0
  52. data/spec_app/app/views/layouts/application.html.erb +0 -12
@@ -4,6 +4,6 @@ module Unpoly
4
4
  # The current version of the unpoly-rails gem.
5
5
  # This version number is also used for releases of the Unpoly
6
6
  # frontend code.
7
- VERSION = '0.22.1'
7
+ VERSION = '0.23.0'
8
8
  end
9
9
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- unpoly-rails (0.21.0)
4
+ unpoly-rails (0.22.1)
5
5
  rails (>= 3)
6
6
 
7
7
  GEM
Binary file
@@ -0,0 +1,2 @@
1
+ #= require jquery
2
+ #= require unpoly
@@ -0,0 +1,7 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require jasmine-jquery
4
+ #= require jasmine-fixture
5
+ #= require jasmine-ajax
6
+ #= require helpers/knife
7
+ #= require unpoly
@@ -0,0 +1,24 @@
1
+ //= require unpoly
2
+
3
+ body
4
+ margin: 0
5
+ background: image-url('grid.png') repeat
6
+ font-family: arial, sans-serif
7
+
8
+ .example
9
+ margin: 50px
10
+
11
+ .button
12
+ display: inline-block
13
+ height: 50px
14
+ line-height: 50px
15
+ padding-left: 25px
16
+ padding-right: 25px
17
+ background-color: #e21
18
+ color: white
19
+ text-decoration: none
20
+ &:hover
21
+ background-color: #fa1
22
+
23
+ dt
24
+ font-weight: bold
@@ -0,0 +1 @@
1
+ //= require unpoly
@@ -1,4 +1,4 @@
1
- class TestController < ActionController::Base
1
+ class BindingTestController < ActionController::Base
2
2
 
3
3
  def is_up
4
4
  render :text => up?.to_s
@@ -0,0 +1,5 @@
1
+ class CssTestController < ApplicationController
2
+
3
+ layout 'integration_test'
4
+
5
+ end
@@ -0,0 +1,14 @@
1
+ module FormTest
2
+ class BasicsController < ApplicationController
3
+
4
+ layout 'integration_test'
5
+
6
+ def new
7
+ end
8
+
9
+ def create
10
+ render 'form_test/submission_result'
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module FormTest
2
+ class UploadsController < ApplicationController
3
+
4
+ layout 'integration_test'
5
+
6
+ def new
7
+
8
+ end
9
+
10
+ def create
11
+ render 'form_test/submission_result'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ class PagesController < ApplicationController
2
+
3
+ layout 'integration_test'
4
+
5
+ end
@@ -0,0 +1,15 @@
1
+ <div class="example">
2
+ <a class="button" href="#" up-tooltip="Tooltip text" up-position="top">Top tooltip</a>
3
+ </div>
4
+
5
+ <div class="example">
6
+ <a class="button" href="#" up-tooltip="Tooltip text" up-position="bottom">Bottom tooltip</a>
7
+ </div>
8
+
9
+ <div class="example">
10
+ <a class="button" href="#" up-tooltip="Tooltip text" up-position="left">Left tooltip</a>
11
+ </div>
12
+
13
+ <div class="example">
14
+ <a class="button" href="#" up-tooltip="Tooltip text" up-position="right">Right tooltip</a>
15
+ </div>
@@ -0,0 +1,33 @@
1
+ <div class="example">
2
+
3
+ <h2>Basic form</h2>
4
+
5
+ <%= form_tag "/form_test/basic", method: :post, 'up-target' => '.result' do %>
6
+
7
+ <p>
8
+ <input type="text" name="text-param" value="text-value" />
9
+ </p>
10
+
11
+ <p>
12
+ <input type="password" name="password-param" value="password-value" />
13
+ </p>
14
+
15
+ <p>
16
+ <select name="select-param">
17
+ <option value="select-value">select-label</option>
18
+ </select>
19
+ </p>
20
+
21
+ <p>
22
+ <button type="submit">Submit</button>
23
+ </p>
24
+
25
+ <% end %>
26
+
27
+ <h3>Submission result</h3>
28
+
29
+ <div class="result">
30
+ Results of the form submission will be shown here.
31
+ </div>
32
+
33
+ </div>
@@ -0,0 +1,30 @@
1
+ <% require "base64" %>
2
+
3
+ <div class="result">
4
+
5
+ <p>
6
+ Submitted <code>params</code> were:
7
+ </p>
8
+
9
+ <dl>
10
+ <% params.each do |key, value| %>
11
+ <dt><code><%= key %></code></dt>
12
+ <dd>
13
+ <% if value.is_a?(String) %>
14
+ <pre><code><%= value %></code></pre>
15
+ <% elsif value.is_a?(ActionDispatch::Http::UploadedFile) %>
16
+ <% if value.original_filename.ends_with?('.jpg') %>
17
+ <img src="data:image/jpeg;base64,<%= Base64.encode64(value.read) %>">
18
+ <% elsif value.original_filename.ends_with?('.png') %>
19
+ <img src="data:image/png;base64,<%= Base64.encode64(value.read) %>">
20
+ <% else %>
21
+ <%= value.original_filename %> (<%= value.size %> bytes)
22
+ <% end %>
23
+ <% else %>
24
+ <%= value.inspect %>
25
+ <% end %>
26
+ </dd>
27
+ <% end %>
28
+ </dl>
29
+
30
+ </div>
@@ -0,0 +1,27 @@
1
+ <div class="example">
2
+
3
+ <h2>Form with file uploads</h2>
4
+
5
+ <%= form_tag "/form_test/upload", method: :post, multipart: true, 'up-target' => '.result' do %>
6
+
7
+ <p>
8
+ <input type="text" name="text-param" value="text-value" />
9
+ </p>
10
+
11
+ <p>
12
+ <input type="file" name="file-param" />
13
+ </p>
14
+
15
+ <p>
16
+ <button type="submit">Submit</button>
17
+ </p>
18
+
19
+ <% end %>
20
+
21
+ <h3>Submission result</h3>
22
+
23
+ <div class="result">
24
+ Results of the form submission will be shown here.
25
+ </div>
26
+
27
+ </div>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Integration test - Unpoly</title>
5
+ <%= stylesheet_link_tag 'integration_test', media: 'all' %>
6
+ <%= javascript_include_tag 'integration_test' %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <div class="page">
11
+ <%= yield %>
12
+ </div>
13
+ </body>
14
+ </html>
@@ -0,0 +1,25 @@
1
+ <div class="example">
2
+
3
+ <h1>Unpoly tests</h1>
4
+
5
+ <h2>Unit tests</h2>
6
+
7
+ <ul>
8
+ <li><%= link_to 'Jasmine specs', '/specs' %></li>
9
+ </ul>
10
+
11
+ <h2>Integration tests</h2>
12
+
13
+ <ul>
14
+ <li><%= link_to 'Tooltip', '/css_test/tooltip' %></li>
15
+ </ul>
16
+
17
+ <ul>
18
+ <li><%= link_to 'Form (basic)', '/form_test/basic/new' %></li>
19
+ </ul>
20
+
21
+ <ul>
22
+ <li><%= link_to 'Form (upload)', '/form_test/upload/new' %></li>
23
+ </ul>
24
+
25
+ </div>
@@ -8,4 +8,7 @@ Rails.application.config.assets.version = '1.0'
8
8
 
9
9
  # Precompile additional assets.
10
10
  # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
- # Rails.application.config.assets.precompile += %w( search.js )
11
+
12
+
13
+ Rails.application.config.assets.precompile += %w( application.js application.css )
14
+ Rails.application.config.assets.precompile += %w( jasmine_specs.js jasmine_specs.css integration_test.js integration_test.css )
@@ -1,8 +1,14 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
3
  mount JasmineRails::Engine => '/specs' if defined?(JasmineRails)
4
- root to: redirect('/specs')
4
+ root to: 'pages#start'
5
5
 
6
- get 'test/:action', controller: 'test'
6
+ get 'binding_test/:action', controller: 'binding_test'
7
+ get 'css_test/:action', controller: 'css_test'
8
+
9
+ namespace :form_test do
10
+ resource :basic, only: [:new, :create]
11
+ resource :upload, only: [:new, :create]
12
+ end
7
13
 
8
14
  end
@@ -1,4 +1,4 @@
1
- describe TestController do
1
+ describe BindingTestController do
2
2
 
3
3
  describe '#up?' do
4
4
 
@@ -0,0 +1,9 @@
1
+ beforeEach ->
2
+
3
+ jasmine.Ajax.addCustomParamParser
4
+ test: (xhr) ->
5
+ up.util.isFormData(xhr.params)
6
+
7
+ parse: (params) ->
8
+ # Just return it
9
+ params
@@ -17,12 +17,12 @@ css_dir: "app/assets/stylesheets"
17
17
  # list of file expressions to include as source files
18
18
  # relative path from src_dir
19
19
  src_files:
20
- - "application.{js.coffee,js,coffee}"
20
+ - "jasmine_specs.{js.coffee,js,coffee}"
21
21
 
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
+ - "jasmine_specs.{css.sass,css,sass}"
26
26
 
27
27
  # path to parent directory of spec_files
28
28
  # relative path from Rails.root
@@ -166,9 +166,29 @@ describe 'up.form', ->
166
166
  @respondWith('<div class="response">new-text</div>')
167
167
  expect(up.browser.url()).toEqual(@hrefBeforeExample)
168
168
 
169
+ describe 'in a form with file inputs', ->
170
+
171
+ beforeEach ->
172
+ @$form.affix('input[name="file-field"][type="file"]')
173
+
174
+ describeCapability 'canFormData', ->
175
+
176
+ it 'transfers the form fields via FormData', ->
177
+ up.submit(@$form)
178
+ data = @lastRequest().data()
179
+ expect(u.isFormData(data)).toBe(true)
180
+
181
+ describeFallback 'canFormData', ->
182
+
183
+ it 'falls back to a vanilla form submission', ->
184
+ form = @$form.get(0)
185
+ spyOn(form, 'submit')
186
+ up.submit(@$form)
187
+ expect(form.submit).toHaveBeenCalled()
188
+
169
189
  describeFallback 'canPushState', ->
170
190
 
171
- it 'submits the given form', ->
191
+ it 'falls back to a vanilla form submission', ->
172
192
  $form = affix('form[action="/path/to"][method="put"][up-target=".response"]')
173
193
  form = $form.get(0)
174
194
  spyOn(form, 'submit')
@@ -4,36 +4,73 @@ describe 'up.tooltip', ->
4
4
 
5
5
  describe 'up.tooltip.attach', ->
6
6
 
7
- it 'opens a tooltop above the center of the given element', ->
8
- $link = affix('span').text('button label')
9
- $link.css(
10
- position: 'absolute'
11
- left: '200px'
12
- top: '200px'
13
- width: '50px'
14
- height: '50px'
15
- )
7
+ it 'opens a tooltip with the given text', ->
8
+ $link = affix('span')
16
9
  up.tooltip.attach($link, html: 'tooltip text')
17
10
  $tooltip = $('.up-tooltip')
18
- expect($tooltip).toBeInDOM()
19
11
  expect($tooltip).toHaveText('tooltip text')
20
- tooltipBox = up.util.measure($tooltip, relative: true)
21
- linkBox = up.util.measure($link, relative: true)
22
- expect(tooltipBox.top).toBeAround(linkBox.top - tooltipBox.height, 15)
23
- expect(tooltipBox.left).toBeAround(linkBox.left + 0.5 * (linkBox.width - tooltipBox.width), 15)
24
-
25
- it 'allows HTML for the tooltip text when contents are given as .html option', ->
12
+
13
+ it 'allows HTML for the tooltip text when contents are given as { html } option', ->
26
14
  $link = affix('span')
27
15
  up.tooltip.attach($link, html: '<b>text</b>')
28
16
  $tooltip = $('.up-tooltip')
29
17
  expect($tooltip.html()).toEqual('<b>text</b>')
30
18
 
31
- it 'escapes HTML for the tooltip text when contents given as .html option', ->
19
+ it 'escapes HTML for the tooltip text when contents given as { text } option', ->
32
20
  $link = affix('span')
33
21
  up.tooltip.attach($link, text: '<b>text</b>')
34
22
  $tooltip = $('.up-tooltip')
35
23
  expect($tooltip.html()).toEqual('&lt;b&gt;text&lt;/b&gt;')
36
24
 
25
+ describe 'positioning', ->
26
+
27
+ beforeEach ->
28
+ @$link = affix('span').text('button label')
29
+ @$link.css(
30
+ position: 'absolute'
31
+ left: '200px'
32
+ top: '200px'
33
+ width: '50px'
34
+ height: '50px'
35
+ )
36
+ @linkBox = up.util.measure(@$link, relative: true)
37
+
38
+ describe 'with { position: "top" }', ->
39
+
40
+ it 'centers the tooltip above the given element', ->
41
+ up.tooltip.attach(@$link, html: 'tooltip text', position: 'top')
42
+ $tooltip = $('.up-tooltip')
43
+ tooltipBox = up.util.measure($tooltip, relative: true)
44
+ expect(tooltipBox.top).toBeAround(@linkBox.top - tooltipBox.height, 15)
45
+ expect(tooltipBox.left).toBeAround(@linkBox.left + 0.5 * (@linkBox.width - tooltipBox.width), 15)
46
+
47
+ describe 'with { position: "right" }', ->
48
+
49
+ it 'centers the tooltip at the right side of the given element', ->
50
+ up.tooltip.attach(@$link, html: 'tooltip text', position: 'right')
51
+ $tooltip = $('.up-tooltip')
52
+ tooltipBox = up.util.measure($tooltip, relative: true)
53
+ expect(tooltipBox.top).toBeAround(@linkBox.top + 0.5 * (@linkBox.height - tooltipBox.height), 15)
54
+ expect(tooltipBox.left).toBeAround(@linkBox.left + @linkBox.width, 15)
55
+
56
+ describe 'with { position: "bottom" }', ->
57
+
58
+ it 'centers the tooltip below the given element', ->
59
+ up.tooltip.attach(@$link, html: 'tooltip text', position: 'bottom')
60
+ $tooltip = $('.up-tooltip')
61
+ tooltipBox = up.util.measure($tooltip, relative: true)
62
+ expect(tooltipBox.top).toBeAround(@linkBox.top + @linkBox.height, 15)
63
+ expect(tooltipBox.left).toBeAround(@linkBox.left + 0.5 * (@linkBox.width - tooltipBox.width), 15)
64
+
65
+ describe 'with { position: "left" }', ->
66
+
67
+ it 'centers the tooltip at the left side of the given element', ->
68
+ up.tooltip.attach(@$link, html: 'tooltip text', position: 'left')
69
+ $tooltip = $('.up-tooltip')
70
+ tooltipBox = up.util.measure($tooltip, relative: true)
71
+ expect(tooltipBox.top).toBeAround(@linkBox.top + 0.5 * (@linkBox.height - tooltipBox.height), 15)
72
+ expect(tooltipBox.left).toBeAround(@linkBox.left - tooltipBox.width, 15)
73
+
37
74
  it 'closes an existing tooltip'
38
75
 
39
76
  describe 'with position option', ->