Skip to content

Instantly share code, notes, and snippets.

@etrepum
Created March 13, 2014 00:29
Show Gist options
  • Save etrepum/9519609 to your computer and use it in GitHub Desktop.
Save etrepum/9519609 to your computer and use it in GitHub Desktop.
Sinatra helper to add a url_escape method
helpers do
def escape(text)
Rack::Utils.escape_html(text)
end
def url_escape(text)
chunks = []
after = text
while after != "" do
before, match, after = after.partition(URI.regexp)
if before != ""
chunks.push(escape(before))
end
if match != ""
chunks.push("<a href=\"#{match}\">#{match}</a>")
end
end
chunks.join
end
alias_method :h, :escape
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment