pluggable_js 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +8 -9
- data/features/pluggable_js.feature +7 -6
- data/features/step_definitions/pluggable_js_steps.rb +9 -3
- data/lib/pluggable_js/helpers.rb +5 -11
- data/lib/pluggable_js/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/pluggable/posts/new.js.coffee +1 -1
- data/test/dummy/app/assets/javascripts/posts.js.coffee +6 -3
- data/test/dummy/app/controllers/posts_controller.rb +2 -1
- data/test/dummy/app/views/layouts/application.html.erb +2 -2
- data/test/dummy/app/views/posts/index.html.erb +1 -1
- data/test/dummy/app/views/posts/new.html.erb +2 -2
- data/test/dummy/config/routes.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8344f65c6acf13c203b313e6057a414f83e49fd
|
4
|
+
data.tar.gz: 6450599c3ab762d0a385abffd81292f6be6a63b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a40748b5a52170e0ac9c0f9537c2a7e9812f43f9ee2cc76145b292e3b936fde5881be6f5a8dcdd3a231ad0a1bb07ae2b727ae4cd791d72a7b501562dc07316
|
7
|
+
data.tar.gz: 7fc292f5541052fe50a30b8953607cdedf6459892c5fbe96731af0473a8c493f865411e2efd1a3ea4293c15ca65e04aa94aec281e64d8717e86c0eb00acd3ec6
|
data/CHANGELOG.md
CHANGED
@@ -33,3 +33,15 @@
|
|
33
33
|
## v1.0.0
|
34
34
|
|
35
35
|
* passing data to javascript functionality
|
36
|
+
|
37
|
+
## v1.0.1
|
38
|
+
|
39
|
+
* array of hashes support
|
40
|
+
|
41
|
+
## v1.0.2
|
42
|
+
|
43
|
+
* array conversion for js and pjs as alias method.
|
44
|
+
|
45
|
+
## v1.0.3
|
46
|
+
|
47
|
+
* removed unnecessary conditions from pluggable_js controller helper
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
|
2
1
|
# PluggableJs
|
3
2
|
|
4
|
-
This gem provides simple functionality of loading page specific javascript and passing data (for Rails >= 3.1 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 loaded.
|
3
|
+
This gem provides simple functionality of loading page specific javascript and passing data from a controller (for Rails >= 3.1 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 loaded.
|
5
4
|
|
6
5
|
## Installation
|
7
6
|
|
8
7
|
* Add `gem 'pluggable_js'` to Gemfile and run `bundle` command to install it
|
9
|
-
* Add `<%= javascript_pluggable_tag %>` to application layout file after `<%= javascript_include_tag 'application' %>` line
|
8
|
+
* Add `<%= javascript_pluggable_tag %>` to application layout file after `<%= javascript_include_tag 'application' %>` line (if you use turbolinks, move helper inside the `body` tag)
|
10
9
|
|
11
10
|
Next steps are necessary only if you want to use generator for large pieces of js code (see usage):
|
12
11
|
|
@@ -45,7 +44,8 @@ class PostsController < ApplicationController
|
|
45
44
|
integer: 1,
|
46
45
|
boolean: true,
|
47
46
|
array: [1, 2, 3],
|
48
|
-
hash: { a: 1, b: 2, c: 3 }
|
47
|
+
hash: { a: 1, b: 2, c: 3 },
|
48
|
+
array_of_hashes: [{a: 1}, {b: 2}, {c: 3}]
|
49
49
|
})
|
50
50
|
end
|
51
51
|
end
|
@@ -61,8 +61,11 @@ posts.index = () ->
|
|
61
61
|
console.log pluggable_js.integer
|
62
62
|
console.log pluggable_js.array
|
63
63
|
console.log pluggable_js.hash
|
64
|
+
console.log pluggable_js.array_of_hashes
|
64
65
|
```
|
65
66
|
|
67
|
+
Note: `pjs` is an alias of `pluggable_js`.
|
68
|
+
|
66
69
|
## Config
|
67
70
|
|
68
71
|
Let's say you've created action `search` that renders `index` template. Most likely we still need to trigger `posts.index()` function. In such situation you may create `config/initializers/pluggable_js.rb` and use pair actions config:
|
@@ -75,8 +78,4 @@ end
|
|
75
78
|
|
76
79
|
`{ 'create' => 'new', 'update' => 'edit' }` is a default REST configuration.
|
77
80
|
|
78
|
-
If you passing data, move `pluggable_js` helper into a separate private method and use `before_action :your_private_method, only: [:index, :search]` (`before_filter` in Rails < 4).
|
79
|
-
|
80
|
-
## Upgrade
|
81
|
-
|
82
|
-
If you are upgrading from version `<= 0.0.6` to `1.0.0`, all you have to do is rename old construction `window.Post` to new `window.posts` (see usage).
|
81
|
+
If you are passing data, move `pluggable_js` helper into a separate private method and use `before_action :your_private_method, only: [:index, :search]` (`before_filter` in Rails < 4).
|
@@ -9,12 +9,13 @@ Feature: PluggableJs
|
|
9
9
|
And I should not see 'You wanna piece of me, boy?'
|
10
10
|
|
11
11
|
Examples:
|
12
|
-
| action | data_type
|
13
|
-
| index | string
|
14
|
-
| search | integer
|
15
|
-
| index | boolean
|
16
|
-
| search | array
|
17
|
-
| index | hash
|
12
|
+
| action | data_type |
|
13
|
+
| index | string |
|
14
|
+
| search | integer |
|
15
|
+
| index | boolean |
|
16
|
+
| search | array |
|
17
|
+
| index | hash |
|
18
|
+
| search | array_of_hashes |
|
18
19
|
|
19
20
|
@javascript
|
20
21
|
Scenario: New Post
|
@@ -35,7 +35,13 @@ Then(/^I should see content with 'array'$/) do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
Then(/^I should see content with 'hash'$/) do
|
38
|
-
page.should have_content '
|
39
|
-
page.should have_content '
|
40
|
-
page.should have_content '
|
38
|
+
page.should have_content 'Dragoon: Make use of me.'
|
39
|
+
page.should have_content 'High Templar: It shall be done.'
|
40
|
+
page.should have_content 'Archon: We burn...'
|
41
|
+
end
|
42
|
+
|
43
|
+
Then(/^I should see content with 'array_of_hashes'$/) do
|
44
|
+
page.should have_content 'Scout: Awaiting command.'
|
45
|
+
page.should have_content 'Arbiter: We feel your presence.'
|
46
|
+
page.should have_content 'Carrier: Affirmative.'
|
41
47
|
end
|
data/lib/pluggable_js/helpers.rb
CHANGED
@@ -34,21 +34,15 @@ module PluggableJs
|
|
34
34
|
end
|
35
35
|
|
36
36
|
module ControllerHelpers
|
37
|
-
# convert hash
|
37
|
+
# convert hash passed from a controller's action to js data string
|
38
38
|
def pluggable_js(hash)
|
39
39
|
data_string = hash.map do |key, value|
|
40
|
-
|
41
|
-
"'#{value}'"
|
42
|
-
elsif value.is_a?(Hash)
|
43
|
-
value.to_json
|
44
|
-
else
|
45
|
-
value
|
46
|
-
end
|
47
|
-
"pluggable_js.#{key} = #{value};"
|
40
|
+
"pluggable_js.#{key} = pjs.#{key} = #{value.to_json};"
|
48
41
|
end.join(' ')
|
49
|
-
@js_data_string = 'window.pluggable_js = {}; ' + data_string
|
42
|
+
@js_data_string = 'window.pluggable_js = window.pjs = {}; ' + data_string
|
50
43
|
end
|
51
|
-
|
44
|
+
alias_method :pjs, :pluggable_js
|
45
|
+
|
52
46
|
end
|
53
47
|
|
54
48
|
end
|
data/lib/pluggable_js/version.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
window.posts = {}
|
2
2
|
posts.index = () ->
|
3
|
-
$('.protoss-quotes').append("<p>#{
|
3
|
+
$('.protoss-quotes').append("<p>#{pjs.zealot_quote}</p>")
|
4
4
|
$('.protoss-quotes').append('<p>You have not enough minerals.</p>' if pluggable_js.minerals_size < 1000)
|
5
5
|
$('.protoss-quotes').append('<p>Base is under attack.</p>') if pluggable_js.base_is_under_attack
|
6
6
|
$('.protoss-quotes').append("<p>#{pluggable_js.alert.join(' ')}</p>")
|
7
|
-
for key of pluggable_js.
|
8
|
-
$('.protoss-quotes').append("<p>#{key}: #{
|
7
|
+
for key, value of pluggable_js.ground_units_quotes
|
8
|
+
$('.protoss-quotes').append("<p>#{key}: #{value}</p>")
|
9
|
+
for unit in pluggable_js.air_units_quotes
|
10
|
+
for key, value of unit
|
11
|
+
$('.protoss-quotes').append("<p>#{key}: #{value}</p>")
|
@@ -19,7 +19,8 @@ class PostsController < ApplicationController
|
|
19
19
|
minerals_size: 999,
|
20
20
|
base_is_under_attack: true,
|
21
21
|
alert: ['Nuclear', 'launch', 'detected.'],
|
22
|
-
|
22
|
+
ground_units_quotes: { 'Dragoon' => 'Make use of me.', 'High Templar' => 'It shall be done.', 'Archon' => 'We burn...' },
|
23
|
+
air_units_quotes: [{'Scout' => 'Awaiting command.'}, {'Arbiter' => 'We feel your presence.'}, {'Carrier' => 'Affirmative.'}]
|
23
24
|
})
|
24
25
|
end
|
25
26
|
|
@@ -2,8 +2,8 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>Dummy</title>
|
5
|
-
<%= stylesheet_link_tag "application", media: "all"
|
6
|
-
<%= javascript_include_tag "application"
|
5
|
+
<%= stylesheet_link_tag "application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "application" %>
|
7
7
|
<%= javascript_pluggable_tag %>
|
8
8
|
<%= csrf_meta_tags %>
|
9
9
|
</head>
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<div class='protoss-quotes'></div>
|
2
|
-
<div class='
|
2
|
+
<div class='terran-quotes'></div>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
<div class='
|
2
|
-
<div class='
|
1
|
+
<div class='protoss-quotes'></div>
|
2
|
+
<div class='terran-quotes'></div>
|
data/test/dummy/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluggable_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Peresleguine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coffee-rails
|
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
230
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.1.11
|
232
232
|
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: Pluggable javascript.
|