Created
January 23, 2012 17:16
-
-
Save thejefflarson/1664329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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