Created
June 21, 2010 19:12
-
-
Save mikewadhera/447328 to your computer and use it in GitHub Desktop.
This file contains 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
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