From 7261622196470f8a36c34c5e1b3ce944df9670fa Mon Sep 17 00:00:00 2001 From: Holger Just Date: Sat, 19 Nov 2011 23:31:58 +0100 Subject: [PATCH] [#604] Add base drop --- app/drops/base_drop.rb | 23 +++++++++++++++++++++++ config/environment.rb | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 app/drops/base_drop.rb diff --git a/app/drops/base_drop.rb b/app/drops/base_drop.rb new file mode 100644 index 00000000..18355cc1 --- /dev/null +++ b/app/drops/base_drop.rb @@ -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 diff --git a/config/environment.rb b/config/environment.rb index 3c174193..0ae61ffe 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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"