pre_render 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +74 -2
  3. data/lib/pre_render/version.rb +1 -1
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c3c0d589af98dc5618bdaef33b91078b21b705
4
- data.tar.gz: 35f0eabc6e52dca5a2f3cfa988779829d17682aa
3
+ metadata.gz: c3476896a3dfcf2a171a65e3f6e52baf0457000e
4
+ data.tar.gz: 5ce05cbe2b9f9d80f6afb66be37bb4f76853a26f
5
5
  SHA512:
6
- metadata.gz: 88dac5da89b583b991a0972b1aea05b451a804be03642b1b4bfc8774be3caa1201b49e61c34e7ec8d7e42bbeeb7b05df7a7eb96feb5d6e7546ce173db8525824
7
- data.tar.gz: 5246c376ab7d7f92e9c32d804692495ff31e043cb1e52c4db20f91cb672f18970560d8e13bb41da0a575b0a1c4069a5345860d3d27b26509da48878fdbe572a5
6
+ metadata.gz: 295e79ae45cf471552f0016e96bba3a433da627da0cb4764aebce5c84b00ea85e50061ba3e4398bd144784b022e59cb1a22ac38e21b6b54ceb8261a8ba0ed26b
7
+ data.tar.gz: 2c56548248bca50c19494f19036a59318eff675154b383c9634382be81536d741c90c7b5448a40927e5fe3c7170670523aae81d114a47e0b84ff2ffce626621a
data/README.md CHANGED
@@ -1,2 +1,74 @@
1
- # pre_render
2
- Adds support for a pre_render methods to Rails controllers.
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
+
@@ -1,3 +1,3 @@
1
1
  module PreRender
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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: