forked from dougalcorn/decent_exposure_pres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
310 lines (264 loc) · 10.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Decent Exposure</title>
<meta name="description" content="A helper for creating declarative interfaces in Rails controllers">
<meta name="author" content="Doug Alcorn">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<script type="text/javascript" src="//use.typekit.net/ono5mit.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<!-- <link rel="stylesheet" href="http://gaslight.dev/assets/application.css"> -->
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<style type="text/css">
body {
font-family: 'ff-din-web', Times, 'Times New Roman', serif;
font-size: 36px;
font-weight: 200;
letter-spacing: -0.02em;
background: url(http://gaslight.co/assets/home/background.jpg);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.reveal .slides {
margin-top: -340px;
}
.reveal code {
padding-left: .5em;
}
.reveal .slides section {
background-color: rgba(255, 255, 255, 0.5);
padding: 2em;
box-sizing: border-box;
box-shadow: 0px 10px 30px #bbb;
}
.reveal h1,
.reveal h2,
.reveal h3,
.reveal h4,
.reveal h5,
.reveal h6,
body {
color: rgba(30, 30, 30, 0.85);
font-family: 'ff-din-web', 'League Gothic', Impact, sans-serif;
}
.reveal h1, .reveal h2 {
font-family: 'League Gothic', Impact, sans-serif;
text-transform: uppercase;
text-shadow: none;
}
.reveal h3,
.reveal h4,
.reveal h5,
.reveal h6 {
text-transform: none;
letter-spacing: -2px;
line-height: 1.1em;
}
.reveal h3 {
color: rgba(55, 55, 55, 0.9);
font-size: 140%;
}
.reveal h4 {
color: rgba(55, 55, 55, 0.9);
font-size: 80%;
}
#bars {
width: 100%;
position: absolute;
top: 0;
height: 15px;
overflow: visible;
margin: 0;
padding: 0;
}
/* line 33, ../../app/assets/stylesheets/application.css.scss */
#bars li {
width: 33.333%;
float: left;
height: 100%;
list-style: none;
-webkit-transition-property: height;
-moz-transition-property: height;
-o-transition-property: height;
transition-property: height;
-webkit-transition-duration: 0.25s;
-moz-transition-duration: 0.25s;
-o-transition-duration: 0.25s;
transition-duration: 0.25s;
-webkit-transition-timing-function: ease-in-out;
-moz-transition-timing-function: ease-in-out;
-o-transition-timing-function: ease-in-out;
transition-timing-function: ease-in-out;
}
/* line 38, ../../app/assets/stylesheets/application.css.scss */
#bars li.brand1 {
background: #d63f31;
}
/* line 39, ../../app/assets/stylesheets/application.css.scss */
#bars li.brand2 {
background: #60b6e4;
}
/* line 40, ../../app/assets/stylesheets/application.css.scss */
#bars li.brand3 {
background: #ebd018;
}
/* line 41, ../../app/assets/stylesheets/application.css.scss */
#bars li.active {
height: 160%;
}
#logo {
position: absolute;
right: 1em;
top: 1em;
}
#logo img {
max-width: 100px;
opacity: 0.5;
-webkit-filter: grayscale(0.6);
}
</style>
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<ul id='bars'>
<li class='brand1'></li>
<li class='brand2'></li>
<li class='brand3'></li>
</ul>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>A Brief Introduction to Decent Exposure</h1>
<h3>A helper for creating declarative interfaces in Rails controllers</h3>
<h4>Doug Alcorn, [email protected]</h4>
</section>
<section>
<h2>Scaffolding</h2>
<pre><code class="ruby">
class EmployeesController < ApplicationController
before_filter :get_company
def index
@employees = @company.employees.all
end
private
def get_company
@company = Company.find(params[:company_id])
end
end
</code></pre>
<aside class="notes">
Here we have a before filter setting an instance variable used by the entire controller. We're further assigning an instance variable in the action. Before filters are somewhat hard to test and are easily forgotten. Also, you'll eventually find yourself scoping filters with :only or :except; which is yucky.
</aside>
</section>
<section>
<h2>Instance Variables in Views</h2>
<pre><code>
Hi, <%= @employee.name %>
</code></pre>
<blockquote cite="http://www.stephencelis.com/2008/09/06/rails-controllers-views-and-variables.html">
In object-oriented programming, an object uses instance variables to store private information. If you want to access an object’s instance variables, those variables should only be accessible through instance methods. At least, this is the expectation.
</blockquote>
</section>
<section>
<h2>Declarative Helper Methods</h2>
<pre><code>
class EmployeesController < ApplicationController
helper_method :employees, :company
def index; end
protected
def company
@company ||= Company.find(params[:company_id])
end
def employees
@employees ||= company.employees.all
end
end
</code></pre>
<aside class="notes">
Here we have two helper methods that encapsulate how to initialize the needed instance variables. They are cached so that the SQL only happens on the first access. In the view you can just call <code>company</code> or <code>employees</code> to access those instances rather than the <code>@company</code> instance variable.
The really good news here is that if you decide to refactor how the employees are accessed (like scoping it to "active" employees), it's easy to change in just one place.
Also, since the helper methods do all the initialization, there's no actual code needed in the index action and it can go away.
Finally, these helper methods are easy to stub out in testing to avoid hitting the database during controller specs.
</aside>
</section>
<section>
<h2>Trickier Example</h2>
<pre><code>
def employee
@employee ||= if params[:id]
Employee.find params[:id]
else
Employee.new params[:employee]
end
end
</code></pre>
<aside class="notes">
Here we see that the singular instance of employee is either initialized with it's id if it's passed in as a param (as in the show action) or it's newed up with passed in attributes (as in the create attribute).
What we can see is there there are lots of corner cases that need to be thought through.
</aside>
</section>
<section>
<h2>Decent Exposure</h2>
<pre><code>
class EmployeesController < ApplicationController
expose(:company)
expose(:employees) { company.employees.all }
expose(:employee)
end
</code></pre>
<aside class="notes">
Here we're using decent exposure's <code>expose</code> method to create helper methods similar to our hand rolled helpers. Without any arguments, they do a pretty "decent" job of guessing what it should do to load the resource. With an optional block you can specify how the resource should be defined.
</aside>
</section>
<section>
<h2>More Info</h2>
<ul>
<li>These slides are at <a href="http://dougalcorn.github.com/decent_exposure_pres">dougalcorn.github.com/decent_exposure_pres</a></li>
<li>Decent Exposure officially lives at <a href="https://github.com/voxdolo/decent_exposure">github.com/voxdolo/decent_exposure</a></li>
<li>A <a href="http://asciicasts.com/episodes/259-decent-exposure">Rails Cast on Decent Exposure</a></li>
</ul>
</section>
</div>
</div>
<div id="logo">
<img src="http://gaslight.co/assets/home/logo.png" />
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/highlight.js', async: true, callback: function() { window.hljs.initHighlightingOnLoad(); } },
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'lib/js/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'lib/js/data-markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/zoom-js/zoom.js', condition: function() { return !!document.body.classList; } },
{ src: '/socket.io/socket.io.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } },
{ src: 'plugin/speakernotes/client.js', async: true, condition: function() { return window.location.host === 'localhost:1947'; } }
]
});
</script>
</body>
</html>