Here is an Textmate snippet that allows you to easily convert HTML and ERB templates to Haml. It also re-converts certain characters back to their normal form after conversion (for some reason html2haml converts stuff like less-than signs and quotes to their HTML character code, ugh).
RSpec and Block-Based View Helpers
Block-based view helpers are a great way to cut down on repetitive HTML chores and DRY up your view code. They are normally rather simple methods that basically stick some content in the middle of HTML code.
Here is a block-based view helper that I use in one of my applications:
# application_helper.rb
# Generic form label styling
def box_label(text)
text = "#{text}:" unless text.end_with?(":")
"<span class=\"box_label\">#{text}</span>"
end
# A generic box to encapsulate some text
def box(title = nil, *args, &block)
options = args.extract_options!
style = options[:style] ? " style = '#{options[:style]}'" : ''
b = "<div class=\"box\"#{style}>#{box_label(title) if title}"
e = '</div>'
data = capture(&block)
res = b + data + e
concat(res, block.binding)
end
Now we can call the "box" helper in a view:
# /some_object/show.html.erb
<% box('Name:') do %>
<%=h @some_object.name %>
<% end %>
and it will actually render this:
<div class="box">
<span class="box_label">Name:</span>
J080119 - Technology Department
</div>
Pretty sweet, right?
It is until you go to spec out your views with RSpec. After some obligatory Googlin' I didn't find much. It seems as though the block doesn't do it's thing when RSpec calls it via the "render" call in your view specs.
So where does this leave us? Time for a custom Matcher;. Relax, it's pretty easy, but it does involve working with a regular expression. Rubular; is a great place to work with your REfu in real time. I highly recommend using it for your Matcher#matches method.
First things first: Crack open that spec_helper.rb file and lets create a new Matcher module that will test our "box" helper:
# spec_helper.rb
module BoxMatcher
class Box
def initialize(name)
@name = name
end
def matches?(actual)
raise "You must supply a 'containing' attribute (.containing 'foo')" unless @contents
@actual = actual
# ___Here is where the real magic happens___
# It is simply a regular expression that tests our
# expectations (the rendered HTML from the 'box' method)
# against what the response actually rendered
# If it matches, we have a passing spec.
@actual.body =~ /<div class="box"><span class="box_label">#{@name}:</span>.*#{@contents}.*n</div>/im
end
def containing(contents)
@contents = contents
self
end
def failure_message
"expected response to have a box describing '#{@name}', but it didn't"
end
def negative_failure_message
"expected response to not have a box describing '#{@name}', but it did"
end
end
def have_box_named(name)
Box.new(name)
end
end
...
Spec::Runner.configure do |config|
...
# Include our new Matcher module
config.include BoxMatcher, :type => :view
end
You can now test the rendering of your block-based view helper via something like:
# some_object.html.erb_spec.rb
it "should render 'bleh' in a box named 'meh'" do
render "/some_object/show.html.erb"
response.should have_box_named("meh").containing('bleh')
end
An Open Letter about Recorded Political Phonecalls
It's just so neat that the Governor or some random Senator is calling little-ole-me!
Your pre-recorded political phone call has single-handedly convinced me to change my political stance and views on life. Thank you for making me see the light in those amazing twenty seconds. Who knew that a phone call could do so much.
Your masterful use of mechanized war dailing and not using real, live, people to spread your word is astounding. It shows that you know how to get things done. Bravo.
I understand that there is an election going on; and yes, I understand that you're just trying to "let everyone know about your great policies". I appreciate that you time your pre-recorded messages of political candor so precisely with my dinner time, or when I get a chance to stretch out on the couch. I'm glad that I get to get off of my ass and walk aross the house to get the phone three times a night.
Please. Stop.
Frustration 2
Taken from: www.kevinwilliampang.com
Very few programmers can go from 0 to code at the drop of a hat. In general, we tend to be more akin to locomotives than ferraris; it may take us awhile to get started, but once we hit our stride we can get an impressive amount of work done. Unfortunately, it's very hard to get into a programming zone when your train of thought is constantly being derailed by clients, managers, and fellow programmers.
There is simply too much information we need to keep in mind while we're working on a task to be able to drop the task, handle another issue, then pick up the task without missing a beat. Interruptions kill our train of thought and getting it back is often a time-consuming, frustrating, and worst of all, error-prone process.
acts_as_video_fu
ActsAsVideoFu
=============
Rails plugin that easily allows you to show video streams on your site. Currently, YouTube and Vimeo streams are
supported.
#video_url is expected to be in these formats:
YouTube: http://www.youtube.com/watch?v=gEILFf2XSrM
Vimeo: http://vimeo.com/726135
Example
=======
./script/generate scaffold Video title:string video_url:string
#video.rb
class Video < ActiveRecord::Base
acts_as_video_fu
end
Video.create!(:title => "Some Title", :video_url => "http://www.youtube.com/watch?v=gEILFf2XSrM")
#show.html.erb
<%= display_video(@video) %>
Available on Github
The Me Meme

1.Take a picture of yourself right now.
2. Don’t change your clothes, don’t fix your hair…just take a picture. (should be super-easy with Photobooth)
3. Post that picture with NO editing.
4 Post these instructions with your picture.













