Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created January 23, 2012 17:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejefflarson/1664329 to your computer and use it in GitHub Desktop.
Save thejefflarson/1664329 to your computer and use it in GitHub Desktop.
require 'open-uri'
class RemoteSnippets
class << self
def get(key)
url = @mappings[key]
open(url).read
end
def register(key, url)
@mappings ||= {}
@mappings[key] = url
end
def []=(key, url)
register key, url
end
def [](key)
get key
end
end
end
# usage:
# in an initializer create some mappings:
# RemoteSnippets.register("header", "http://www.propublica.org/rails/header")
#
# or
#
# RemoteSnippets["header"] = "http://www.propublica.org/rails/header"
#
# and then in templates use either:
#
# RemoteSnippets.get("header")
#
# or
#
# RemoteSnippets["header"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment