Skip to content

Instantly share code, notes, and snippets.

@cyx
Forked from tizoc/recompile_vars.rb
Created August 23, 2011 22:54
Show Gist options
  • Save cyx/1166839 to your computer and use it in GitHub Desktop.
Save cyx/1166839 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