Skip to content

@thejefflarson /remote-snippets.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.