Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 4e7dedb4f447090001000002

Refactor to Helpers

This Rails partial is almost all template escapes. Put it into a helper, and refactor each case to methods so we can build out the controls for each. (I've converted to tabs - fighting with Vimgolf's default config shouldn't be part of the challenge.)

Start file
## _controls.html.erb
<div class='controls'>
	<% if event.author == current_user -%>
		<%= link_to "Edit Activity", edit_event_path(event), :class => 'button' %>
	<% else -%>
		<% if current_user.attending? event -%>
			<%= link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post %>
		<% else -%>
			<% if current_user.invited_to? event -%>
				<%= link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post %>
			<% else -%>
				<%= link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post %>
			<% end -%>
		<% end -%>
	<% end -%>
</div>

## event_helper.rb
module EventHelper
end
End file
## _controls.html.erb
<div class='controls'>
	<%= event_controls event %>
</div>

## event_helper.rb
module EventHelper
	def event_controls(event)
		if event.author == current_user
			author_controls(event)
		elsif current_user.attending? event
			attendee_controls(event)
		elsif current_user.invited_to? event
			invitee_controls(event)
		else
			public_controls(event)
		end
	end

	def author_controls(event)
		link_to "Edit Activity", edit_event_path(event), :class => 'button'
	end

	def attendee_controls(event)
		link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post
	end

	def invitee_controls(event)
		link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post
	end

	def public_controls(event)
		link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post
	end
end

View Diff

3,15c3
< 	<% if event.author == current_user -%>
< 		<%= link_to "Edit Activity", edit_event_path(event), :class => 'button' %>
< 	<% else -%>
< 		<% if current_user.attending? event -%>
< 			<%= link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post %>
< 		<% else -%>
< 			<% if current_user.invited_to? event -%>
< 				<%= link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post %>
< 			<% else -%>
< 				<%= link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post %>
< 			<% end -%>
< 		<% end -%>
< 	<% end -%>
---
> 	<%= event_controls event %>
19a8,34
> 	def event_controls(event)
> 		if event.author == current_user
> 			author_controls(event)
> 		elsif current_user.attending? event
> 			attendee_controls(event)
> 		elsif current_user.invited_to? event
> 			invitee_controls(event)
> 		else
> 			public_controls(event)
> 		end
> 	end
> 
> 	def author_controls(event)
> 		link_to "Edit Activity", edit_event_path(event), :class => 'button'
> 	end
> 
> 	def attendee_controls(event)
> 		link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post
> 	end
> 
> 	def invitee_controls(event)
> 		link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post
> 	end
> 
> 	def public_controls(event)
> 		link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post
> 	end

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 23 remaining solutions by signing in and submitting your own entry
#24 Pavlo Klets / @p01nt - Score: 855 - 10/27/11 @ 21:47
jdG:se paste<CR>o<div class='controls'><CR><Tab><%= event_controls event %><CR></div><CR><CR>## event_helper.rb<CR>module EventHelper<CR><Tab>def event_controls(event)<CR><Tab><Tab>if event.author == current_user<CR><Tab><Tab><Tab>author_controls(event)<CR><Tab><Tab>elsif current_user.attending? event<CR><Tab><Tab><Tab>attendee_controls(event)<CR><Tab><Tab>elsif current_user.invited_to? event<CR><Tab><Tab><Tab>invitee_controls(event)<CR><Tab><Tab>else<CR><Tab><Tab><Tab>public_controls(event)<CR><Tab><Tab>end<CR><Tab>end<CR><CR><Tab>def author_controls(event)<CR><Tab><Tab>link_to "Edit Activity", edit_event_path(event), :class => 'button'<CR><Tab>end<CR><CR><Tab>def attendee_controls(event)<CR><Tab><Tab>link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post<CR><Tab>end<CR><CR><Tab>def invitee_controls(event)<CR><Tab><Tab>link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR><CR><Tab>def public_controls(event)<CR><Tab><Tab>link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR>end<Esc>ZZ

0 comments


#25 nickGPT / @nickandbro - Score: 855 - 08/28/24 @ 22:30
jdG:se paste<CR>o<div class='controls'><CR><Tab><%= event_controls event %><CR></div><CR><CR>## event_helper.rb<CR>module EventHelper<CR><Tab>def event_controls(event)<CR><Tab><Tab>if event.author == current_user<CR><Tab><Tab><Tab>author_controls(event)<CR><Tab><Tab>elsif current_user.attending? event<CR><Tab><Tab><Tab>attendee_controls(event)<CR><Tab><Tab>elsif current_user.invited_to? event<CR><Tab><Tab><Tab>invitee_controls(event)<CR><Tab><Tab>else<CR><Tab><Tab><Tab>public_controls(event)<CR><Tab><Tab>end<CR><Tab>end<CR><CR><Tab>def author_controls(event)<CR><Tab><Tab>link_to "Edit Activity", edit_event_path(event), :class => 'button'<CR><Tab>end<CR><CR><Tab>def attendee_controls(event)<CR><Tab><Tab>link_to "Leave", leave_event_path(event), :class => "button neg", :method => :post<CR><Tab>end<CR><CR><Tab>def invitee_controls(event)<CR><Tab><Tab>link_to "Accept Invite", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR><CR><Tab>def public_controls(event)<CR><Tab><Tab>link_to "I'm Going", join_event_path(event), :class => "button pos", :method => :post<CR><Tab>end<CR>end<Esc>ZZ

0 comments


Created by: @wondible

25 active golfers, 50 entries

Leaderboard (lowest score wins):
147
#1 - Urtica dioica / @udioica

07/15/2013 at 01:20AM

147
#2 - Aaron Fresh / @AaronFresh7

09/13/2014 at 09:05PM

147
#3 - Peppa Pig / @PeppaPi95550250

07/03/2024 at 07:56AM

148
#4 - Justin Love / @wondible

12/24/2011 at 04:45AM

158
#5 - John Anderson / @opejn

12/25/2011 at 07:53AM

160
#6 - ゆきみ / @edp02

02/26/2014 at 01:48PM

171
#7 - h_east (トロッコ6個) / @h_east

10/02/2011 at 05:49AM

176
#8 - Abdel Said / @abdelsaid

02/17/2012 at 03:02PM

210
#9 - William Dunand / @wdunand

02/28/2012 at 06:29AM

242
#10 - RobertT / @techrt2050

10/10/2013 at 07:08AM

242
#11 - 杨洋 / @176795444

07/02/2017 at 07:35AM

286
#12 - Vasil Sakarov / @vsakarov

12/28/2011 at 11:38AM

286
#13 - galadriel2143 / @galadriel2143

07/04/2013 at 07:38AM

288
#14 - maxthoursie / @maxthoursie

01/31/2012 at 08:49AM

297
#15 - Yongho / @YONG_HO

07/09/2013 at 03:02AM

325
#16 - i5513 / @i5513

04/26/2015 at 10:01PM

352
#17 - Jonathan Lozinski / @jlozinski

04/21/2012 at 06:07PM

355
#18 - shahanavaz m / @shahanavazm

03/16/2024 at 12:41AM

386
#19 - magizbox / @rain_1024

07/12/2014 at 08:25AM

407
#20 - Ivan Brennan / @ivanbrennan

08/24/2014 at 11:24PM

423
#21 - You-Siang Lin / @yslinnctu

12/15/2011 at 12:58AM

484
#22 - Rob C. Grant / @rob_c_grant

02/01/2012 at 06:39PM

817
#23 -  River / @glacialrd

11/08/2014 at 10:17AM

855
#24 - Pavlo Klets / @p01nt

10/27/2011 at 09:47PM

855
#25 - nickGPT / @nickandbro

08/28/2024 at 10:30PM