Skip to content

Instantly share code, notes, and snippets.

@jhammann
Created September 11, 2013 14:46
Show Gist options
  • Select an option

  • Save jhammann/6524675 to your computer and use it in GitHub Desktop.

Select an option

Save jhammann/6524675 to your computer and use it in GitHub Desktop.
A ruby helper that puts the first letter of a string (like a name) in a span to give it a special styling. For example: you want the first letter of a lastname in a special font, this helper creates a span that enables that.
def span_capitalize(string)
name = string.match(/(^[a-z])(.*)/i)
first_letter = name[1]
rest = name[2]
content_tag(:span, first_letter) + rest
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment