Skip to content

Instantly share code, notes, and snippets.

@marcroberts
marcroberts / simple_format_with_hypenation.rb
Created August 28, 2009 15:35
Add soft hyphens every 6 characters to words longer than 7 characters
module ActionView
module Helpers
module TextHelper
def simple_format_with_hyphenation(text, html_options={})
simple_format_without_hyphenation(text.gsub(/(\w{6})(\w)/,'\1­\2'), html_options)
end
alias_method_chain :simple_format, :hyphenation
@marcroberts
marcroberts / shrtn.rb
Created August 6, 2009 18:39
Rack Middleware to generate short URLs for a model
# drop in /lib in a rails app
# replace MODEL with the model to run against
# enable in environment.rb with:
# config.middleware.use 'Shrtn::Middleware'
module Shrtn
class Helper
include Singleton
def initialize
@chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['-','_']