Skip to content

Instantly share code, notes, and snippets.

@tizoc
Created August 18, 2011 22:19
Show Gist options
  • Save tizoc/1155408 to your computer and use it in GitHub Desktop.
Save tizoc/1155408 to your computer and use it in GitHub Desktop.
def mote(template, params = {})
variables = mote_process_variables(mote_cache, template, params)
mote_cache[template] ||= Mote.parse(template, self, variables)
mote_cache[template][params]
end
def mote_file(filename, params = {})
variables = mote_process_variables(mote_files, filename, params)
mote_files[filename] ||= Mote.parse(File.read(filename), self, variables)
mote_files[filename][params]
end
def mote_process_variables(cache, key, params)
variables = Set.new(params.keys.map &:to_sym)
seen_variables = mote_template_variables[key]
unless (variables - seen_variables).empty?
seen_variables += variables
cache.delete(key)
end
seen_variables
end
def mote_template_variables
@_mote_template_variables ||= Hash.new{|h, k| h[k] = Set.new}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment