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 +4 -4
- data/README.md +14 -10
- data/lib/happy_place/controller.rb +13 -4
- data/lib/happy_place/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa25386c08b4e740ceac1ab66d337a1f0577c5a0
|
4
|
+
data.tar.gz: 1dcc0f29128bdeae412ab7d5a6fb693decf73099
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
37
|
+
happy_place adds a js method to your controller.
|
38
38
|
|
39
|
-
|
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
|
-
`
|
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
|
-
|
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.
|
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
|
-
|
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
|
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.
|
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,
|
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
|
23
|
-
|
24
|
-
|
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
|
data/lib/happy_place/version.rb
CHANGED