pluggable_js 2.0.1 → 2.0.4

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: 1c053d4795af1596c881bb47fea30ce23856cbf7
4
- data.tar.gz: ff0bbd8d51e1929d48410a0651e68ed99e1123d3
3
+ metadata.gz: 2cc20f0627f664082c987b6d5e70bd6571aae063
4
+ data.tar.gz: 8171d7cf58b584808136c99d206acea4d7baa565
5
5
  SHA512:
6
- metadata.gz: 0ec2f03e85a3a2e775608410813752b80f139434d1fe934908f620f1cbf1b07911b09d70c3a9e1088b096fa965194c6cdd293b50d1d2299db5b6152a6e430834
7
- data.tar.gz: 22fa3a8fabe1c300ac37b5c0c85b259e35b43ca2efc7008c2e5eb4c6e5bc279cf85084b0dea157bc1b7864fd85518dc6e9b470aeda1a011323a19c7396c215fc
6
+ metadata.gz: 5cf93f00b0f6ca8cd7a7bde116202ee1a836196eaa2d3ad9263932f3a0824bf2c46c4319b6cd3d9d4ba1d0932392c99918ce8a66ffc957f711f240745fe8d123
7
+ data.tar.gz: d29e8a146abf41b85889b16a8761ce6043bd15bbc17ef45d388fefdad89a3a6b5b96604a675e4f0e0179b017f6e2c8c138d8db66f4a5903d709aeaad86b020bb
@@ -53,3 +53,11 @@
53
53
  ## v2.0.1
54
54
 
55
55
  * refactored helpers, improved readme
56
+
57
+ ## v2.0.3
58
+
59
+ * turbolinks related bugfix
60
+
61
+ ## v2.0.4
62
+
63
+ * nested resources related bugfix
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
- # PluggableJs
1
+ # PluggableJs
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pluggable_js.svg)](http://badge.fury.io/rb/pluggable_js)
2
4
 
3
5
  This gem provides simple functionality of loading page specific javascript and allows to pass data from a controller (for Rails 3 and Rails 4 with asset pipeline enabled). Keep desired js code in controller related files as action based functions. They will be triggered only when matching controller and action parameters and when DOM is ready.
4
6
 
5
7
  ## Installation
6
8
 
7
- 1. Add `gem 'pluggable_js', '~> 2.0.0'` to Gemfile and run `bundle` command to install it
9
+ 1. Add `gem 'pluggable_js', '~> 2.0.4'` to Gemfile and run `bundle` command to install it
8
10
  2. Add `<%= javascript_pluggable_tag %>` helper to application layout file after `<%= javascript_include_tag 'application' %>` line (if you use turbolinks paste it above the closing `</body>` tag)
9
11
 
10
12
  ## Usage
@@ -1,13 +1,13 @@
1
1
  When(/^I go to posts 'index'$/) do
2
- visit posts_path
2
+ visit pluggable_js_posts_path
3
3
  end
4
4
 
5
5
  When(/^I go to posts 'search'$/) do
6
- visit search_posts_path
6
+ visit search_pluggable_js_posts_path
7
7
  end
8
8
 
9
9
  When(/^I go to new post$/) do
10
- visit new_post_path
10
+ visit new_pluggable_js_post_path
11
11
  end
12
12
 
13
13
  Then(/^I should see '(.*?)'$/) do |text|
@@ -5,17 +5,20 @@ module PluggableJs
5
5
  def javascript_pluggable_tag
6
6
  controller = params[:controller]
7
7
  action = define_pair_action
8
+ sc_var_name = "__should_call_#{controller.gsub(/\//, '__')}_#{action}"
8
9
 
9
10
  ''.tap do |content|
10
11
  content << (javascript_tag "
11
12
  (function() {
12
13
  var function_name = '#{controller}##{action}';
13
- if (typeof(this[function_name]) == 'function') {
14
+ var #{sc_var_name} = true;
15
+ if (typeof(this[function_name]) == 'function' && #{sc_var_name}) {
14
16
  $(function() {
17
+ #{sc_var_name} = false;
15
18
  return window[function_name](#{@pluggable_js_data});
16
19
  });
17
20
  }
18
- }).call(this);"
21
+ }).call(window);"
19
22
  )
20
23
 
21
24
  if File.exist?(Rails.root + "app/assets/javascripts/pluggable/#{controller}/#{action}.js.coffee")
@@ -1,3 +1,3 @@
1
1
  module PluggableJs
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -1,4 +1,4 @@
1
- @['posts#index'] = (data) ->
1
+ @['pluggable_js/posts#index'] = (data) ->
2
2
  $('.protoss-quotes').append("<p>#{data.zealot_quote}</p>")
3
3
  $('.protoss-quotes').append('<p>You have not enough minerals.</p>' if data.minerals_size < 1000)
4
4
  $('.protoss-quotes').append('<p>Base is under attack.</p>') if data.base_is_under_attack
@@ -9,5 +9,5 @@
9
9
  for key, value of unit
10
10
  $('.protoss-quotes').append("<p>#{key}: #{value}</p>")
11
11
 
12
- @['posts#new'] = (data) ->
12
+ @['pluggable_js/posts#new'] = (data) ->
13
13
  $('.terran-quotes').append("<p>#{data.marine_quote}</p>")
@@ -0,0 +1,30 @@
1
+ module PluggableJs
2
+ class PostsController < ApplicationController
3
+ before_action :set_pluggable_js, only: [:index, :search]
4
+
5
+ def index
6
+ end
7
+
8
+ def search
9
+ render :index
10
+ end
11
+
12
+ def new
13
+ pjs(marine_quote: 'You wanna piece of me, boy?')
14
+ end
15
+
16
+ private
17
+
18
+ def set_pluggable_js
19
+ pluggable_js(
20
+ zealot_quote: 'My life for aiur.',
21
+ minerals_size: 999,
22
+ base_is_under_attack: true,
23
+ alert: ['Nuclear', 'launch', 'detected.'],
24
+ ground_units_quotes: { 'Dragoon' => 'Make use of me.', 'High Templar' => 'It shall be done.', 'Archon' => 'We burn...' },
25
+ air_units_quotes: [{'Scout' => 'Awaiting command.'}, {'Arbiter' => 'We feel your presence.'}, {'Carrier' => 'Affirmative.'}]
26
+ )
27
+ end
28
+
29
+ end
30
+ end
@@ -1,8 +1,12 @@
1
1
  Dummy::Application.routes.draw do
2
- root 'posts#index'
3
- resources :posts, only: [:index, :new] do
4
- collection do
5
- get :search
2
+ root 'pluggable_js/posts#index'
3
+
4
+ namespace :pluggable_js do
5
+ resources :posts, only: [:index, :new] do
6
+ collection do
7
+ get :search
8
+ end
6
9
  end
7
- end
10
+ end
11
+
8
12
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluggable_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Peresleguine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jquery-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: capybara-webkit
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Page-specific javascript for Rails applications with the ability of passing
@@ -116,7 +116,7 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - .gitignore
119
+ - ".gitignore"
120
120
  - CHANGELOG.md
121
121
  - Gemfile
122
122
  - LICENSE
@@ -138,19 +138,19 @@ files:
138
138
  - test/dummy/Rakefile
139
139
  - test/dummy/app/assets/images/.keep
140
140
  - test/dummy/app/assets/javascripts/application.js
141
- - test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee
141
+ - test/dummy/app/assets/javascripts/pluggable/pluggable_js/posts/new.js.coffee
142
142
  - test/dummy/app/assets/javascripts/posts.js.coffee
143
143
  - test/dummy/app/assets/stylesheets/application.css
144
144
  - test/dummy/app/controllers/application_controller.rb
145
145
  - test/dummy/app/controllers/concerns/.keep
146
- - test/dummy/app/controllers/posts_controller.rb
146
+ - test/dummy/app/controllers/pluggable_js/posts_controller.rb
147
147
  - test/dummy/app/helpers/application_helper.rb
148
148
  - test/dummy/app/mailers/.keep
149
149
  - test/dummy/app/models/.keep
150
150
  - test/dummy/app/models/concerns/.keep
151
151
  - test/dummy/app/views/layouts/application.html.erb
152
- - test/dummy/app/views/posts/index.html.erb
153
- - test/dummy/app/views/posts/new.html.erb
152
+ - test/dummy/app/views/pluggable_js/posts/index.html.erb
153
+ - test/dummy/app/views/pluggable_js/posts/new.html.erb
154
154
  - test/dummy/bin/bundle
155
155
  - test/dummy/bin/rails
156
156
  - test/dummy/bin/rake
@@ -186,17 +186,17 @@ require_paths:
186
186
  - lib
187
187
  required_ruby_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - '>='
189
+ - - ">="
190
190
  - !ruby/object:Gem::Version
191
191
  version: '0'
192
192
  required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  requirements:
194
- - - '>='
194
+ - - ">="
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project:
199
- rubygems_version: 2.1.11
199
+ rubygems_version: 2.2.2
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Page-specific javascript for Rails.
@@ -208,19 +208,19 @@ test_files:
208
208
  - test/dummy/Rakefile
209
209
  - test/dummy/app/assets/images/.keep
210
210
  - test/dummy/app/assets/javascripts/application.js
211
- - test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee
211
+ - test/dummy/app/assets/javascripts/pluggable/pluggable_js/posts/new.js.coffee
212
212
  - test/dummy/app/assets/javascripts/posts.js.coffee
213
213
  - test/dummy/app/assets/stylesheets/application.css
214
214
  - test/dummy/app/controllers/application_controller.rb
215
215
  - test/dummy/app/controllers/concerns/.keep
216
- - test/dummy/app/controllers/posts_controller.rb
216
+ - test/dummy/app/controllers/pluggable_js/posts_controller.rb
217
217
  - test/dummy/app/helpers/application_helper.rb
218
218
  - test/dummy/app/mailers/.keep
219
219
  - test/dummy/app/models/.keep
220
220
  - test/dummy/app/models/concerns/.keep
221
221
  - test/dummy/app/views/layouts/application.html.erb
222
- - test/dummy/app/views/posts/index.html.erb
223
- - test/dummy/app/views/posts/new.html.erb
222
+ - test/dummy/app/views/pluggable_js/posts/index.html.erb
223
+ - test/dummy/app/views/pluggable_js/posts/new.html.erb
224
224
  - test/dummy/bin/bundle
225
225
  - test/dummy/bin/rails
226
226
  - test/dummy/bin/rake
@@ -1,28 +0,0 @@
1
- class PostsController < ApplicationController
2
- before_action :set_pluggable_js, only: [:index, :search]
3
-
4
- def index
5
- end
6
-
7
- def search
8
- render :index
9
- end
10
-
11
- def new
12
- pjs(marine_quote: 'You wanna piece of me, boy?')
13
- end
14
-
15
- private
16
-
17
- def set_pluggable_js
18
- pluggable_js(
19
- zealot_quote: 'My life for aiur.',
20
- minerals_size: 999,
21
- base_is_under_attack: true,
22
- alert: ['Nuclear', 'launch', 'detected.'],
23
- ground_units_quotes: { 'Dragoon' => 'Make use of me.', 'High Templar' => 'It shall be done.', 'Archon' => 'We burn...' },
24
- air_units_quotes: [{'Scout' => 'Awaiting command.'}, {'Arbiter' => 'We feel your presence.'}, {'Carrier' => 'Affirmative.'}]
25
- )
26
- end
27
-
28
- end