pre_render 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +74 -2
- data/lib/pre_render/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3476896a3dfcf2a171a65e3f6e52baf0457000e
|
4
|
+
data.tar.gz: 5ce05cbe2b9f9d80f6afb66be37bb4f76853a26f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 295e79ae45cf471552f0016e96bba3a433da627da0cb4764aebce5c84b00ea85e50061ba3e4398bd144784b022e59cb1a22ac38e21b6b54ceb8261a8ba0ed26b
|
7
|
+
data.tar.gz: 2c56548248bca50c19494f19036a59318eff675154b383c9634382be81536d741c90c7b5448a40927e5fe3c7170670523aae81d114a47e0b84ff2ffce626621a
|
data/README.md
CHANGED
@@ -1,2 +1,74 @@
|
|
1
|
-
# pre_render
|
2
|
-
|
1
|
+
# The pre_render Gem
|
2
|
+
|
3
|
+
Adds support for a ```pre_render()``` method to Rails controllers.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following line to your Rails application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "pre_render"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Let's say you have a ```Person``` model with the accompanying ```PeopleController```. Then the controller might look something
|
16
|
+
like this:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class PeopleController < ApplicationController
|
20
|
+
|
21
|
+
before_action :set_person, only: [:show, :edit, :update, :destroy]
|
22
|
+
|
23
|
+
# GET /people
|
24
|
+
# GET /people.json
|
25
|
+
def index
|
26
|
+
@people = Person.all
|
27
|
+
end
|
28
|
+
|
29
|
+
# GET /people/1
|
30
|
+
# GET /people/1.json
|
31
|
+
def show
|
32
|
+
end
|
33
|
+
|
34
|
+
# ...
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def pre_render(view, *args)
|
39
|
+
logger.info "Preparing to render the \"#{view}\" view of #{self.class}"
|
40
|
+
case view
|
41
|
+
when :index
|
42
|
+
# ...
|
43
|
+
when :edit
|
44
|
+
# ...
|
45
|
+
# ...
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Use callbacks to share common setup or constraints between actions.
|
51
|
+
def set_person
|
52
|
+
@person = Person.find(params[:id])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
56
|
+
def person_params
|
57
|
+
params.require(:person).permit(:first_name, :last_name, :age)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
The ```pre_render()``` method will be called right before Rails' ```render()``` method. This will give your controller a last chance to
|
64
|
+
fully initialize any instance variables a view might need to render itself. If you are using any view model construct, this is a
|
65
|
+
good place to initialize or finish initializing it.
|
66
|
+
|
67
|
+
## Credits
|
68
|
+
|
69
|
+
The idea for this gem came from my time spent working as a classic ASP.NET developer. The classic ASP.NET page event model
|
70
|
+
also supports the notion of a ```PreRender()``` method being called right before the ```Render()``` method to allow an application's
|
71
|
+
code-behind class to finish initialization of its properties and fields.
|
72
|
+
|
73
|
+
I found this to be useful then, as I do now in the Rails world.
|
74
|
+
|
data/lib/pre_render/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pre_render
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Brazil
|
@@ -78,3 +78,4 @@ signing_key:
|
|
78
78
|
specification_version: 4
|
79
79
|
summary: Adds support for a pre_render() method to Rails controllers.
|
80
80
|
test_files: []
|
81
|
+
has_rdoc:
|