Only compile the Converter#matches regexp when asked for

This commit is contained in:
Parker Moore 2014-10-12 14:31:49 -07:00
parent fbe98df488
commit 4942b2947b
2 changed files with 14 additions and 12 deletions

View File

@ -8,7 +8,6 @@ module Jekyll
def setup def setup
return if @setup return if @setup
@regexp = build_extname_regexp
@parser = @parser =
case @config['markdown'].downcase case @config['markdown'].downcase
when 'redcarpet' then RedcarpetParser.new(@config) when 'redcarpet' then RedcarpetParser.new(@config)
@ -28,11 +27,6 @@ module Jekyll
@setup = true @setup = true
end end
def build_extname_regexp
rgx = '^\.(' + @config['markdown_ext'].gsub(',','|') +')$'
Regexp.new(rgx, Regexp::IGNORECASE)
end
def valid_processors def valid_processors
%w[ %w[
maruku maruku
@ -52,8 +46,15 @@ module Jekyll
].map(&:to_sym) ].map(&:to_sym)
end end
def extname_matches_regexp
@extname_matches_regexp ||= Regexp.new(
'(' + @config['markdown_ext'].gsub(',','|') +')$',
Regexp::IGNORECASE
)
end
def matches(ext) def matches(ext)
ext =~ @regexp ext =~ extname_matches_regexp
end end
def output_ext(ext) def output_ext(ext)

View File

@ -9,7 +9,6 @@ module Jekyll
def setup def setup
return if @setup return if @setup
require 'redcloth' require 'redcloth'
@regexp = build_extname_regexp
@setup = true @setup = true
rescue LoadError rescue LoadError
STDERR.puts 'You are missing a library required for Textile. Please run:' STDERR.puts 'You are missing a library required for Textile. Please run:'
@ -17,13 +16,15 @@ module Jekyll
raise Errors::FatalException.new("Missing dependency: RedCloth") raise Errors::FatalException.new("Missing dependency: RedCloth")
end end
def build_extname_regexp def extname_matches_regexp
rgx = '(' + @config['textile_ext'].gsub(',','|') +')$' @extname_matches_regexp ||= Regexp.new(
Regexp.new(rgx, Regexp::IGNORECASE) '(' + @config['textile_ext'].gsub(',','|') +')$',
Regexp::IGNORECASE
)
end end
def matches(ext) def matches(ext)
ext =~ @regexp ext =~ extname_matches_regexp
end end
def output_ext(ext) def output_ext(ext)