[#604] Add base drop

This commit is contained in:
Holger Just 2011-11-19 23:31:58 +01:00
parent 4289559b5f
commit 7261622196
2 changed files with 26 additions and 0 deletions

23
app/drops/base_drop.rb Normal file
View File

@ -0,0 +1,23 @@
class BaseDrop < Liquid::Drop
def initialize(object)
@object = object unless object.respond_to?(:visible?) && !object.visible?
end
# Defines a Liquid method on the drop that is allowed to call the
# Ruby method directly. Best used for attributes.
#
# Based on Module#liquid_methods
def self.allowed_methods(*allowed_methods)
class_eval do
allowed_methods.each do |sym|
define_method sym do
if @object.respond_to?(:public_send)
@object.public_send(sym) rescue nil
else
@object.send(sym) rescue nil
end
end
end
end
end
end

View File

@ -49,6 +49,9 @@ Rails::Initializer.run do |config|
# (by default production uses :info, the others :debug)
# config.log_level = :debug
# Liquid drops
config.autoload_paths += %W( #{RAILS_ROOT}/app/drops )
# Enable page/fragment caching by setting a file-based store
# (remember to create the caching directory and make it readable to the application)
# config.action_controller.cache_store = :file_store, "#{RAILS_ROOT}/tmp/cache"