Improve Site#getConverterImpl and call it Site#find_converter_instance
This commit is contained in:
parent
657b16519e
commit
0c0aea3ad7
|
@ -10,7 +10,7 @@ module Jekyll
|
|||
# Returns the HTML formatted String.
|
||||
def textilize(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Textile)
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Textile)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ module Jekyll
|
|||
# Returns the HTML formatted String.
|
||||
def markdownify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Markdown)
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Markdown)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
|
@ -32,7 +32,7 @@ module Jekyll
|
|||
# Returns the CSS formatted String.
|
||||
def sassify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Sass)
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Sass)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ module Jekyll
|
|||
# Returns the CSS formatted String.
|
||||
def scssify(input)
|
||||
site = @context.registers[:site]
|
||||
converter = site.getConverterImpl(Jekyll::Converters::Scss)
|
||||
converter = site.find_converter_instance(Jekyll::Converters::Scss)
|
||||
converter.convert(input)
|
||||
end
|
||||
|
||||
|
|
|
@ -414,13 +414,8 @@ module Jekyll
|
|||
# klass - The Class of the Converter to fetch.
|
||||
#
|
||||
# Returns the Converter instance implementing the given Converter.
|
||||
def getConverterImpl(klass)
|
||||
matches = converters.select { |c| c.class == klass }
|
||||
if impl = matches.first
|
||||
impl
|
||||
else
|
||||
raise "Converter implementation not found for #{klass}"
|
||||
end
|
||||
def find_converter_instance(klass)
|
||||
converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call
|
||||
end
|
||||
|
||||
# Create array of instances of the subclasses of the class or module
|
||||
|
|
Loading…
Reference in New Issue