LayoutFilter is deprecated from now on.
This commit is contained in:
parent
b5ae0a7562
commit
cd2273da6f
|
@ -8,7 +8,7 @@ require "ace/filters"
|
|||
# - metadata
|
||||
# - config
|
||||
class Post < Ace::Item
|
||||
before Ace::LayoutFilter, layout: "post.html"
|
||||
before Ace::TemplateFilter, layout: "post.html"
|
||||
|
||||
def document
|
||||
Nokogiri::HTML(self.content)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class Tag < Ace::Item
|
||||
before Ace::LayoutFilter, layout: "tag.html"
|
||||
before Ace::TemplateFilter, layout: "tag.html"
|
||||
end
|
||||
|
||||
class TagPagesGenerator
|
||||
|
|
|
@ -1,26 +1,10 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require "ace/filters"
|
||||
require "template-inheritance"
|
||||
require_relative "template"
|
||||
|
||||
layouts = File.join(Dir.pwd, "layouts")
|
||||
unless TemplateInheritance::Template.paths.include?(layouts)
|
||||
TemplateInheritance::Template.paths.unshift(layouts)
|
||||
end
|
||||
warn "~ TemplateFilter is deprecated, use TemplateFilter from now on."
|
||||
|
||||
module Ace
|
||||
class LayoutFilter < Filter
|
||||
class Scope
|
||||
include Ace::Helpers
|
||||
end
|
||||
|
||||
def initialize(options)
|
||||
@path = options[:layout]
|
||||
end
|
||||
|
||||
def call(item, content)
|
||||
template = TemplateInheritance::Template.new(@path, Scope.new)
|
||||
return template.render(item: item)
|
||||
end
|
||||
class TemplateFilter < TemplateFilter
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,25 +3,41 @@
|
|||
require "ace/filters"
|
||||
require "template-inheritance"
|
||||
|
||||
layouts = File.join(Dir.pwd, "layouts")
|
||||
unless TemplateInheritance::Template.paths.include?(layouts)
|
||||
TemplateInheritance::Template.paths.unshift(layouts)
|
||||
end
|
||||
|
||||
TemplateInheritance::Template.paths << File.join(Dir.pwd, "content")
|
||||
|
||||
module Ace
|
||||
class TemplateFilter < Filter
|
||||
TEMPLATE_EXTS_PATTERN = /\.(haml|erb|erubis)$/i
|
||||
class Scope
|
||||
include Ace::Helpers
|
||||
end
|
||||
|
||||
def self.add_to_paths(directory)
|
||||
unless TemplateInheritance::Template.paths.include?(directory)
|
||||
TemplateInheritance::Template.paths.unshift(directory)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(options = Hash.new)
|
||||
@path = options[:layout]
|
||||
end
|
||||
|
||||
def call(item, content)
|
||||
if item.output_path.match(TEMPLATE_EXTS_PATTERN)
|
||||
item.output_path = item.output_path.split(".")[0..-2].join(".")
|
||||
if @path.nil?
|
||||
@path = item.original_path.sub("content/", "")
|
||||
end
|
||||
|
||||
relative_path = item.original_path.sub("content/", "")
|
||||
template = TemplateInheritance::Template.new(relative_path)
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
Ace::TemplateFilter.add_to_paths(File.join(Dir.pwd, "layouts"))
|
||||
Ace::TemplateFilter.add_to_paths(File.join(Dir.pwd, "content"))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module Ace
|
||||
VERSION = "0.3"
|
||||
VERSION = "0.3.2"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue