Skip to content

Instantly share code, notes, and snippets.

@mikewadhera
Created June 21, 2010 19:12
Show Gist options
  • Save mikewadhera/447328 to your computer and use it in GitHub Desktop.
Save mikewadhera/447328 to your computer and use it in GitHub Desktop.
def sml_attr(name, options={)
# Same as before
if options[:default].respond_to?(:call)
define_method sml_method(attribute), options[:default]
elsif options[:default].nil?
define_method sml_method(attribute), lambda {self.send(attribute)}
end
self.sml_attributes.push(attribute) if !self.sml_attributes.include?(attribute)
# Do what liquid_methods(*args) does but instead call the sml version of the method
drop_class = eval "class #{self.to_s}::SmlLiquidDropClass < Liquid::Drop; self; end"
define_method :to_liquid do
drop_class.new(self)
end
drop_class.class_eval do
def initialize(object)
@object = object
end
allowed_methods.each do |sym|
define_method sym do
@object.send @object.class.sml_method(sym)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment