with_popup 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc6b4929c87d9fbf8e19da6de439b351694c44d1
4
- data.tar.gz: 4d14b07853d5f74b8d715450b0a6ef51495a992b
3
+ metadata.gz: 5464e30a0fa3ecb96e2e074958ec7d3630374f20
4
+ data.tar.gz: 0600195c384ea0d64af8e47448447923a486a74f
5
5
  SHA512:
6
- metadata.gz: 48ba97bf97b179835237567c3edfa41aeb98ceaef98bdd9f7c26dd1a2f8ea17377b04cf0510390db7a4261df7f9f9ca372c1e74e53647e86d4d4407c7478cba8
7
- data.tar.gz: 94b7085a4ad81954ae98c9f2f44769398bec368325d0e3f2550393ee6ac5549ca25f130871a996a340b1c51376244f43a50f5dc483f24b0baf4909ef77efdb13
6
+ metadata.gz: 3257778adf653385f0cbcc98cd24262a277091c34256044fc9e2573fedbc3f673ef268387385231d9ff8e65c5b527f1d6cd1125961fe0531bd947a1def3680b6
7
+ data.tar.gz: 21adf6a89f75ae80815650932f8c6c716e5d2e351835c2f345a93e3bf766155567ebf64892f8820cc6ee89a80d9f28449f8badbb30ee7061a67bd4845c142aa5
data/lib/with_popup.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "with_popup/engine"
2
- require 'with_popup/controller'
2
+ require 'with_popup/controllers'
3
3
  require 'with_popup/helpers'
4
4
 
5
5
  module WithPopup
@@ -0,0 +1,6 @@
1
+ module WithPopup
2
+ module Controllers
3
+ extend ActiveSupport::Autoload
4
+ autoload :ActionController
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module WithPopup
2
+ module Controllers
3
+ module ActionController
4
+ def close_popup
5
+ session[:_with_popup] = :close
6
+ end
7
+
8
+ def reload_popup(path)
9
+ session[:_with_popup] = path
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,7 +5,7 @@ module WithPopup
5
5
 
6
6
  initializer 'with_popup.include_modules' do
7
7
  ActiveSupport.on_load :action_controller do
8
- include WithPopup::Controller
8
+ include WithPopup::Controllers::ActionController
9
9
  end
10
10
  ActiveSupport.on_load :action_view do
11
11
  include WithPopup::Helpers::FormTagHelper
@@ -1,13 +1,17 @@
1
- module WithPopup::Helpers::FormHelper
2
- include WithPopup::Helpers::Util
1
+ module WithPopup
2
+ module Helpers
3
+ module FormHelper
4
+ include WithPopup::Helpers::Util
3
5
 
4
- def submit_with_popup(value = nil, options = {})
5
- add_with_popup_option_to!(options)
6
- submit(value, options)
7
- end
6
+ def submit_with_popup(value = nil, options = {})
7
+ add_with_popup_option_to!(options)
8
+ submit(value, options)
9
+ end
8
10
 
9
- def button_with_popup(value = nil, options = {}, &block)
10
- add_with_popup_option_to!(options)
11
- button(value, options, &block)
11
+ def button_with_popup(value = nil, options = {}, &block)
12
+ add_with_popup_option_to!(options)
13
+ button(value, options, &block)
14
+ end
15
+ end
12
16
  end
13
17
  end
@@ -1,43 +1,47 @@
1
- module WithPopup::Helpers::FormTagHelper
2
- include WithPopup::Helpers::Util
3
-
4
- def submit_with_popup_tag(value = 'Save changes', options = {})
5
- add_with_popup_option_to!(options)
6
- submit_tag(value, options)
7
- end
8
-
9
- def image_submit_with_popup_tag(source, options = {})
10
- add_with_popup_option_to!(options)
11
- image_submit_tag(source, options)
12
- end
13
-
14
- def button_with_popup_tag(content_or_options = nil, options = {}, &block)
15
- add_with_popup_option_to!(options)
16
- button_tag(content_or_options, options, &block)
17
- end
18
-
19
- def button_with_popup_to(name = nil, options = nil, html_options = {}, &block)
20
- add_with_popup_option_to!(html_options)
21
- button_to(name, options, html_options, &block)
22
- end
23
-
24
- def link_with_popup_to(name = nil, options = nil, html_options = {}, &block)
25
- add_with_popup_option_to!(html_options)
26
- link_to(name, options, html_options, &block)
27
- end
28
-
29
- def link_with_popup_to_if(condition, name, options = {}, html_options = {}, &block)
30
- add_with_popup_option_to!(html_options)
31
- link_to_if(condition, name, options, html_options, &block)
32
- end
33
-
34
- def link_with_popup_to_unless(condition, name, options = {}, html_options = {}, &block)
35
- add_with_popup_option_to!(html_options)
36
- link_to_unless(condition, name, options, html_options, &block)
37
- end
38
-
39
- def link_with_popup_to_unless_current(name, options = {}, html_options = {}, &block)
40
- add_with_popup_option_to!(html_options)
41
- link_to_unless_current(name, options, html_options, &block)
1
+ module WithPopup
2
+ module Helpers
3
+ module FormTagHelper
4
+ include WithPopup::Helpers::Util
5
+
6
+ def submit_with_popup_tag(value = 'Save changes', options = {})
7
+ add_with_popup_option_to!(options)
8
+ submit_tag(value, options)
9
+ end
10
+
11
+ def image_submit_with_popup_tag(source, options = {})
12
+ add_with_popup_option_to!(options)
13
+ image_submit_tag(source, options)
14
+ end
15
+
16
+ def button_with_popup_tag(content_or_options = nil, options = {}, &block)
17
+ add_with_popup_option_to!(options)
18
+ button_tag(content_or_options, options, &block)
19
+ end
20
+
21
+ def button_with_popup_to(name = nil, options = nil, html_options = {}, &block)
22
+ add_with_popup_option_to!(html_options)
23
+ button_to(name, options, html_options, &block)
24
+ end
25
+
26
+ def link_with_popup_to(name = nil, options = nil, html_options = {}, &block)
27
+ add_with_popup_option_to!(html_options)
28
+ link_to(name, options, html_options, &block)
29
+ end
30
+
31
+ def link_with_popup_to_if(condition, name, options = {}, html_options = {}, &block)
32
+ add_with_popup_option_to!(html_options)
33
+ link_to_if(condition, name, options, html_options, &block)
34
+ end
35
+
36
+ def link_with_popup_to_unless(condition, name, options = {}, html_options = {}, &block)
37
+ add_with_popup_option_to!(html_options)
38
+ link_to_unless(condition, name, options, html_options, &block)
39
+ end
40
+
41
+ def link_with_popup_to_unless_current(name, options = {}, html_options = {}, &block)
42
+ add_with_popup_option_to!(html_options)
43
+ link_to_unless_current(name, options, html_options, &block)
44
+ end
45
+ end
42
46
  end
43
47
  end
@@ -1,60 +1,63 @@
1
- class WithPopup::Rack
2
- def initialize(app)
3
- @app = app
4
- end
5
-
6
- def call(env)
7
- @env = env
8
- @status, @headers, @response = @app.call(env)
9
- return [@status, @headers, @response] unless need_injection?
10
- body = inject_js_to_the_response
11
- clear_param!
12
- [@status, @headers, [body]]
13
- end
14
-
15
- private
16
-
17
- def need_injection?
18
- @status == 200 && html? && popup_param
19
- end
20
-
21
- def html?
22
- @headers["Content-Type"].try(:include?, "text/html")
23
- end
24
-
25
- def popup_param
26
- session[:_with_popup]
27
- end
28
-
29
- def session
30
- @env['rack.session']
31
- end
32
-
33
- def clear_param!
34
- session.delete :_with_popup
35
- end
36
-
37
- def inject_js_to_the_response
38
- body = @response.try(:body) || @response.first
39
- js = popup_param == :close ? close_popup_js : reload_popup_js
40
- body.sub('</body>', js + '</body>')
41
- end
42
-
43
- def close_popup_js
44
- <<-JS
45
- <script type="text/javascript">
46
- var popup = open('', 'withPopup');
47
- popup && popup.close();
48
- </script>
49
- JS
50
- end
51
-
52
- def reload_popup_js
53
- <<-JS
54
- <script type="text/javascript">
55
- var popup = open('', 'withPopup');
56
- popup && (popup.location.href = '#{popup_param}');
57
- </script>
58
- JS
1
+ module WithPopup
2
+ class Rack
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ @env = env
10
+ @status, @headers, @response = @app.call(env)
11
+ return [@status, @headers, @response] unless need_injection?
12
+ body = inject_js_to_the_response
13
+ clear_param!
14
+ [@status, @headers, [body]]
15
+ end
16
+
17
+ private
18
+
19
+ def need_injection?
20
+ @status == 200 && html? && popup_param
21
+ end
22
+
23
+ def html?
24
+ @headers["Content-Type"].try(:include?, "text/html")
25
+ end
26
+
27
+ def popup_param
28
+ session[:_with_popup]
29
+ end
30
+
31
+ def session
32
+ @env['rack.session']
33
+ end
34
+
35
+ def clear_param!
36
+ session.delete :_with_popup
37
+ end
38
+
39
+ def inject_js_to_the_response
40
+ body = @response.try(:body) || @response.first
41
+ js = popup_param == :close ? close_popup_js : reload_popup_js
42
+ body.sub('</body>', js + '</body>')
43
+ end
44
+
45
+ def close_popup_js
46
+ <<-JS
47
+ <script type="text/javascript">
48
+ var popup = open('', 'withPopup');
49
+ popup && popup.close();
50
+ </script>
51
+ JS
52
+ end
53
+
54
+ def reload_popup_js
55
+ <<-JS
56
+ <script type="text/javascript">
57
+ var popup = open('', 'withPopup');
58
+ popup && (popup.location.href = '#{popup_param}');
59
+ </script>
60
+ JS
61
+ end
59
62
  end
60
63
  end
@@ -0,0 +1,6 @@
1
+ module WithPopup
2
+ module TestHelpers
3
+ extend ActiveSupport::Autoload
4
+ autoload :Controller
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module WithPopup
2
+ module TestHelpers
3
+ module Controller
4
+ def with_popup_reloading_path
5
+ session[:_with_popup] == :close ? nil : session[:_with_popup]
6
+ end
7
+
8
+ def with_popup_is_closing?
9
+ session[:_with_popup] == :close
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module WithPopup
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,35 @@
1
+ require 'rails_helper'
2
+
3
+ describe 'TestHelper', type: :controller do
4
+ describe '#with_popup_reloading_path' do
5
+ context 'when popup is going to be reloaded' do
6
+ it 'returns reloading url' do
7
+ session[:_with_popup] = '/path/to'
8
+ expect(with_popup_reloading_path).to eql '/path/to'
9
+ end
10
+ end
11
+
12
+ context 'when popup is closing' do
13
+ it 'returns nil' do
14
+ session[:_with_popup] = :close
15
+ expect(with_popup_reloading_path).to be_nil
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#with_popup_is_closing?' do
21
+ context 'when popup is going to be reloaded' do
22
+ it 'returns false' do
23
+ session[:_with_popup] = '/path/to'
24
+ expect(with_popup_is_closing?).to be_falsy
25
+ end
26
+ end
27
+
28
+ context 'when popup is closing' do
29
+ it 'returns nil' do
30
+ session[:_with_popup] = :close
31
+ expect(with_popup_is_closing?).to be_truthy
32
+ end
33
+ end
34
+ end
35
+ end
@@ -19236,3 +19236,127 @@ Processing by PostsController#create as HTML
19236
19236
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"nn3SRsO7PND08Q8Awypqokzw2l/6FTaCIRLQCnOCe/TxljjeHs22s0PUudn9sMOxXFpFPst7HDcAOKwssf6/ng==", "post"=>{"body"=>""}, "commit"=>"submit (with popup_features)", "view"=>"form_helper"}
19237
19237
  Rendered posts/form_helper.html.erb within layouts/application (0.7ms)
19238
19238
  Completed 200 OK in 26ms (Views: 16.2ms | ActiveRecord: 0.0ms)
19239
+
19240
+
19241
+ Started GET "/" for ::1 at 2016-03-24 14:03:50 +0700
19242
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
19243
+ Processing by TopController#index as HTML
19244
+ Rendered top/index.html.erb within layouts/application (3.4ms)
19245
+ Completed 200 OK in 245ms (Views: 245.1ms | ActiveRecord: 0.0ms)
19246
+
19247
+
19248
+ Started GET "/posts/new?view=form_tag_helper" for ::1 at 2016-03-24 14:03:53 +0700
19249
+ Processing by PostsController#new as HTML
19250
+ Parameters: {"view"=>"form_tag_helper"}
19251
+ Rendered posts/form_tag_helper.html.erb within layouts/application (20.8ms)
19252
+ Completed 200 OK in 53ms (Views: 39.9ms | ActiveRecord: 0.5ms)
19253
+
19254
+
19255
+ Started POST "/posts" for ::1 at 2016-03-24 14:03:55 +0700
19256
+ Processing by PostsController#create as HTML
19257
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"hXe7wmoh5HZrFZhMqC2VWhfeUTzNS5VgP8UiHsuDjo3qnFFat1duFdwwLpWWtzxJB3TOXfwlv9Ue7144Cf9K5w==", "post"=>{"body"=>""}, "commit"=>"submit_tag (with popup options)", "view"=>"form_tag_helper"}
19258
+ Rendered posts/form_tag_helper.html.erb within layouts/application (3.9ms)
19259
+ Completed 200 OK in 45ms (Views: 23.2ms | ActiveRecord: 0.0ms)
19260
+
19261
+
19262
+ Started GET "/posts/src" for ::1 at 2016-03-24 14:03:55 +0700
19263
+ Processing by PostsController#src as HTML
19264
+ Rendered posts/src.html.erb within layouts/application (0.8ms)
19265
+ Completed 200 OK in 34ms (Views: 34.1ms | ActiveRecord: 0.0ms)
19266
+
19267
+
19268
+ Started POST "/posts" for ::1 at 2016-03-24 14:03:58 +0700
19269
+ Processing by PostsController#create as HTML
19270
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"pYSzMNt36e5Gc5+1NwDdyHEo7bGIOdCm6F9aAcReC67Kb1moBgFjjfFWKWwJmnTbYYJy0LlX+hPJdSYnBiLPxA==", "post"=>{"body"=>"e"}, "commit"=>"submit_tag (with popup options)", "view"=>"form_tag_helper"}
19271
+ Redirected to http://localhost:3000/posts/done
19272
+ Completed 302 Found in 10ms (ActiveRecord: 0.0ms)
19273
+
19274
+
19275
+ Started GET "/posts/src" for ::1 at 2016-03-24 14:03:58 +0700
19276
+ Processing by PostsController#src as HTML
19277
+ Rendered posts/src.html.erb within layouts/application (0.1ms)
19278
+ Completed 200 OK in 24ms (Views: 24.2ms | ActiveRecord: 0.0ms)
19279
+
19280
+
19281
+ Started GET "/posts/done" for ::1 at 2016-03-24 14:03:58 +0700
19282
+ Processing by PostsController#done as HTML
19283
+ Rendered posts/done.html.erb within layouts/application (1.1ms)
19284
+ Completed 200 OK in 38ms (Views: 37.7ms | ActiveRecord: 0.0ms)
19285
+
19286
+
19287
+ Started GET "/posts/reload" for ::1 at 2016-03-24 14:03:58 +0700
19288
+ Processing by PostsController#reload as HTML
19289
+ Rendered posts/reload.html.erb within layouts/application (0.5ms)
19290
+ Completed 200 OK in 22ms (Views: 21.8ms | ActiveRecord: 0.0ms)
19291
+
19292
+
19293
+ Started GET "/monthly_sales" for 127.0.0.1 at 2016-03-24 14:05:20 +0700
19294
+
19295
+ ActionController::RoutingError (No route matches [GET] "/monthly_sales"):
19296
+ actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
19297
+ actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
19298
+ railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
19299
+ railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
19300
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
19301
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
19302
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
19303
+ railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
19304
+ quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
19305
+ actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
19306
+ rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
19307
+ rack (1.6.4) lib/rack/runtime.rb:18:in `call'
19308
+ activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
19309
+ rack (1.6.4) lib/rack/lock.rb:17:in `call'
19310
+ actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
19311
+ rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
19312
+ railties (4.2.6) lib/rails/engine.rb:518:in `call'
19313
+ railties (4.2.6) lib/rails/application.rb:165:in `call'
19314
+ rack (1.6.4) lib/rack/lock.rb:17:in `call'
19315
+ rack (1.6.4) lib/rack/content_length.rb:15:in `call'
19316
+ rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
19317
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
19318
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
19319
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
19320
+
19321
+
19322
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms)
19323
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (1.0ms)
19324
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (3.8ms)
19325
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.4ms)
19326
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (109.9ms)
19327
+
19328
+
19329
+ Started GET "/monthly_sales" for 127.0.0.1 at 2016-03-24 14:05:24 +0700
19330
+
19331
+ ActionController::RoutingError (No route matches [GET] "/monthly_sales"):
19332
+ actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
19333
+ actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
19334
+ railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
19335
+ railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
19336
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
19337
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
19338
+ activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
19339
+ railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
19340
+ quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
19341
+ actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
19342
+ rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
19343
+ rack (1.6.4) lib/rack/runtime.rb:18:in `call'
19344
+ activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
19345
+ rack (1.6.4) lib/rack/lock.rb:17:in `call'
19346
+ actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
19347
+ rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
19348
+ railties (4.2.6) lib/rails/engine.rb:518:in `call'
19349
+ railties (4.2.6) lib/rails/application.rb:165:in `call'
19350
+ rack (1.6.4) lib/rack/lock.rb:17:in `call'
19351
+ rack (1.6.4) lib/rack/content_length.rb:15:in `call'
19352
+ rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
19353
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
19354
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
19355
+ /Users/madmax/.rbenv/versions/2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
19356
+
19357
+
19358
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.4ms)
19359
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_route.html.erb (1.1ms)
19360
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.4ms)
19361
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.4ms)
19362
+ Rendered /Users/madmax/Programs/itmammoth/with_popup/vendor/bundle/ruby/2.3.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (73.1ms)