Class: Ace::TemplateFilter
- Defined in:
- lib/ace/filters/layout.rb,
lib/ace/filters/template.rb
Defined Under Namespace
Classes: Scope
Class Method Summary collapse
Instance Method Summary collapse
- #call(item, content) ⇒ Object
-
#initialize(options = Hash.new) ⇒ TemplateFilter
constructor
A new instance of TemplateFilter.
Constructor Details
#initialize(options = Hash.new) ⇒ TemplateFilter
Returns a new instance of TemplateFilter.
18 19 20 |
# File 'lib/ace/filters/template.rb', line 18 def initialize( = Hash.new) @layout = [:layout] if .has_key?(:layout) end |
Class Method Details
.add_to_paths(directory) ⇒ Object
12 13 14 15 16 |
# File 'lib/ace/filters/template.rb', line 12 def self.add_to_paths(directory) unless TemplateInheritance::Template.paths.include?(directory) TemplateInheritance::Template.paths.unshift(directory) end end |
Instance Method Details
#call(item, content) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ace/filters/template.rb', line 22 def call(item, 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(".") if parts.length == 2 # template.haml item.output_path = "#{parts[0]}.html" elsif parts.length == 3 # template.html.haml or template.xml.haml item.output_path = "#{parts[0]}.#{parts[1]}" else 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) return template.render(item: item) end |