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 by @edp02:

Unlock 6 remaining solutions by signing in and submitting your own entry
Created by: @wondible

23 active golfers, 48 entries

Solutions by @edp02:
160
#5 - ゆきみ / @edp02

02/26/2014 at 01:48PM

161
#>5 - ゆきみ / @edp02

02/26/2014 at 01:01PM

164
#>5 - ゆきみ / @edp02

02/26/2014 at 11:12AM

181
#>7 - ゆきみ / @edp02

02/24/2014 at 01:17PM

188
#>7 - ゆきみ / @edp02

02/24/2014 at 01:10PM

198
#>7 - ゆきみ / @edp02

02/24/2014 at 11:32AM