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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7e1dc20d0c0328f1bf75473e5a53c1498cb92ee
4
- data.tar.gz: 1ea6d564384dc36b3f4e11a7a870b2217351e2a0
3
+ metadata.gz: d8344f65c6acf13c203b313e6057a414f83e49fd
4
+ data.tar.gz: 6450599c3ab762d0a385abffd81292f6be6a63b0
5
5
  SHA512:
6
- metadata.gz: a72f01f53602186364f71b60cad17bc562369eeb6ef5b006746462d1200ef9af7c42c566716d3604e9f1189728eb24ee8f1ff9f67f73777e71b315789eff243a
7
- data.tar.gz: 26a4568fd34a37e100ddb26e0e2813214a52f92496c6dd71dfe9aa2c9e72be1a0b1ac27846aaef9a96bf59b10224077d00d7f1072e4644377b5f98731d419d56
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 'Zealots: 12.'
39
- page.should have_content 'Dragoons: 6.'
40
- page.should have_content 'Archons: 1.'
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
@@ -34,21 +34,15 @@ module PluggableJs
34
34
  end
35
35
 
36
36
  module ControllerHelpers
37
- # convert hash, passed from controller's action, to js data string
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
- value = if value.is_a?(String)
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
@@ -1,3 +1,3 @@
1
1
  module PluggableJs
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -2,4 +2,4 @@
2
2
  # don't want to define as a function in controller related js file.
3
3
 
4
4
  jQuery ->
5
- $('.marine-quote').text('You wanna piece of me, boy?')
5
+ $('.terran-quotes').text('You wanna piece of me, boy?')
@@ -1,8 +1,11 @@
1
1
  window.posts = {}
2
2
  posts.index = () ->
3
- $('.protoss-quotes').append("<p>#{pluggable_js.zealot_quote}</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.units
8
- $('.protoss-quotes').append("<p>#{key}: #{pluggable_js.units[key]}.</p>")
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
- units: { 'Zealots' => 12, 'Dragoons' => 6, 'Archons' => 1 }
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", "data-turbolinks-track" => true %>
6
- <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
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='marine-quote'></div>
2
+ <div class='terran-quotes'></div>
@@ -1,2 +1,2 @@
1
- <div class='zealot-quote'></div>
2
- <div class='marine-quote'></div>
1
+ <div class='protoss-quotes'></div>
2
+ <div class='terran-quotes'></div>
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
+ root 'posts#index'
2
3
  resources :posts, only: [:index, :new] do
3
4
  collection do
4
5
  get :search
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.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-04 00:00:00.000000000 Z
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.0.5
231
+ rubygems_version: 2.1.11
232
232
  signing_key:
233
233
  specification_version: 4
234
234
  summary: Pluggable javascript.