diff --git a/lib/ace.rb b/lib/ace.rb index be24e20..025b98d 100644 --- a/lib/ace.rb +++ b/lib/ace.rb @@ -51,8 +51,14 @@ module Ace class Item def self.inherited(subclass) self.subclasses << subclass - subclass.before_filters.push(*self.before_filters) - subclass.after_filters.push(*self.after_filters) + + self.before_filters.each do |instance| + subclass.before_filters << instance.dup + end + + self.after_filters.each do |instance| + subclass.after_filters << instance.dup + end end def self.subclasses diff --git a/lib/ace/filters/template.rb b/lib/ace/filters/template.rb index 9344028..1443d60 100644 --- a/lib/ace/filters/template.rb +++ b/lib/ace/filters/template.rb @@ -16,12 +16,31 @@ module Ace end def initialize(options = Hash.new) - @path = options[:layout] + @layout = options[:layout] if options.has_key?(:layout) end def call(item, content) - if @path.nil? - @path = item.original_path.sub("content/", "") + path = @layout || item.original_path.sub(/content\//, "") # We remove content/, because content is in TI paths. + if path.nil? + raise <<-EOF.gsub(/ {10}/m, "") + You have to specify output_path of #{self.inspect} + + Usage: + + class Post < Ace::Item + before Ace::TemplateFilter, layout: "posts.html" + end + + # OR: + + class Post < Ace::Item + before Ace::TemplateFilter + + # And have #original_path set up (Ace does it by default, + # but if you are using some custom code it might not work + # out of the box). + end + EOF end parts = item.output_path.split(".") @@ -33,7 +52,7 @@ module Ace raise "Template can be named either with one suffix as template.haml or with two of them as template.html.haml resp. template.xml.haml." end - template = TemplateInheritance::Template.new(@path, Scope.new) + template = TemplateInheritance::Template.new(path, Scope.new) return template.render(item: item) end end diff --git a/lib/ace/version.rb b/lib/ace/version.rb index 9ccb4bd..654189d 100644 --- a/lib/ace/version.rb +++ b/lib/ace/version.rb @@ -1,5 +1,5 @@ # encoding: utf-8 module Ace - VERSION = "0.3.2" + VERSION = "0.3.3" end