Skip to content

Commit f515846

Browse files
committed
Add tutor with sample app
The best way to learn something is by doing. Getting started with something new can often be intimidating, and going through the documentation of a project does not leave you with the muscle memory to be able to repeat what you have read. This commit provides a vimtutor-like instructions and a sample Rails application to help you practice your newly learned skills.
1 parent c28d2b2 commit f515846

File tree

103 files changed

+1867
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1867
-0
lines changed

README.markdown

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ Once help tags have been generated, you can view the manual with
6969

7070
[bundler.vim]: https://github.com/tpope/vim-bundler
7171

72+
## Tutor
73+
74+
If you prefer learning by doing, make sure to checkout the included tutor.
75+
76+
It will let you interact with a sample Rails application, and will guide you
77+
through some of the most useful commands rails.vim has to offer.
78+
79+
To start the tutor, run:
80+
81+
```
82+
./vim-rails-tutor
83+
```
84+
85+
**Note:** the executable above will run `bundle install` in order to install
86+
all gems necessary to run the sample app and its tests.
87+
7288
## FAQ
7389

7490
> I installed the plugin and started Vim. Why does only the `:Rails`

tutor/INSTRUCTIONS

Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
1+
===============================================================================
2+
= W e l c o m e t o t h e R a i l s . V I M T u t o r =
3+
===============================================================================
4+
5+
This tutor assumes you have basic working knowledge of Vim.
6+
If you are new to Vim and are not familiar with most basic operations,
7+
press : then type q! to exit the program and run vimtutor first.
8+
9+
This tutor also assumes you have the rails.vim plugin installed.
10+
If you have not done so, please follow the instructions on its git repo:
11+
https://github.com/tpope/vim-rails
12+
13+
You will need approximately 30 minutes to complete this tutor.
14+
15+
ATTENTION:
16+
Any changes made during the lessons that follow will modify the original
17+
vim-rails-tutor. Assuming that you have pulled a copy of the
18+
tutor via git clone, you can always use your favorite git command to
19+
restore the instructions and/or the example rails application
20+
to their original state.
21+
22+
Like vimtutor, this tutor aims to teach you some of the rails.vim
23+
commands by use, rather than by reading a doc file or watching a video,
24+
therefore, it is important that you follow the instructions and execute
25+
all commands.
26+
27+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
29+
Lesson 1.1: NAVIGATION WITH CONTEXT
30+
31+
** Getting familiar with contextual rails.vim navigation. **
32+
33+
1. Enter the following command to open the Comment model from the
34+
example rails app :Vmodel comment .
35+
36+
Note: The above will open the Comment model in a new vertical split.
37+
Keep both windows open in order to be able to follow the
38+
instructions in this file. If you need to switch between windows
39+
you can use CTRL-w w .
40+
41+
2. To see the unit test for the Comment model execute :Eunittest .
42+
43+
3. To see the controller related to the Comment model execute :Emodel
44+
while in the Comment model window.
45+
46+
4. To see the javascript file for the Comment model, execute :Ejavascript .
47+
48+
5. To close the working window execute :q .
49+
50+
51+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52+
53+
Lesson 1.2 NAVIGATION WITH LINE CONTEXT
54+
55+
** Rails view navigation from controller. **
56+
57+
1. Open the Comments controller into a new window by executing
58+
:Vcontroller comments .
59+
60+
2. Try executing :Eview . This should fail with 'No view name given'.
61+
62+
3. Now, move the cursor to any line between 3 and 5 and execute :Eview .
63+
This will take you to the view template matching the 'new' action.
64+
65+
4. Go back to the controller by executing :Econtroller .
66+
67+
5. Put the cursor anywhere between line 7 and 9 and execute :Eview .
68+
Similar to step 3, this step will take you to the index template.
69+
70+
6. Execute :q to close the working window.
71+
72+
73+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
74+
75+
Lesson 1.3 NAVIGATION WITHOUT CONTEXT
76+
77+
** Navigate to anything from anywhere. **
78+
79+
1. Open the Comments controller into a new window by executing
80+
:Vcontroller comments .
81+
82+
2. You can switch to the User model by executing :Emodel user .
83+
84+
3. Execute :Elayout users to go to the Users layout.
85+
86+
4. Execute :Eview comments/index to jump to the comments index view.
87+
88+
5. Execute :q to close the working window.
89+
90+
91+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92+
93+
Lesson 1 SUMMARY
94+
95+
1. :E<something Rails-y> will take you to the expected Rails file based on
96+
the context of your current location.
97+
98+
2. :E<something Rails-y> <argument> does not take the context of your
99+
current location into account, and takes you to the specified location.
100+
101+
3. Sometimes, the line you are currently on is taken into consideration.
102+
103+
4. For a full list of the commands available, please refer to rails.vim`
104+
documentation.
105+
106+
Note: Throughout Lesson 1 we mostly used the prefix :E to edit a desired
107+
file into the current window. The following options are also available:
108+
109+
* :S - for a horizontal split window
110+
* :V - for a vertical split window
111+
* :T - for a new tab
112+
* :D - for reading the file into the current buffer
113+
114+
115+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116+
117+
Lesson 2.1: CLASS DEFINITION UNDER CURSOR
118+
119+
** gf has been modified to take context into account. **
120+
121+
1. Execute :Vcontroller comments .
122+
123+
2. Put the cursor over 'Comment' in line 4.
124+
125+
3. Press gf . This will take you to the Comment model.
126+
127+
4. Put the cursor over 'User' in line 5.
128+
129+
5. Press gf . This will take you to the User class definition file.
130+
131+
6. Execute :q to close the working window.
132+
133+
134+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135+
136+
Lesson 2.2: MODEL RELATIONSHIP UNDER CURSOR
137+
138+
** gf for model relationships. **
139+
140+
1. Execute :Vmodel comment .
141+
142+
2. Move the cursor to point anywhere on the 'belongs_to :user' line.
143+
144+
3. Press gf . This will take you to the User model.
145+
146+
4. In the User model, move the cursor to point anywhere on the
147+
'has_many :comments' line.
148+
149+
5. Press gf . This will take you back to the Comment model.
150+
151+
6. Execute :q to close the working window.
152+
153+
154+
155+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156+
157+
Lesson 2.3: PARTIALS UNDER CURSOR
158+
159+
** gf to jump to partial definition. **
160+
161+
1. Execute :Vcontroller users.
162+
163+
2. Move the cursor to the 'layout :users' line.
164+
165+
3. Press gf . This will take you to the Users layout.
166+
167+
4. Move the cursor to point to any character of the partial name on line 4.
168+
169+
Note: If you place the cursor anywhere besides within 'shared/tim_pope',
170+
the above will not work, as there will be no definition file to
171+
look for.
172+
173+
5. Press CTRL-W CTRL-F . This will open the partial in a new vertical
174+
split window.
175+
176+
6. Execute :q to close that window.
177+
178+
179+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180+
181+
Lesson 2.4: PATHS UNDER CURSOR
182+
183+
** gf to jump to path`s controller action. **
184+
185+
1. This example builds on the example in Lesson 2.3. If you are starting
186+
this lesson from scratch, execute :Vlayout users .
187+
188+
2. Move the cursor to 'new_comment_path'.
189+
190+
3. Press gf to go to the matching action for this path.
191+
Note from the documentation:
192+
"""
193+
[T]he controller and action for the named route are
194+
determined by evaluating routes.rb as Ruby and doing some
195+
introspection. This means code from the application is executed.
196+
Keep this in mind when navigating unfamiliar applications.
197+
"""
198+
199+
4. Execute :q to close the working window.
200+
201+
202+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203+
204+
Lesson 2 SUMMARY
205+
206+
1. The gf command which normally edits the file under the cursor, has
207+
been remapped to take Rails context into account.
208+
209+
2. In some cases (i.e.: gf on a path [Lesson 2.4]) code from the Rails
210+
application is executed to determine the correct mapping.
211+
212+
3. Besides gf the following related commands have also been remapped
213+
to take Rails context into account:
214+
215+
* CTRL-W f - opens file in new window
216+
* CTRL-W gf - opens file in new tab
217+
* c_CTRL-R CTRL-F - inserts filename on command line
218+
219+
4. For a full list of gf mappings, please refer to the rails.vim docs.
220+
221+
222+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223+
224+
Lesson 3.1: RELATED FILES
225+
226+
** Jumping to Related files with :R .**
227+
228+
1. Execute :Vcontroller comments .
229+
230+
2. Place the cursor on the first line or any line between methods.
231+
232+
3. Execute :R . This will take you to the Comments controller related
233+
file, which in this case is the Comments helper.
234+
235+
4. Press CTRL-O to jump back to the Comments controller.
236+
237+
5. Move the cursor to any of the action methods in the Comments controller.
238+
239+
6. Execute :R . This will take you to the controller action's related view.
240+
241+
7. Now execute :R from the view. This will send you back to the Comments
242+
controller.
243+
244+
8. Execute :q to close the working window.
245+
246+
247+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248+
249+
Lesson 3.2: ALTERNATE FILES
250+
251+
** Jumping to Alternate files with :A . **
252+
253+
1. Execute :Vcontroller comments .
254+
255+
2. Execute :A anywhere in the file. This will take you to the functional
256+
test for that controller.
257+
258+
3. Execute :A again. This will take you back to the controller.
259+
260+
4. Execute :Emodel comment .
261+
262+
5. Execute :A to go to the unit test for the Comment model.
263+
264+
6. Execute :A to go back to the Comment model.
265+
266+
267+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
268+
269+
Lesson 3 SUMMARY
270+
271+
1. The Alternate file :A is usually the test file or whatever the test
272+
file is designed to test.
273+
274+
2. The Related file :R is useful for navigating to views and templates.
275+
276+
3. For a full list of the Alternate and Related file mappings, please
277+
refer to the rails.vim docs.
278+
279+
4. :A and :R can be used in the following ways:
280+
281+
* :AE - same as :A . Edits the file in the same window.
282+
* :AS - opens the file in a horizontal split window.
283+
* :AV - opens the file in a vertical split window.
284+
* :AT - opens the file in a new tab.
285+
* :AD - reads file in the current buffer.
286+
287+
The same postfixes can be applied to the :R command as well.
288+
289+
290+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291+
292+
Lesson 4.1: RAKE FOR TESTS
293+
294+
** Using :Rake to execute related tests. **
295+
296+
1. Open the Comment model in a new window using :Vmodel comment .
297+
298+
2. Execute :Rake . This will run the tests related to your model.
299+
300+
3. Execute :A to go to the actual Comment unit tests.
301+
302+
4. Execute :Rake to run the Comment unit tests again.
303+
304+
5. Go to the Comments controller by executing :Econtroller comments .
305+
306+
6. Execute :Rake to run the functional tests for that controller.
307+
308+
7. :A to jump to the functional tests.
309+
310+
8. :Rake to run the functional tests again.
311+
312+
9. Execute :q to close the working window.
313+
314+
315+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
316+
317+
Lesson 4.2: RAKE FOR TASKS
318+
319+
** Using :Rake to execute tasks. **
320+
321+
1. In this window execute :Rake routes. As expected you should see
322+
the output of the 'rake routes' command.
323+
324+
2. Execute :Rake - to run the last executed command.
325+
326+
327+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328+
329+
Lesson 4 SUMMARY
330+
331+
1. Use :Rake to execute the current model, controller, helper test.
332+
When no argument is passed :Rake defaults to something sensible.
333+
For a full list refer to the rails.vim docs.
334+
335+
2. :Rake without arguments will also run rspec specs.
336+
337+
3. Pass an argument to :Rake in order to execute any rake task.
338+
339+
4. Use :Rake - to re-run the last :Rake call.
340+
341+

tutor/sample_rails5_app/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore the default SQLite database.
11+
/db/*.sqlite3
12+
/db/*.sqlite3-journal
13+
14+
# Ignore all logfiles and tempfiles.
15+
/log/*
16+
/tmp/*
17+
!/log/.keep
18+
!/tmp/.keep
19+
20+
# Ignore Byebug command history file.
21+
.byebug_history
22+
23+
.rspec
24+

0 commit comments

Comments
 (0)