Improve Site#getConverterImpl and call it Site#find_converter_instance

This commit is contained in:
Parker Moore 2014-12-28 14:12:09 -05:00
parent 657b16519e
commit 0c0aea3ad7
2 changed files with 6 additions and 11 deletions

View File

@ -10,7 +10,7 @@ module Jekyll
# Returns the HTML formatted String. # Returns the HTML formatted String.
def textilize(input) def textilize(input)
site = @context.registers[:site] site = @context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Textile) converter = site.find_converter_instance(Jekyll::Converters::Textile)
converter.convert(input) converter.convert(input)
end end
@ -21,7 +21,7 @@ module Jekyll
# Returns the HTML formatted String. # Returns the HTML formatted String.
def markdownify(input) def markdownify(input)
site = @context.registers[:site] site = @context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Markdown) converter = site.find_converter_instance(Jekyll::Converters::Markdown)
converter.convert(input) converter.convert(input)
end end
@ -32,7 +32,7 @@ module Jekyll
# Returns the CSS formatted String. # Returns the CSS formatted String.
def sassify(input) def sassify(input)
site = @context.registers[:site] site = @context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Sass) converter = site.find_converter_instance(Jekyll::Converters::Sass)
converter.convert(input) converter.convert(input)
end end
@ -43,7 +43,7 @@ module Jekyll
# Returns the CSS formatted String. # Returns the CSS formatted String.
def scssify(input) def scssify(input)
site = @context.registers[:site] site = @context.registers[:site]
converter = site.getConverterImpl(Jekyll::Converters::Scss) converter = site.find_converter_instance(Jekyll::Converters::Scss)
converter.convert(input) converter.convert(input)
end end

View File

@ -414,13 +414,8 @@ module Jekyll
# klass - The Class of the Converter to fetch. # klass - The Class of the Converter to fetch.
# #
# Returns the Converter instance implementing the given Converter. # Returns the Converter instance implementing the given Converter.
def getConverterImpl(klass) def find_converter_instance(klass)
matches = converters.select { |c| c.class == klass } converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call
if impl = matches.first
impl
else
raise "Converter implementation not found for #{klass}"
end
end end
# Create array of instances of the subclasses of the class or module # Create array of instances of the subclasses of the class or module