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