happy_place 0.0.5 → 0.0.6

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: c51fabd7545e21b800c25038db6656f4c4afbbe6
4
- data.tar.gz: c5f9fa062853e454d0642a517311656c96802eac
3
+ metadata.gz: 699c95a15b39dc929671551c1579537fae0b811a
4
+ data.tar.gz: 4c3226374364afb61ccaa75d5f64e19c06593dae
5
5
  SHA512:
6
- metadata.gz: 60f3ed8d446bd150e299c62a5a61c0c08665f21fc0389c219094d8a7b0cd0228f44d0f4596a9f9a4554f26dfff56f42a81f1a844d7efefe3464e9782f0641fad
7
- data.tar.gz: d14a0c6faee0d80dc0d8b881ec1abeb38c24e0ce6abaab903527b405c4f21c9a3754b948af5da928de9073865ad4fd8f0f2189cbb56f60840517648d3292049e
6
+ metadata.gz: dbee823d359531914b2d98058d021deba71467cdfd359d847b700d9775ab6bab372bf2b5bb62d10c5dd66c8c79712755bef6323073ae023ba1cac2011287c687
7
+ data.tar.gz: e9cc999efbab6d768e327747c787ecb4632c71e100b1d465ab5d9de1255f62752930004e1932549369f6f3f38730b96c0a93bba796160ec77f4a8d423c0d3ab1
data/README.md CHANGED
@@ -33,6 +33,10 @@ Or install it yourself as:
33
33
 
34
34
  $ gem install happy_place
35
35
 
36
+ ## Demo
37
+
38
+ If you would like to see happy_place in action check out [happy-place-demo](https://happy-place-demo.herokuapp.com/dashboard).
39
+
36
40
  ## Features
37
41
  happy_place adds a js method to your controller.
38
42
 
@@ -169,7 +173,7 @@ Or require them explicitly:
169
173
 
170
174
  ### Stop using js views after remote actions!
171
175
 
172
- Lets say you have a blog where you can see a list of posts (Imagine that!). You use the Posts#index to display this and it is loaded noramally with :html.
176
+ Let's say you have a blog where you can see a list of posts (Imagine that!). You use the Posts#index to display this and it is loaded normally with :html.
173
177
 
174
178
  ```html
175
179
  <!-- posts/index.html.erb -->
@@ -13,21 +13,26 @@ 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, partials: {}, args: {})
16
+ def js(js_class: nil, function: nil, partials: {}, args: {}, container: {}, rendered: false)
17
17
  class_and_function = build_class_and_function(js_class, function)
18
18
  built_args = build_args(partials, args)
19
19
  case request.format.to_sym
20
20
  when :js
21
21
  render js: class_and_function + built_args
22
22
  when :html
23
- render
23
+ render unless rendered
24
+
24
25
  response_body = response.body
25
- before_body_end_index = response_body.rindex('</body>')
26
+ if response_body.present?
27
+ before_body_end_index = response_body.rindex('</body>')
26
28
 
27
- before_body = response_body[0, before_body_end_index].html_safe
28
- after_body = response_body[before_body_end_index..-1].html_safe
29
+ before_body = response_body[0, before_body_end_index].html_safe
30
+ after_body = response_body[before_body_end_index..-1].html_safe
29
31
 
30
- response.body = before_body + auto_exec_function(class_and_function, built_args).html_safe + after_body
32
+ response.body = before_body + auto_exec_function(class_and_function, built_args).html_safe + after_body
33
+ else
34
+ response.body = auto_exec_function(class_and_function, built_args.gsub("\n", ""), container).html_safe
35
+ end
31
36
  end
32
37
  end
33
38
 
@@ -47,8 +52,12 @@ module HappyPlace
47
52
  end
48
53
  end
49
54
 
50
- def auto_exec_function(class_and_function, args)
51
- "<script type='application/javascript'>jQuery(document).ready(function($) {" + render_to_string(js: class_and_function + args) + "});</script>"
55
+ def auto_exec_function(class_and_function, args, container)
56
+ script_string = "<script type='application/javascript'>jQuery(document).ready(function($) {" + render_to_string(js: class_and_function + args) + "});</script>"
57
+ if container.present?
58
+ script_string = container[:open] + script_string + container[:close]
59
+ end
60
+ script_string
52
61
  end
53
62
 
54
63
  def hash_to_js_args(args)
@@ -1,3 +1,3 @@
1
1
  module HappyPlace
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: happy_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Piccolo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails