self_renderer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +25 -4
- data/lib/self_renderer/version.rb +1 -1
- data/lib/self_renderer.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: 46e2a834d05504a734dbbdae8e4c4771eeb3f545
|
4
|
+
data.tar.gz: 4bf622793d5201ec98bc2f2574a314a911e5d790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35e934940725feada8e1332c653c2555ffcf3c5ce2de15d3f28ce3c9e47db8482f73f0aa46f5cbad524bed80724ba852ed5b6a37c8ba91260a5a8d3ea2e114b4
|
7
|
+
data.tar.gz: ca047a12c2b5e06d0aca3f58bfc26ebf04439d7722eb2c1ce1071a1eda1198745a46666d7ebcd87dc3cd53ff92e62b23e2d947fc83ec7ee3fe5b90a0c87de203
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,18 +9,39 @@ Rails model & object rendering outside the context of web requests.
|
|
9
9
|
|
10
10
|
## Quick Start
|
11
11
|
|
12
|
-
```
|
13
|
-
|
12
|
+
```ruby
|
13
|
+
# Gemfile
|
14
|
+
gem "self_renderer"
|
14
15
|
```
|
15
16
|
|
16
17
|
```ruby
|
17
|
-
|
18
|
-
|
18
|
+
# app/models/user.rb
|
19
19
|
class User < ApplicationRecord
|
20
20
|
include SelfRenderer
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
+
```erb
|
25
|
+
<!-- app/views/users/show.html.erb -->
|
26
|
+
<h1>User</h1>
|
27
|
+
<%= render "item" %>
|
28
|
+
```
|
29
|
+
|
30
|
+
```erb
|
31
|
+
<!-- app/views/users/_item.html.erb -->
|
32
|
+
<p><%= @user.name %></p>
|
33
|
+
```
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
# app/views/users/show.json.jbuilder
|
37
|
+
json.partial! "item"
|
38
|
+
```
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# app/views/users/_item.json.jbuilder
|
42
|
+
json.name @user.name
|
43
|
+
```
|
44
|
+
|
24
45
|
```ruby
|
25
46
|
# render html strings
|
26
47
|
User.find(1).render_to_html(template: "users/show.html.erb")
|
data/lib/self_renderer.rb
CHANGED
@@ -39,7 +39,7 @@ module SelfRenderer
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def render_self(template: nil, partial: nil, assigns: {}, locals: {})
|
42
|
-
name = self.class.name.parameterize(separator: "_")
|
42
|
+
name = self.class.name.parameterize(separator: "_").to_sym
|
43
43
|
assigns[name] = self
|
44
44
|
locals[name] = self
|
45
45
|
return self_renderer.render(template, assigns: assigns, locals: locals).squish if template
|