-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (154 loc) · 7.75 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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Charlotte Ruby Gem Workshop</title>
<style type="text/css">
body {
margin-top: 1.0em;
background-color: #eee;
font-family: 'Helvetica Neue', Helvetica, Arial, FreeSans, san-serif;
color: #000000;
}
#container {
margin: 0 auto;
width: 900px;
}
h1 { font-size: 3em; color: #333; margin-bottom: 3px; text-align:center;}
h1 .small { font-size: 0.4em; }
h1 a { text-decoration: none }
h2 { font-size: 1.5em; color: #333; }
h3 {color: #fff; padding: 10px; background-color: #444;}
a { color: #333; }
hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
.footer { text-align:center; padding-top:30px; font-style: italic; }
.gist{
margin: 10px 0;
font-size: 12px;
font-family: 'Bitstream Vera Sans Mono', Courier, monospace;
}
.gist .gist-file .gist-data pre{
padding: 10px !important;
}
.rbox {
margin: 15px 0;
padding: 15px;
border: 1px solid #D2D2D2;
background-color: white;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
font-family: 'Bitstream Vera Sans Mono', Courier, monospace;
font-size: 14px;
}
.rbox .shell{
color: #00750B;
}
span.red{
color: red;
}
</style>
</head>
<body>
<a href="http://github.com/charlotte-ruby/gem_workshop_tutorial"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
<div id="container">
<h1><a href="http://github.com/charlotte-ruby/gem_workshop_tutorial">Charlotte Ruby Gem Workshop</a>
<h2>Creating a simple gem for Rails using Jeweler</h2>
<h3>acts_as_charlie_sheen</h3>
<h2>Requirements: ruby & a github account
<h2>1. Install Jeweler</h2>
Open up your shell and install and run this command:
<div class="rbox">
<span class="shell">winning$</span> gem install jeweler
</div>
<h2>2. Create gem skelaton</h2>
<div class="rbox">
<span class="shell">winning$</span> jeweler acts_as_charlie_sheen
</div>
<h2>3. Navigate to the gem directory and run bundle install</h2>
<div class="rbox">
<span class="shell">winning$</span> cd acts_as_charlie_sheen<br/>
<span class="shell">winning$</span> bundle install
</div>
<h2>4. Update the Rakefile in your favorite editor</h2>
This file will be translated into the gem's gemspec. Update the summary, description, email and authors with your own information.<br/><br/> <span class="red"><b>NOTE:</b> Jeweler will not generate your gemspec if you have TODO or FIXME in the description and summary, so you will need to change these attributes.</span>
<script src="https://gist.github.com/1230996.js?file=Rakefile"></script>
<h2>5. create a VERSION file</h2>
Jeweler includes a rake task that will create a flat file named VERSION. This file includes only the version number. Jeweler will start the VERSION file at version 0.0.0
<div class="rbox">
<span class="shell">winning$</span> rake version:write
</div>
<h2>6. create the gemspec</h2>
Let's go ahead and create the gemspec using another Jeweler rake task
<div class="rbox">
<span class="shell">winning$</span> rake gemspec
</div>
<h2>7. Add a directory for your code</h2>
<div class="rbox">
<span class="shell">winning$</span> mkdir lib/acts_as_charlie_sheen
</div>
<h2>8. Create a ruby file and add some code</h2>
Add "base.rb" to "/lib/acts_as_charlie_sheen/". This file will be loaded by the root ruby file in the gem. Many gem developers use a root ruby file that requires all of the ruby modules and classes inside lib/gem_name/.
<script src="https://gist.github.com/1231109.js?file=base.rb"></script>
<h2>9. Create a Railtie in lib/acts_as_charlie_sheen/</h2>
<script src="https://gist.github.com/1231112.js?file=railtie.rb"></script>
This allows the Rails boot process to load your gem into your Rails app, just by including it in your Gemfile. The main benefit of using a Railtie is that it provides you access to the Rails initialization process</h2>
<h2>10. Require the Railtie and your code</h2>
Your entry point file is lib/acts_as_charlie_sheen.rb. This file will be loaded when your gem is required in an app. You will need to require all other ruby files within this file in order for them to be used in your app.
<script src="https://gist.github.com/1231053.js?file=acts_as_charlie_sheen.rb"></script>
<h2>11. Bump your version to 0.0.1</h2>
Now that you have some code in your gem, let's go ahead and do an early release. Jeweler has rake tasks that will bump your VERSION file for major, minor or patch versions. Bump the patch version to 0.0.1
<div class="rbox">
<span class="shell">winning$</span> rake version:bump:patch
</div>
<h2>12. Add and commit your code to git</h2>
<div class="rbox">
<span class="shell">winning$</span> git add .<br/>
<span class="shell">winning$</span> git commit -m 'first commit'
</div>
<h2>13. Create a github repo for the gem</h2>
Sign in to github under the account name you specified in your Rakefile/Gemspec and add a new repository called acts_as_charlie_sheen
<h2>14. Release your gem to github</h2>
Now that you have some code and bumped your version to 0.0.1, you can push it to github. The following rake commands will generate a gemspec, push the gemspec to github and then create a git tag and push to your github repo
<div class="rbox">
<span class="shell">winning$</span> rake gemspec:release<br/>
<span class="shell">winning$</span> rake git:release
</div>
<h2>15. Create a new Rails app</h2>
Navigate to a directory outside your gem and create a new Rails app.
<div class="rbox">
<span class="shell">winning$</span> cd /some_other_directory<br/>
<span class="shell">winning$</span> rails new my_app<br/>
<span class="shell">winning$</span> cd /my_app<br/>
</div>
<h2>16. Add it to your Gemfile</h2>
<span class="red"><b>NOTE:</b> Change this line, so that it points to your github account instead of "your_username"</span>
<script src="https://gist.github.com/1231077.js?file=Gemfile"></script>
<h2>17. Install w/ bundler</h2>
This will install the gem in your Rails app
<div class="rbox">
<span class="shell">winning$</span> bundle install
</div>
<h2>18. Scaffold a Person and run the migration</h2>
You need to create this model, so we can make it act like charlie sheen
<div class="rbox">
<span class="shell">winning$</span> rails g scaffold person<br/>
<span class="shell">winning$</span> rake db:migrate
</div>
<h2>19. Make the model act like Charlie Sheen</h2>
<script src="https://gist.github.com/1231091.js?file=person.rb"></script>
<h2>20. Edit the Person show view</h2>
To see the gem in action, you will need to add the instance method to the show view. Edit "app/views/people/show.html.erb":
<script src="https://gist.github.com/1231102.js?file=show.html.erb"></script>
<h2>21. Fire up the server and test it out in your browser</h2>
<div class="rbox">
<span class="shell">winning$</span> rails s
</div>
Open up your favorite browser and type in this URL: <br/><a href="http://localhost:3000/people">http://localhost:3000/people</a><br/>
Add a person and then navigate to the show view
<div class="footer">
get the source code on GitHub : <a href="http://github.com/charlotte-ruby/gem_workshop_tutorial">charlotte-ruby/gem_workshop_tutorial</a>
</div>
</div>
</body>
</html>