Allow Convertibles to be converted by >= 1 converters.
This commit is contained in:
parent
b00c5e9587
commit
d004bc4ea5
|
@ -62,27 +62,36 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def transform
|
||||
self.content = converter.convert(content)
|
||||
converters.reduce(content) do |output, converter|
|
||||
begin
|
||||
converter.convert output
|
||||
rescue => e
|
||||
Jekyll.logger.error "Conversion error:", "There was an error converting" +
|
||||
" '#{path}'."
|
||||
Jekyll.logger.error "Conversion error:", "#{converter.class} encountered an error converting '#{path}'."
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Determine the extension depending on content_type.
|
||||
#
|
||||
# Returns the String extension for the output file.
|
||||
# e.g. ".html" for an HTML output file.
|
||||
def output_ext
|
||||
converter.output_ext(ext)
|
||||
if converters.all? { |c| c.is_a?(Jekyll::Converters::Identity) }
|
||||
ext
|
||||
else
|
||||
converters.map {|c|
|
||||
c.output_ext(ext) unless c.is_a?(Jekyll::Converters::Identity)
|
||||
}.compact.uniq.join("")
|
||||
end
|
||||
end
|
||||
|
||||
# Determine which converter to use based on this convertible's
|
||||
# extension.
|
||||
#
|
||||
# Returns the Converter instance.
|
||||
def converter
|
||||
@converter ||= site.converters.find { |c| c.matches(ext) }
|
||||
def converters
|
||||
@converters ||= site.converters.select { |c| c.matches(ext) }.sort
|
||||
end
|
||||
|
||||
# Render Liquid in the content
|
||||
|
@ -159,7 +168,7 @@ module Jekyll
|
|||
#
|
||||
# Returns true if the layout is invalid, false if otherwise
|
||||
def invalid_layout?(layout)
|
||||
!data["layout"].nil? && data["layout"] != "none" && layout.nil? && !(self.is_a? Jekyll::Excerpt)
|
||||
!data["layout"].nil? && layout.nil? && !(self.is_a? Jekyll::Excerpt)
|
||||
end
|
||||
|
||||
# Recursively render layouts
|
||||
|
@ -205,11 +214,11 @@ module Jekyll
|
|||
info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page => payload['page'] } }
|
||||
|
||||
# render and transform content (this becomes the final content of the object)
|
||||
payload["highlighter_prefix"] = converter.highlighter_prefix
|
||||
payload["highlighter_suffix"] = converter.highlighter_suffix
|
||||
payload["highlighter_prefix"] = converters.first.highlighter_prefix
|
||||
payload["highlighter_suffix"] = converters.first.highlighter_suffix
|
||||
|
||||
self.content = render_liquid(content, payload, info) if render_with_liquid?
|
||||
transform
|
||||
self.content = transform
|
||||
|
||||
# output keeps track of what will finally be written
|
||||
self.output = content
|
||||
|
|
|
@ -56,6 +56,15 @@ module Jekyll
|
|||
PRIORITIES[other.priority] <=> PRIORITIES[self.priority]
|
||||
end
|
||||
|
||||
# Spaceship is priority [higher -> lower]
|
||||
#
|
||||
# other - The class to be compared.
|
||||
#
|
||||
# Returns -1, 0, 1.
|
||||
def <=>(other)
|
||||
self.class <=> other.class
|
||||
end
|
||||
|
||||
# Initialize a new plugin. This should be overridden by the subclass.
|
||||
#
|
||||
# config - The Hash of configuration options.
|
||||
|
|
|
@ -342,9 +342,7 @@ class TestPost < Test::Unit::TestCase
|
|||
should "transform textile" do
|
||||
@post.process(@real_file)
|
||||
@post.read_yaml(@source, @real_file)
|
||||
@post.transform
|
||||
|
||||
assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.content
|
||||
assert_equal "<h1>{{ page.title }}</h1>\n<p>Best <strong>post</strong> ever</p>", @post.transform
|
||||
end
|
||||
|
||||
context "#excerpt" do
|
||||
|
@ -642,41 +640,41 @@ class TestPost < Test::Unit::TestCase
|
|||
|
||||
should "process .md as markdown under default configuration" do
|
||||
post = setup_post '2011-04-12-md-extension.md'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Markdown
|
||||
end
|
||||
|
||||
should "process .text as identity under default configuration" do
|
||||
post = setup_post '2011-04-12-text-extension.text'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Identity
|
||||
end
|
||||
|
||||
should "process .text as markdown under alternate configuration" do
|
||||
@site.config['markdown_ext'] = 'markdown,mdw,mdwn,md,text'
|
||||
post = setup_post '2011-04-12-text-extension.text'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Markdown
|
||||
end
|
||||
|
||||
should "process .md as markdown under alternate configuration" do
|
||||
@site.config['markdown_ext'] = 'markdown,mkd,mkdn,md,text'
|
||||
post = setup_post '2011-04-12-text-extension.text'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Markdown
|
||||
end
|
||||
|
||||
should "process .mkdn under text if it is not in the markdown config" do
|
||||
@site.config['markdown_ext'] = 'markdown,mkd,md,text'
|
||||
post = setup_post '2013-08-01-mkdn-extension.mkdn'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Identity
|
||||
end
|
||||
|
||||
should "process .text as textile under alternate configuration" do
|
||||
@site.config['textile_ext'] = 'textile,text'
|
||||
post = setup_post '2011-04-12-text-extension.text'
|
||||
conv = post.converter
|
||||
conv = post.converters.first
|
||||
assert conv.kind_of? Jekyll::Converters::Textile
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue