happy_place 0.0.2 → 0.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: 056e62b5797b23e69b1e0cae4158020d0aee4d4a
4
- data.tar.gz: e47b08f4ee4d10d4b25c607a71110621a13550b9
3
+ metadata.gz: aa25386c08b4e740ceac1ab66d337a1f0577c5a0
4
+ data.tar.gz: 1dcc0f29128bdeae412ab7d5a6fb693decf73099
5
5
  SHA512:
6
- metadata.gz: 3ce1d9a81d9aebb0b26e178e9d0d42cbe7a555f21ef12e751eee2c16d8599fb09a992a00c1c332e40036204daadc3be6639e086b68f131dcda56008cd995372d
7
- data.tar.gz: bea28f72651714c95facdc577c3ddfa60d29be862e1679dae435b5e4ac1e4fd20dfcf1a473b5acdf78cac06b7305b0bbcc220d4c8d678db0ee7f972f761292a2
6
+ metadata.gz: 8bda773c9d66986e0f973a34c921f91f419efaac3fc218d3c10d2ab252996e67c311d8282aa4ec6b5a5d53e9709d59a1f4418655858c35d895151b0f93b930d7
7
+ data.tar.gz: f6a627ca590200639e5224ce7db825a71ebae3c6ec021b807bc8b3a548426815f7c3c69c12571c18893311519f2187ca03f6d6722489b60be73fc16721966262
data/README.md CHANGED
@@ -34,15 +34,19 @@ Or install it yourself as:
34
34
  $ gem install happy_place
35
35
 
36
36
  ## Features
37
- happy_place adds a js method to your controller. This method accepts the following keyword arguments:
37
+ happy_place adds a js method to your controller.
38
38
 
39
- `js_class:` String name of the js class that you want to user
39
+ It is important to note that this is not a breaking change to your controller. All controllers should work normally when adding this gem. This will allow you to test out happy place and see if you like it without breaking the rest of your app and if you do like it you can gradually make the changes to using the js method for all your js needs.
40
+
41
+ The `js` method accepts the following keyword arguments:
42
+
43
+ `js_class:` String name of the js class that you want to use
40
44
 
41
45
  `function:` Sting of the name of the function you would like to call
42
46
 
43
- `partial:` String of the partial name and path that you would like to render
47
+ `partials:` Hash of keyword arguments with partials that will be rendered and available in your js function
44
48
 
45
- `args:` Hash of arguments that you would like to be available in your js function
49
+ `args:` Hash of keyword arguments that you would like to be available in your js function
46
50
 
47
51
  Both partial and keys passed from args will be available in your js function by accessing the object passed in.
48
52
 
@@ -55,7 +59,7 @@ class ExampleContorller
55
59
  format.js {
56
60
  js(js_class: "ExampleClass",
57
61
  function: "doSomething",
58
- partial: "some_partial",
62
+ partials: {some_partial: "some_partial"},
59
63
  args: {first_id: @examples.first.id}
60
64
  )
61
65
  }
@@ -70,7 +74,7 @@ class this.ExampleClass
70
74
  constructor: ->
71
75
 
72
76
  @doSomething: (args) ->
73
- html_to_append = args.partial
77
+ html_to_append = args.some_partial
74
78
  first_id = args.first_id
75
79
  alert(html_to_append)
76
80
  alert(first_id)
@@ -86,7 +90,7 @@ class ExampleContorller
86
90
  respond_to do |format|
87
91
  format.js {
88
92
  js(
89
- partial: "some_partial",
93
+ partials: {some_partial: "some_partial"},
90
94
  args: {first_id: @examples.first.id}
91
95
  )
92
96
  }
@@ -125,7 +129,7 @@ class this.ExampleController
125
129
  constructor: ->
126
130
 
127
131
  @index: ->
128
- alert "Huzza!)
132
+ alert "Huzza!"
129
133
  ```
130
134
 
131
135
  ## Naming and Directory Structure
@@ -223,7 +227,7 @@ class PostsController
223
227
  @posts = Posts.all
224
228
 
225
229
  respond_to do |format|
226
- format.js { js partial: "posts" }
230
+ format.js { js partials: {posts: "posts"} }
227
231
  format.html
228
232
  end
229
233
  end
@@ -237,7 +241,7 @@ class this.PostsController
237
241
  constructor: ->
238
242
 
239
243
  @index: (args) ->
240
- $(".posts_table").html(args.partial);
244
+ $(".posts_table").html(args.posts);
241
245
  ```
242
246
 
243
247
  Step 4. Add `assets/controllers` to your manifest application.js
@@ -13,15 +13,16 @@ module HappyPlace
13
13
  # end
14
14
 
15
15
  # instance methods to go on every controller go here
16
- def js(js_class: nil, function: nil, partial: nil, args: {})
16
+ def js(js_class: nil, function: nil, partials: {}, args: {})
17
17
  return unless [:js, :html].include?(request.format.to_sym)
18
18
 
19
19
  js_class ||= self.class.name.gsub("::", ".")
20
20
  function ||= action_name
21
21
 
22
- if partial.present?
23
- appendable = (render_to_string partial: partial).gsub("\n", "")
24
- built_args = "({" + (["partial: '#{appendable}'"] + hash_to_js_args(args)).join(", ") + "});"
22
+ if partials.present?
23
+ built_args = "({" +
24
+ (build_partials_string(partials) + hash_to_js_args(args)).join(", ") +
25
+ "});"
25
26
  else
26
27
  built_args = "({" + hash_to_js_args(args).join(", ") + "});"
27
28
  end
@@ -56,5 +57,13 @@ module HappyPlace
56
57
  js_args
57
58
  end
58
59
 
60
+ def build_partials_string(partials)
61
+ partials_strings = []
62
+ partials.each_pair do |k, v|
63
+ partials_strings << (k.to_s + ": " + "'#{(render_to_string partial: v).gsub("\n", "")}'")
64
+ end
65
+ partials_strings
66
+ end
67
+
59
68
  end
60
69
  end
@@ -1,3 +1,3 @@
1
1
  module HappyPlace
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Piccolo